main_window.cpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Includes
10 *****************************************************************************/
11 
12 #include <QtGui>
13 #include <QMessageBox>
14 #include <iostream>
15 #include "main_window.hpp"
16 
17 using namespace Qt;
18 
19 /*****************************************************************************
20 ** Implementation [MainWindow]
21 *****************************************************************************/
22 
23 MainWindow::MainWindow(QNode *node, QWidget *parent) :
24  QMainWindow(parent),
25  qnode(node)
26 {
27  ui.setupUi(this); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.
28  QObject::connect(ui.actionAbout_Qt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt())); // qApp is a global variable for the application
29 
30  ReadSettings();
31  setWindowIcon(QIcon(":/images/icon.png"));
32  ui.tab_manager->setCurrentIndex(0); // ensure the first tab is showing - qt-designer should have this already hardwired, but often loses it (settings?).
33 
34  setWindowTitle(QApplication::translate("MainWindowDesign", qnode->nodeName().c_str(), 0, QApplication::UnicodeUTF8));
35 
36  /*********************
37  ** Logging
38  **********************/
39  ui.view_logging->setModel(qnode->loggingModel());
40  QObject::connect(qnode, SIGNAL(loggingUpdated()), this, SLOT(updateLoggingView()));
41  QObject::connect(qnode, SIGNAL(rosShutdown()), this, SLOT(close()));
42 
43  /*********************
44  ** Auto Start
45  **********************/
46  if ( ui.checkbox_remember_settings->isChecked() ) {
48  }
49 }
50 
52 
53 /*****************************************************************************
54 ** Implementation [Slots]
55 *****************************************************************************/
56 
58  QMessageBox msgBox;
59  msgBox.setText("Couldn't find the ros master.");
60  msgBox.exec();
61  close();
62 }
63 
64 /*
65  * These triggers whenever the button is clicked, regardless of whether it
66  * is already checked or not.
67  */
68 
70  if ( ui.checkbox_use_environment->isChecked() ) {
71  if ( !qnode->on_init() ) {
73  } else {
74  ui.button_connect->setEnabled(false);
75  }
76  } else {
77  if ( ! qnode->on_init(
78  ui.line_edit_master->text().toStdString(),
79  ui.line_edit_host->text().toStdString() )
80  ) {
82  } else {
83  ui.button_connect->setEnabled(false);
84  ui.line_edit_master->setReadOnly(true);
85  ui.line_edit_host->setReadOnly(true);
86  }
87  }
88 }
89 
91  bool enabled;
92  if ( state == 0 ) {
93  enabled = true;
94  } else {
95  enabled = false;
96  }
97  ui.line_edit_master->setEnabled(enabled);
98  ui.line_edit_host->setEnabled(enabled);
99 }
100 
101 /*****************************************************************************
102 ** Implemenation [Slots][manually connected]
103 *****************************************************************************/
104 
111  ui.view_logging->scrollToBottom();
112 }
113 
114 /*****************************************************************************
115 ** Implementation [Menu]
116 *****************************************************************************/
117 
119  QMessageBox::about(this, tr("About ..."),tr("<h2>PACKAGE_NAME Test Program 0.10</h2><p>Copyright Yujin Robot</p><p>This package needs an about description.</p>"));
120 }
121 
122 /*****************************************************************************
123 ** Implementation [Configuration]
124 *****************************************************************************/
125 
127  QSettings settings("Qt-Ros Package", qnode->nodeName().c_str());
128  restoreGeometry(settings.value("geometry").toByteArray());
129  restoreState(settings.value("windowState").toByteArray());
130  QString master_url = settings.value("master_url",QString("http://192.168.1.2:11311/")).toString();
131  QString host_url = settings.value("host_url", QString("192.168.1.3")).toString();
132  QString topic_name = settings.value("topic_name", QString("/chatter")).toString();
133  ui.line_edit_master->setText(master_url);
134  ui.line_edit_host->setText(host_url);
135  bool remember = settings.value("remember_settings", false).toBool();
136  ui.checkbox_remember_settings->setChecked(remember);
137  bool checked = settings.value("use_environment_variables", false).toBool();
138  ui.checkbox_use_environment->setChecked(checked);
139  if ( checked ) {
140  ui.line_edit_master->setEnabled(false);
141  ui.line_edit_host->setEnabled(false);
142  }
143 }
144 
146  QSettings settings("Qt-Ros Package", qnode->nodeName().c_str());
147  settings.setValue("geometry", geometry());
148  settings.setValue("master_url",ui.line_edit_master->text());
149  settings.setValue("host_url",ui.line_edit_host->text());
150  settings.setValue("use_environment_variables",QVariant(ui.checkbox_use_environment->isChecked()));
151  settings.setValue("windowState", saveState());
152  settings.setValue("remember_settings",QVariant(ui.checkbox_remember_settings->isChecked()));
153 }
154 
155 void MainWindow::closeEvent(QCloseEvent *event)
156 {
157  qnode->shutdown();
158  WriteSettings();
159  QMainWindow::closeEvent(event);
160 }
void on_button_connect_clicked(bool check)
Definition: main_window.cpp:69
void showNoMasterMessage()
Definition: main_window.cpp:57
QNode * qnode
Definition: main_window.hpp:55
MainWindow(QNode *node, QWidget *parent=0)
Definition: main_window.cpp:23
void closeEvent(QCloseEvent *event)
Ui::MainWindowDesign ui
Definition: main_window.hpp:54
QStringListModel * loggingModel()
Definition: qnode.hpp:43
void on_checkbox_use_environment_stateChanged(int state)
Definition: main_window.cpp:90
bool on_init()
Definition: qnode.cpp:45
Qt based gui for eros_qtalker.
void shutdown()
Definition: qnode.cpp:37
void on_actionAbout_triggered()
Definition: qnode.hpp:31
void updateLoggingView()
const std::string & nodeName()
Definition: qnode.hpp:44
void WriteSettings()
void ReadSettings()


qt_tutorials
Author(s): Daniel Stonier
autogenerated on Wed Mar 11 2020 03:12:20