main_window.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009  ** Includes
00010  *****************************************************************************/
00011 
00012 #include <QtGui>
00013 #include <QMessageBox>
00014 #include <iostream>
00015 #include "../include/rocon_qorchestra/main_window.hpp"
00016 
00017 /*****************************************************************************
00018  ** Namespaces
00019  *****************************************************************************/
00020 
00021 namespace rocon_qorchestra
00022 {
00023 
00024 using namespace Qt;
00025 
00026 /*****************************************************************************
00027  ** Implementation [MainWindow]
00028  *****************************************************************************/
00029 
00030 MainWindow::MainWindow(int argc, char** argv, QWidget *parent) : QMainWindow(parent), qnode(argc, argv)
00031 {
00032         ui.setupUi(this); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.
00033         QObject::connect(ui.actionAbout_Qt, SIGNAL(triggered(bool)), qApp,
00034     SLOT(aboutQt())); // qApp is a global variable for the application
00035 
00036         ReadSettings();
00037         ui.tab_manager->setCurrentIndex(0); // ensure the first tab is showing - qt-designer should have this already hardwired, but often loses it (settings?).
00038     QObject::connect(&qnode, SIGNAL(rosShutdown()), this, SLOT(close()));
00039 
00040     /*********************
00041         ** Concert Clients
00042         **********************/
00043     QObject::connect(&qnode, SIGNAL(concertClientsUpdate()), this, SLOT(updateConcertClientsViews()));
00044         QHeaderView *header = new QHeaderView(Qt::Horizontal);
00045         header->setResizeMode(QHeaderView::ResizeToContents);
00046         header->setStretchLastSection(true);
00047         ui.table_view_concert_clients->setHorizontalHeader(header);
00048     ui.table_view_concert_clients->setModel(qnode.concertClientsModel());
00049     ui.tree_view_implementations->setModel(qnode.implementations.model());
00050 
00051     /*********************
00052         ** Sigslots
00053         **********************/
00054     QObject::connect(this, SIGNAL(tableViewConcertClientsClicked( const QModelIndex )),
00055       &qnode, SLOT(retrieveClientAppList( const QModelIndex )));
00056     QObject::connect(&qnode, SIGNAL(clientAppListRetrieved( QStandardItemModel* )),
00057       this, SLOT(updateClientAppsViews( QStandardItemModel* )));
00058 
00059     QObject::connect(this, SIGNAL(tableViewClientAppsClicked( const QModelIndex )),
00060       &qnode, SLOT(retrieveAppDetails( const QModelIndex )));
00061     QObject::connect(&qnode, SIGNAL(appDetailsRetrieved( QStandardItemModel* )),
00062       this, SLOT(updateAppDetailsViews( QStandardItemModel* )));
00063 
00064     QObject::connect(&(qnode.implementations), SIGNAL(sigImplementationsFetched()), this, SLOT(updateViewImplementations()));
00065     QObject::connect(&qnode, SIGNAL(installMissingAppsRequest ( const QStandardItem* )),
00066       this, SLOT(installMissingAppsBox( const QStandardItem* )));
00067     QObject::connect(this, SIGNAL(installMissingAppsConfirmed( const QStandardItem* )),
00068         &qnode, SLOT(installMissingApps( const QStandardItem* )));
00069     QObject::connect(&qnode, SIGNAL(solutionRequirementsMet()),
00070       this, SLOT(enableStartSolution()));
00071 
00072     QObject::connect(this, SIGNAL(buttonInstallAppClicked(const QModelIndex)),
00073       &qnode, SLOT(installApp(const QModelIndex)));
00074     QObject::connect(this, SIGNAL(buttonUninstallAppClicked(const QModelIndex)),
00075       &qnode, SLOT(uninstallApp(const QModelIndex)));
00076     QObject::connect(&qnode, SIGNAL(missingAppsInstalled( const QModelIndex )),
00077       &qnode, SLOT(checkSolution( const QModelIndex )));
00078 
00079         /*********************
00080          ** Auto Start
00081          **********************/
00082         if (ui.checkbox_remember_settings->isChecked())
00083                 on_button_connect_clicked(true);
00084 }
00085 
00086 
00087 MainWindow::~MainWindow()
00088 {
00089 }
00090 
00091 
00092 /*****************************************************************************
00093  ** Implementation [Configuration]
00094  *****************************************************************************/
00095 
00096 void MainWindow::ReadSettings()
00097 {
00098   QSettings settings("Qt-Ros Package", "rocon_qorchestra");
00099   restoreGeometry(settings.value("geometry").toByteArray());
00100   restoreState(settings.value("windowState").toByteArray());
00101   QString master_url = settings.value("master_url",
00102       QString("http://192.168.1.2:11311/")).toString();
00103   QString host_url =
00104       settings.value("host_url", QString("192.168.1.3")).toString();
00105   //QString topic_name = settings.value("topic_name", QString("/chatter")).toString();
00106   ui.line_edit_master->setText(master_url);
00107   ui.line_edit_host->setText(host_url);
00108   //ui.line_edit_topic->setText(topic_name);
00109   bool remember = settings.value("remember_settings", false).toBool();
00110   ui.checkbox_remember_settings->setChecked(remember);
00111   bool checked = settings.value("use_environment_variables", false).toBool();
00112   ui.checkbox_use_environment->setChecked(checked);
00113   if (checked) {
00114     ui.line_edit_master->setEnabled(false);
00115     ui.line_edit_host->setEnabled(false);
00116     //ui.line_edit_topic->setEnabled(false);
00117   }
00118 }
00119 
00120 void MainWindow::WriteSettings()
00121 {
00122   QSettings settings("Qt-Ros Package", "rocon_qorchestra");
00123   settings.setValue("master_url", ui.line_edit_master->text());
00124   settings.setValue("host_url", ui.line_edit_host->text());
00125   //settings.setValue("topic_name",ui.line_edit_topic->text());
00126   settings.setValue("use_environment_variables",
00127   QVariant(ui.checkbox_use_environment->isChecked()));
00128   settings.setValue("geometry", saveGeometry());
00129   settings.setValue("windowState", saveState());
00130   settings.setValue("remember_settings",
00131   QVariant(ui.checkbox_remember_settings->isChecked()));
00132 }
00133 
00134 
00135 void MainWindow::closeEvent(QCloseEvent *event)
00136 {
00137   WriteSettings();
00138   QMainWindow::closeEvent(event);
00139 }
00140 
00141 
00142 void MainWindow::showNoMasterMessage()
00143 {
00144   QMessageBox msgBox;
00145   msgBox.setText("Couldn't find the ros master.");
00146   msgBox.exec();
00147   close();
00148 }
00149 
00150 
00151 /*****************************************************************************
00152  ** Implementation [Slots][automaticcally connected]
00153  *****************************************************************************/
00154 
00155 void MainWindow::on_actionAbout_triggered()
00156 {
00157   QMessageBox::about(
00158       this,
00159       tr("About ..."),
00160       tr("<h2>PACKAGE_NAME Test Program 0.10</h2><p>Copyright Yujin Robot</p><p>This package needs an about description.</p>"));
00161 }
00162 
00163 
00164 /*
00165  * These triggers whenever the button is clicked, regardless of whether it
00166  * is already checked or not.
00167  */
00168 void MainWindow::on_button_connect_clicked(bool check)
00169 {
00170         if (ui.checkbox_use_environment->isChecked()) {
00171                 if (!qnode.init()) {
00172                   showNoMasterMessage();
00173                 } else {
00174                   ui.button_connect->setEnabled(false);
00175                   ui.toolbox_command->setCurrentIndex(1);
00176                 }
00177         } else {
00178             if (!qnode.init(ui.line_edit_master->text().toStdString(), ui.line_edit_host->text().toStdString())) {
00179                 showNoMasterMessage();
00180             } else {
00181                     ui.button_connect->setEnabled(false);
00182                         ui.line_edit_master->setReadOnly(true);
00183                         ui.line_edit_host->setReadOnly(true);
00184                         ui.line_edit_topic->setReadOnly(true);
00185                     ui.toolbox_command->setCurrentIndex(1);
00186                 }
00187         }
00188 }
00189 
00190 
00191 void MainWindow::on_checkbox_use_environment_stateChanged(int state)
00192 {
00193         bool enabled;
00194         if (state == 0)
00195                 enabled = true;
00196         else
00197                 enabled = false;
00198         ui.line_edit_master->setEnabled(enabled);
00199         ui.line_edit_host->setEnabled(enabled);
00200         //ui.line_edit_topic->setEnabled(enabled);
00201 }
00202 
00203 
00204 void MainWindow::on_table_view_concert_clients_clicked(const QModelIndex &index)
00205 {
00206 //  std::cout << "Index clicked: " << index.row() << "," << index.column() << std::endl;
00207   Q_EMIT tableViewConcertClientsClicked( index );
00208 }
00209 
00210 
00211 void MainWindow::on_table_view_client_apps_clicked(const QModelIndex &index)
00212 {
00213   std::cout << "Index clicked: " << index.row() << "," << index.column() << std::endl;
00214   client_app_list_index_ = index;
00215   Q_EMIT tableViewClientAppsClicked( index );
00216 }
00217 
00218 
00219 
00220 void MainWindow::on_button_update_concert_clients_clicked()
00221 {
00222   Q_EMIT buttonUpdateConcertClientsClicked();
00223 }
00224 
00225 
00226 void MainWindow::on_button_install_app_clicked()
00227 {
00228   if ( client_app_list_index_.column() == 0 )
00229     Q_EMIT buttonInstallAppClicked( client_app_list_index_ );
00230   else
00231     ROS_WARN("QOrchestra: uhm, installing an installed app does not make a lot of sense!");
00232 }
00233 
00234 void MainWindow::on_button_uninstall_app_clicked() {
00235     if ( client_app_list_index_.column() == 1 ) {
00236         Q_EMIT buttonUninstallAppClicked( client_app_list_index_ );
00237     } else {
00238             ROS_WARN("QOrchestra: hm, uninstalling a not installed app does not make a lot of sense!");
00239     }
00240 }
00241 
00242 void MainWindow::on_button_check_implementation_clicked() {
00243 
00244         // selection mode is SingleSelection, so this should only return one
00245         QModelIndexList list = ui.tree_view_implementations->selectionModel()->selectedIndexes();
00246         if ( list.size() == 1 ) {
00247                 qnode.checkSolution(list.at(0));
00248         } else { // otherwise zero
00249                 ROS_ERROR_STREAM("QOrchestra : implementation list returned a size of zero, this is a bug in qorchestra.");
00250         }
00251 }
00252 
00253 void MainWindow::on_button_start_implementation_clicked() {
00254         qnode.startSolution();
00255         ui.button_start_implementation->setEnabled(false);
00256         ui.button_stop_implementation->setEnabled(true);
00257 }
00258 
00259 void MainWindow::on_button_stop_implementation_clicked() {
00260         qnode.stopSolution();
00261         ui.button_start_implementation->setEnabled(true);
00262         ui.button_stop_implementation->setEnabled(false);
00263 }
00264 
00265 void MainWindow::on_button_view_implementation_clicked() {
00266         qnode.implementations.viewLinkGraph();
00267 }
00268 
00269 
00270 /*****************************************************************************
00271  ** Implementation [Slots][manually connected]
00272  *****************************************************************************/
00273 
00278 void MainWindow::updateConcertClientsViews() {
00279         ui.table_view_concert_clients->resizeRowsToContents();
00280         ui.table_view_concert_clients->resizeColumnsToContents();
00281 }
00282 
00283 void MainWindow::updateClientAppsViews( QStandardItemModel* client_apps_model)
00284 {
00285 //  QHeaderView *header = new QHeaderView(Qt::Horizontal);
00286 //  header->setResizeMode(QHeaderView::ResizeToContents);
00287 //  header->setStretchLastSection(true);
00288 //  ui.table_view_client_apps->setHorizontalHeader(header);
00289   ui.table_view_client_apps->setModel(client_apps_model);
00290   ui.table_view_client_apps->resizeRowsToContents();
00291   ui.table_view_client_apps->resizeColumnsToContents();
00292 }
00293 
00294 
00295 void MainWindow::updateAppDetailsViews( QStandardItemModel* app_details_model)
00296 {
00297   ui.table_view_app_details->setModel(app_details_model);
00298   ui.table_view_app_details->resizeRowsToContents();
00299   ui.table_view_app_details->resizeColumnsToContents();
00300 }
00301 
00306 void MainWindow::updateViewImplementations() {
00307         if ( qnode.implementations.model()->rowCount() > 0 ) {
00308                 QModelIndex index = qnode.implementations.model()->index(0,0);
00309                 ui.tree_view_implementations->expand(index);
00310                 ui.tree_view_implementations->setCurrentIndex(index);
00311                 ui.button_check_implementation->setEnabled(true);
00312                 ui.button_start_implementation->setEnabled(false);
00313                 ui.button_view_implementation->setEnabled(true);
00314         }
00315 }
00316 
00317 
00318 void MainWindow::installMissingAppsBox( const QStandardItem* missing_apps_on_devices )
00319 {
00320   QMessageBox msg_box;
00321   msg_box.setIcon(QMessageBox::Question);
00322   msg_box.setWindowTitle("Installation of missing apps");
00323   msg_box.addButton(QMessageBox::Ok);
00324   msg_box.addButton(QMessageBox::Abort);
00325   msg_box.setDefaultButton(QMessageBox::Ok);
00326   std::stringstream stream;
00327   stream << "The following devices are missing the listed apps:\n";
00328   for(int i = 0; i < missing_apps_on_devices->rowCount(); ++i)
00329   {
00330     stream << "Device '" << missing_apps_on_devices->child(i, 0)->text().toStdString() << "' is missing app '"
00331       << missing_apps_on_devices->child(i, 1)->text().toStdString() << "'.\n";
00332   }
00333   stream << "\nPress 'OK' to start the installation of the missing devices or 'Abort' to not install any apps.\n";
00334   msg_box.setText(stream.str().c_str());
00335   if ( msg_box.exec() == QMessageBox::Ok )
00336   {
00337     std::cout << "Confirmation to install missing apps given." << std::endl;
00338     Q_EMIT installMissingAppsConfirmed(missing_apps_on_devices);
00339   }
00340 }
00341 
00342 
00343 void MainWindow::enableStartSolution()
00344 {
00345   ui.button_start_implementation->setEnabled(true);
00346 }
00347 
00348 
00349 } // namespace rocon_qorchestra
00350 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


graveyard_rocon_qorchestra
Author(s): Daniel Stonier
autogenerated on Wed Jan 23 2013 13:42:01