manage_kml_dialog.cpp
Go to the documentation of this file.
00001 #include "manage_kml_dialog.h"
00002 
00003 #include "qt4/Qt/qcheckbox.h"
00004 #include "qt4/Qt/qpushbutton.h"
00005 #include "qt4/Qt/qfiledialog.h"
00006 #include <iostream>
00007 
00008 #include "ros/package.h"
00009 
00010 #include <ui_manage_kml_dialog.h>
00011 
00012 namespace rqt_marble_plugin {
00013 
00014 #define TEXT_COLUMN 0
00015 #define CHECK_BOX_COLUMN 1
00016 
00017 
00018 ManageKmlDialog::ManageKmlDialog(std::map< QString, bool>& kml_files, QWidget *parent) :
00019     QDialog(parent),
00020     ui(new Ui::manageKmlDialog)
00021 {
00022     ui->setupUi(this);
00023 
00024     ui->kml_treeWidget->header()->show();
00025     ui->kml_treeWidget->header()->resizeSection(0, 630);
00026     ui->kml_treeWidget->header()->resizeSection(1, 45);
00027 
00028     addAllKMLsToTreeWiev(kml_files);
00029 
00030     m_kml_files = kml_files;
00031 
00032     connect( ui->addButton , SIGNAL(clicked()) , this, SLOT( SetKMLFile() ));
00033     connect( ui->removeButton, SIGNAL(clicked()), this, SLOT(deleteKML()));
00034     connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()) );
00035     connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()) );
00036 
00037     connect(this, SIGNAL(accepted()), this, SLOT(okButtonClicked()));
00038     connect(this, SIGNAL(rejected()), this, SLOT(cancelButtonClicked()));
00039 }
00040 
00041 ManageKmlDialog::~ManageKmlDialog()
00042 {
00043     delete ui;
00044 }
00045 
00046 
00047 void ManageKmlDialog::SetKMLFile( bool envoke_file_dialog )
00048 {
00049     QFileInfo fi;
00050 
00051     if(envoke_file_dialog )
00052     {
00053         QString fn = QFileDialog::getOpenFileName( 0, tr("Open Geo Data File"), tr("") , tr("Geo Data Files (*.kml)"));
00054         fi.setFile( fn );
00055     }
00056 
00057     if( fi.isFile() )
00058     {
00059         bool show = true;
00060         addKMLToTreeWiev(fi, show);
00061         m_kml_files[fi.absoluteFilePath()] = show;
00062     }
00063 
00064 }
00065 
00066 void ManageKmlDialog::addAllKMLsToTreeWiev(std::map< QString, bool>& kml_files)
00067 {
00068     for(std::map< QString, bool>::iterator it = kml_files.begin(); it!=kml_files.end();it++)
00069     {
00070         QString filename = it->first;
00071         QFileInfo fi;
00072         fi.setFile(filename);
00073         bool show = it->second;
00074 
00075         addKMLToTreeWiev(fi, show);
00076     }
00077 }
00078 
00079 void ManageKmlDialog::addKMLToTreeWiev(QFileInfo& kmlFile, bool show)
00080 {
00081     QList<QTreeWidgetItem*> items = ui->kml_treeWidget->findItems( kmlFile.absoluteFilePath() , Qt::MatchExactly | Qt::MatchRecursive , TEXT_COLUMN );
00082     if(items.size()>0)
00083     {
00084         return; // no doubles
00085     }
00086 
00087     QTreeWidgetItem* item = new QTreeWidgetItem();
00088 
00089     item->setText(TEXT_COLUMN, kmlFile.absoluteFilePath() );
00090     if(show)
00091         item->setCheckState(CHECK_BOX_COLUMN, Qt::Checked);
00092     else
00093         item->setCheckState(CHECK_BOX_COLUMN, Qt::Unchecked);
00094     ui->kml_treeWidget->addTopLevelItem( item );
00095 
00096 }
00097 
00098 void ManageKmlDialog::deleteKML()
00099 {
00100 
00101     QList<QTreeWidgetItem*> items = ui->kml_treeWidget->selectedItems();
00102 
00103     if(items.size()==1)
00104     {
00105         QTreeWidgetItem* item = items.at(0);
00106         m_kml_files.erase(item->text(TEXT_COLUMN));
00107         delete items.at(0);
00108     }
00109 }
00110 
00111 void ManageKmlDialog::checkBoxClicked(int state)
00112 {
00113 
00114 }
00115 
00116 std::map< QString, bool> ManageKmlDialog::getKmlFiles()
00117 {
00118     return m_kml_files;
00119 }
00120 
00121 void ManageKmlDialog::cancelButtonClicked()
00122 {
00123     m_kml_files.clear();
00124 }
00125 
00126 void ManageKmlDialog::okButtonClicked()
00127 {
00128     int count = ui->kml_treeWidget->topLevelItemCount();
00129     for(int i = 0; i< count; i++)
00130     {
00131         QTreeWidgetItem* item = ui->kml_treeWidget->topLevelItem(i);
00132         if(item->checkState(CHECK_BOX_COLUMN)==Qt::Unchecked)
00133         {
00134             m_kml_files[item->text(TEXT_COLUMN)] = false;
00135         } else {
00136             m_kml_files[item->text(TEXT_COLUMN)] = true;
00137         }
00138     }
00139 }
00140 
00141 
00142 }


marble_plugin
Author(s): Tobias Bär
autogenerated on Thu Aug 27 2015 13:56:10