console_master.cpp
Go to the documentation of this file.
1 // *****************************************************************************
2 //
3 // Copyright (c) 2015, Southwest Research Institute® (SwRI®)
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Southwest Research Institute® (SwRI®) nor the
14 // names of its contributors may be used to endorse or promote products
15 // derived from this software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 // ARE DISCLAIMED. IN NO EVENT SHALL Southwest Research Institute® BE LIABLE
21 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27 // DAMAGE.
28 //
29 // *****************************************************************************
30 
34 
35 #include <QFontDialog>
36 #include <QSettings>
37 
38 namespace swri_console
39 {
40 ConsoleMaster::ConsoleMaster(int argc, char** argv):
41  ros_thread_(argc, argv),
42  connected_(false),
43  window_font_(QFont("Ubuntu Mono", 9))
44 {
45  // The RosThread takes advantage of queued connections when emitting log messages
46  // to ensure that the messages are processed in the console window's event thread.
47  // In order for that to work, we have to manually register the message type with
48  // Qt's QMetaType system.
49  qRegisterMetaType<rosgraph_msgs::LogConstPtr>("rosgraph_msgs::LogConstPtr");
50 
51  QObject::connect(&bag_reader_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
52  &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
53  QObject::connect(&bag_reader_, SIGNAL(finishedReading()),
54  &db_, SLOT(processQueue()));
55  QObject::connect(&log_reader_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
56  &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
57  QObject::connect(&log_reader_, SIGNAL(finishedReading()),
58  &db_, SLOT(processQueue()));
59 }
60 
62 {
64  ros_thread_.wait();
65 }
66 
68 {
69  ConsoleWindow* win = new ConsoleWindow(&db_);
70  windows_.append(win);
71 
72  QSettings settings;
73  window_font_ = settings.value(SettingsKeys::FONT, QFont("Ubuntu Mono", 9)).value<QFont>();
74  win->setFont(window_font_);
75  QObject::connect(win, SIGNAL(createNewWindow()),
76  this, SLOT(createNewWindow()));
77 
78  QObject::connect(&ros_thread_, SIGNAL(connected(bool)),
79  win, SLOT(connected(bool)));
80 
81  QObject::connect(this,
82  SIGNAL(fontChanged(const QFont &)),
83  win, SLOT(setFont(const QFont &)));
84 
85  QObject::connect(win, SIGNAL(selectFont()),
86  this, SLOT(selectFont()));
87 
88  QObject::connect(win, SIGNAL(readBagFile()),
89  &bag_reader_, SLOT(promptForBagFile()));
90 
91  QObject::connect(win, SIGNAL(readLogFile()),
92  &log_reader_, SLOT(promptForLogFile()));
93 
94  QObject::connect(win, SIGNAL(readLogDirectory()),
95  &log_reader_, SLOT(promptForLogDirectory()));
96 
97 
98  if (!ros_thread_.isRunning())
99  {
100  // There's only one ROS thread, and it services every window. We need to initialize
101  // it and its connections to the LogDatabase when we first create a window, but
102  // after that it doesn't need to be modified again.
103  QObject::connect(&ros_thread_, SIGNAL(logReceived(const rosgraph_msgs::LogConstPtr& )),
104  &db_, SLOT(queueMessage(const rosgraph_msgs::LogConstPtr&) ));
105 
106  QObject::connect(&ros_thread_, SIGNAL(spun()),
107  &db_, SLOT(processQueue()));
108 
109  ros_thread_.start();
110  }
111 
112  win->show();
113 }
114 
115 void ConsoleMaster::fontSelectionChanged(const QFont &font)
116 {
117  window_font_ = font;
118  QSettings settings;
119  settings.setValue(SettingsKeys::FONT, font);
120  Q_EMIT fontChanged(window_font_);
121 }
122 
124 {
125  QFont starting_font = window_font_;
126 
127  QFontDialog dlg(window_font_);
128 
129  QObject::connect(&dlg, SIGNAL(currentFontChanged(const QFont &)),
130  this, SLOT(fontSelectionChanged(const QFont &)));
131 
132  int ret = dlg.exec();
133 
134  if (ret == QDialog::Accepted) {
135  if (window_font_ != dlg.selectedFont()) {
136  window_font_ = dlg.selectedFont();
137  Q_EMIT fontChanged(window_font_);
138  }
139  } else {
140  if (window_font_ != starting_font) {
141  window_font_ = starting_font;
142  Q_EMIT fontChanged(window_font_);
143  }
144  }
145 }
146 } // namespace swri_console
QList< ConsoleWindow * > windows_
void fontSelectionChanged(const QFont &font)
void fontChanged(const QFont &font)
void setFont(const QFont &font)
static const QString FONT
Definition: settings_keys.h:58
ConsoleMaster(int argc, char **argv)


swri_console
Author(s):
autogenerated on Wed Jun 5 2019 21:25:59