config_dialog.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, Open Source Robotics Foundation, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * * Redistributions in binary form must reproduce the above
12  * copyright notice, this list of conditions and the following
13  * disclaimer in the documentation and/or other materials provided
14  * with the distribution.
15  * * Neither the name of the TU Darmstadt nor the names of its
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <QFileDialog>
34 #include <QGridLayout>
35 #include <QLabel>
36 #include <QPushButton>
37 
38 #include <rqt_rviz/config_dialog.h>
39 
40 namespace rqt_rviz {
41 
43 {
44  // Window configurations
45  this->setWindowTitle(tr("Choose configuration"));
46  this->setWindowFlags(Qt::Window | Qt::WindowCloseButtonHint |
47  Qt::WindowStaysOnTopHint | Qt::CustomizeWindowHint);
48 
49  // File
50  QLabel* file_label = new QLabel("File path");
51  file_label->setToolTip("Full path to file");
52 
53  file_edit_ = new QLineEdit;
54  file_edit_->setMinimumWidth(300);
55 
56  QPushButton* browse_button = new QPushButton(tr("Browse"));
57  connect(browse_button, SIGNAL(clicked()), this, SLOT(OnBrowse()));
58 
59  // Hide menu
60  QLabel* hide_label = new QLabel("Hide menu");
61  hide_label->setToolTip("Check to hide RViz's top menu bar");
62 
63  hide_box_ = new QCheckBox();
64 
65  // Buttons
66  QPushButton* cancel_button = new QPushButton(tr("&Cancel"));
67  this->connect(cancel_button, SIGNAL(clicked()), this, SLOT(close()));
68 
69  QPushButton* apply_button = new QPushButton(tr("&Apply"));
70  apply_button->setDefault(true);
71  this->connect(apply_button, SIGNAL(clicked()), this, SLOT(accept()));
72 
73  QHBoxLayout* buttons_layout = new QHBoxLayout;
74  buttons_layout->addWidget(cancel_button);
75  buttons_layout->addWidget(apply_button);
76 
77  // Layout
78  QGridLayout* main_layout = new QGridLayout();
79 
80  main_layout->addWidget(file_label, 0, 0);
81  main_layout->addWidget(file_edit_, 0, 1);
82  main_layout->addWidget(browse_button, 0, 2);
83 
84  main_layout->addWidget(hide_label, 1, 0);
85  main_layout->addWidget(hide_box_, 1, 1);
86  main_layout->setAlignment(hide_box_, Qt::AlignLeft);
87 
88  main_layout->addLayout(buttons_layout, 2, 0, 1, 3);
89  main_layout->setColumnStretch(1, 2);
90 
91  this->setLayout(main_layout);
92 }
93 
95 {
96 }
97 
99 {
100  QString filename = QFileDialog::getOpenFileName(0,
101  tr("Choose config file:"), "", tr("Rviz config file (*.rviz)"));
102 
103  file_edit_->setText(filename);
104 }
105 
106 std::string ConfigDialog::GetFile() const
107 {
108  return file_edit_->text().toStdString();
109 }
110 
111 void ConfigDialog::SetFile(const std::string& file)
112 {
113  file_edit_->setText(QString::fromStdString(file));
114 }
115 
117 {
118  return hide_box_->isChecked();
119 }
120 
121 void ConfigDialog::SetHide(const bool hide)
122 {
123  hide_box_->setChecked(hide);
124 }
125 
126 }
127 
filename
void OnBrowse()
Callback when the browse button is pressed.
bool GetHide() const
Get the hide menu option.
ConfigDialog()
Constructor.
std::string GetFile() const
Get the file path entered by the user.
void SetHide(const bool hide)
Set the hide menu option.
QCheckBox * hide_box_
Holds the boolean for whether to hide the menu.
Definition: config_dialog.h:79
~ConfigDialog()
Destructor.
QLineEdit * file_edit_
Holds the file path.
Definition: config_dialog.h:76
void SetFile(const std::string &file)
Populate the file path line edit.


rqt_rviz
Author(s): Dorian Scholz
autogenerated on Fri Feb 1 2019 03:57:23