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 "../include/%(package)s/main_window.hpp"
16 
17 /*****************************************************************************
18 ** Namespaces
19 *****************************************************************************/
20 
21 namespace %(package)s {
22 
23 using namespace Qt;
24 
25 /*****************************************************************************
26 ** Implementation [MainWindow]
27 *****************************************************************************/
28 
29 MainWindow::MainWindow(int argc, char** argv, QWidget *parent)
30  : QMainWindow(parent)
31  , qnode(argc,argv)
32 {
33  ui.setupUi(this); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.
34  QObject::connect(ui.actionAbout_Qt, SIGNAL(triggered(bool)), qApp, SLOT(aboutQt())); // qApp is a global variable for the application
35 
36  ReadSettings();
37  setWindowIcon(QIcon(":/images/icon.png"));
38  ui.tab_manager->setCurrentIndex(0); // ensure the first tab is showing - qt-designer should have this already hardwired, but often loses it (settings?).
39  QObject::connect(&qnode, SIGNAL(rosShutdown()), this, SLOT(close()));
40 
41  /*********************
42  ** Logging
43  **********************/
44  ui.view_logging->setModel(qnode.loggingModel());
45  QObject::connect(&qnode, SIGNAL(loggingUpdated()), this, SLOT(updateLoggingView()));
46 
47  /*********************
48  ** Auto Start
49  **********************/
50  if ( ui.checkbox_remember_settings->isChecked() ) {
52  }
53 }
54 
56 
57 /*****************************************************************************
58 ** Implementation [Slots]
59 *****************************************************************************/
60 
62  QMessageBox msgBox;
63  msgBox.setText("Couldn't find the ros master.");
64  msgBox.exec();
65  close();
66 }
67 
68 /*
69  * These triggers whenever the button is clicked, regardless of whether it
70  * is already checked or not.
71  */
72 
74  if ( ui.checkbox_use_environment->isChecked() ) {
75  if ( !qnode.init() ) {
77  } else {
78  ui.button_connect->setEnabled(false);
79  }
80  } else {
81  if ( ! qnode.init(ui.line_edit_master->text().toStdString(),
82  ui.line_edit_host->text().toStdString()) ) {
84  } else {
85  ui.button_connect->setEnabled(false);
86  ui.line_edit_master->setReadOnly(true);
87  ui.line_edit_host->setReadOnly(true);
88  ui.line_edit_topic->setReadOnly(true);
89  }
90  }
91 }
92 
93 
95  bool enabled;
96  if ( state == 0 ) {
97  enabled = true;
98  } else {
99  enabled = false;
100  }
101  ui.line_edit_master->setEnabled(enabled);
102  ui.line_edit_host->setEnabled(enabled);
103  //ui.line_edit_topic->setEnabled(enabled);
104 }
105 
106 /*****************************************************************************
107 ** Implemenation [Slots][manually connected]
108 *****************************************************************************/
109 
116  ui.view_logging->scrollToBottom();
117 }
118 
119 /*****************************************************************************
120 ** Implementation [Menu]
121 *****************************************************************************/
122 
124  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>"));
125 }
126 
127 /*****************************************************************************
128 ** Implementation [Configuration]
129 *****************************************************************************/
130 
132  QSettings settings("Qt-Ros Package", "%(package)s");
133  restoreGeometry(settings.value("geometry").toByteArray());
134  restoreState(settings.value("windowState").toByteArray());
135  QString master_url = settings.value("master_url",QString("http://192.168.1.2:11311/")).toString();
136  QString host_url = settings.value("host_url", QString("192.168.1.3")).toString();
137  //QString topic_name = settings.value("topic_name", QString("/chatter")).toString();
138  ui.line_edit_master->setText(master_url);
139  ui.line_edit_host->setText(host_url);
140  //ui.line_edit_topic->setText(topic_name);
141  bool remember = settings.value("remember_settings", false).toBool();
142  ui.checkbox_remember_settings->setChecked(remember);
143  bool checked = settings.value("use_environment_variables", false).toBool();
144  ui.checkbox_use_environment->setChecked(checked);
145  if ( checked ) {
146  ui.line_edit_master->setEnabled(false);
147  ui.line_edit_host->setEnabled(false);
148  //ui.line_edit_topic->setEnabled(false);
149  }
150 }
151 
153  QSettings settings("Qt-Ros Package", "%(package)s");
154  settings.setValue("master_url",ui.line_edit_master->text());
155  settings.setValue("host_url",ui.line_edit_host->text());
156  //settings.setValue("topic_name",ui.line_edit_topic->text());
157  settings.setValue("use_environment_variables",QVariant(ui.checkbox_use_environment->isChecked()));
158  settings.setValue("geometry", saveGeometry());
159  settings.setValue("windowState", saveState());
160  settings.setValue("remember_settings",QVariant(ui.checkbox_remember_settings->isChecked()));
161 
162 }
163 
164 void MainWindow::closeEvent(QCloseEvent *event)
165 {
166  WriteSettings();
167  QMainWindow::closeEvent(event);
168 }
169 
170 } // namespace %(package)s
171 
void updateLoggingView()
void on_actionAbout_triggered()
void on_button_connect_clicked(bool check)
Definition: main_window.cpp:73
#define package
Definition: main_window.hpp:9
void showNoMasterMessage()
Definition: main_window.cpp:61
Ui::MainWindowDesign ui
Definition: main_window.hpp:58
bool init()
Definition: qnode.cpp:43
QStringListModel * loggingModel()
Definition: qnode.hpp:59
void WriteSettings()
void ReadSettings()
void on_checkbox_use_environment_stateChanged(int state)
Definition: main_window.cpp:94
void closeEvent(QCloseEvent *event)


qt_create
Author(s): Daniel Stonier
autogenerated on Wed Mar 11 2020 03:12:19