diff --git a/apps/OpenSpace/ext/launcher/include/marknodes.h b/apps/OpenSpace/ext/launcher/include/marknodes.h index 5a7edeedab..e18dd7d4c9 100644 --- a/apps/OpenSpace/ext/launcher/include/marknodes.h +++ b/apps/OpenSpace/ext/launcher/include/marknodes.h @@ -26,19 +26,32 @@ #define __OPENSPACE_UI_LAUNCHER___MARKNODES___H__ #include -#include -#include -#include -QT_BEGIN_NAMESPACE -namespace Ui { -class markNodes; -} -QT_END_NAMESPACE +namespace openspace { class Profile; } -class markNodes : public QDialog -{ - Q_OBJECT +class QLineEdit; +class QListWidget; +class QListWidgetItem; +class QPushButton; + +class MarkNodes : public QDialog { +Q_OBJECT +public: + /** + * Constructor for markNodes class + * + * \param imported The #openspace::Profile object containing all data of the + * new or imported profile. + * \param parent Pointer to parent Qt widget + */ + MarkNodes(openspace::Profile* profile, QWidget* parent); + + /** + * Handles keypress while the Qt dialog window is open + * + * \param evt #QKeyEvent object for the key press event + */ + void keyPressEvent(QKeyEvent* evt); public slots: void listItemSelected(); @@ -46,34 +59,15 @@ public slots: void listItemRemove(); void parseSelections(); -public: - /** - * Constructor for markNodes class - * - * \param imported The #openspace::Profile object containing all data of the - * new or imported profile. - * \param parent Pointer to parent Qt widget (optional) - */ - explicit markNodes(openspace::Profile* imported, QWidget *parent = nullptr); - - /** - * Destructor for markNodes class - */ - ~markNodes(); - - /** - * Handles keypress while the Qt dialog window is open - * - * \param evt #QKeyEvent object for the key press event - */ - void keyPressEvent(QKeyEvent *evt); - private: - Ui::markNodes *ui; - QWidget* _parent; std::vector _markedNodesListItems; - openspace::Profile* _imported; + openspace::Profile* _profile; std::vector _data; + + QListWidget* _list = nullptr; + QPushButton* _removeButton = nullptr; + QLineEdit* _newNode = nullptr; + }; #endif // __OPENSPACE_UI_LAUNCHER___MARKNODES___H__ diff --git a/apps/OpenSpace/ext/launcher/include/profileedit.h b/apps/OpenSpace/ext/launcher/include/profileedit.h index a2b635c7b2..5ffc383a26 100644 --- a/apps/OpenSpace/ext/launcher/include/profileedit.h +++ b/apps/OpenSpace/ext/launcher/include/profileedit.h @@ -140,7 +140,7 @@ private: AdditionalScripts* _addedScripts; DeltaTimes* _deltaTimes; Camera* _camera; - markNodes* _markNodes; + MarkNodes* _markNodes; openspace::Profile* _pData; const std::string _reportedAssets; bool _saveSelected = false; diff --git a/apps/OpenSpace/ext/launcher/include/ui_marknodes.h b/apps/OpenSpace/ext/launcher/include/ui_marknodes.h deleted file mode 100644 index d1ee75e2a5..0000000000 --- a/apps/OpenSpace/ext/launcher/include/ui_marknodes.h +++ /dev/null @@ -1,180 +0,0 @@ -/***************************************************************************************** - * * - * OpenSpace * - * * - * Copyright (c) 2014-2020 * - * * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this * - * software and associated documentation files (the "Software"), to deal in the Software * - * without restriction, including without limitation the rights to use, copy, modify, * - * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to * - * permit persons to whom the Software is furnished to do so, subject to the following * - * conditions: * - * * - * The above copyright notice and this permission notice shall be included in all copies * - * or substantial portions of the Software. * - * * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, * - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * - * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * - * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF * - * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE * - * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * - ****************************************************************************************/ - -#ifndef __OPENSPACE_UI_LAUNCHER___UI_MARKNODES___H__ -#define __OPENSPACE_UI_LAUNCHER___UI_MARKNODES___H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -class Ui_markNodes -{ -public: - QGridLayout *gridLayout; - QListWidget *list; - QLabel *label_node; - QLineEdit *line_node; - QPushButton *button_remove; - QPushButton *button_add; - QHBoxLayout *hLay_bottom_buttonBox; - QLabel *label_error; - QDialogButtonBox *buttonBox; - QFrame *line; - - void setupUi(QDialog *markNodes) - { - if (markNodes->objectName().isEmpty()) - markNodes->setObjectName(QString::fromUtf8("markNodes")); - markNodes->resize(295, 500); - markNodes->setMinimumSize(QSize(360, 500)); - markNodes->setMaximumSize(QSize(1000, 800)); - gridLayout = new QGridLayout(markNodes); - gridLayout->setObjectName(QString::fromUtf8("gridLayout")); - list = new QListWidget(markNodes); - list->setObjectName(QString::fromUtf8("list")); - QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); - sizePolicy.setHorizontalStretch(0); - sizePolicy.setVerticalStretch(0); - sizePolicy.setHeightForWidth(list->sizePolicy().hasHeightForWidth()); - list->setSizePolicy(sizePolicy); - list->setMinimumSize(QSize(0, 50)); - list->setMaximumSize(QSize(16777215, 1000)); - QFont font; - font.setFamily(QString::fromUtf8("Arial")); - list->setFont(font); - list->setAlternatingRowColors(true); - list->setMovement(QListView::Free); - list->setResizeMode(QListView::Adjust); - - gridLayout->addWidget(list, 0, 0, 1, 1); - - label_node = new QLabel(markNodes); - label_node->setObjectName(QString::fromUtf8("label_node")); - QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Fixed); - sizePolicy1.setHorizontalStretch(0); - sizePolicy1.setVerticalStretch(0); - sizePolicy1.setHeightForWidth(label_node->sizePolicy().hasHeightForWidth()); - label_node->setSizePolicy(sizePolicy1); - QFont font1; - font1.setFamily(QString::fromUtf8("Arial")); - font1.setPointSize(12); - label_node->setFont(font1); - - gridLayout->addWidget(label_node, 2, 0, 1, 1); - - line_node = new QLineEdit(markNodes); - line_node->setObjectName(QString::fromUtf8("line_node")); - line_node->setMinimumSize(QSize(200, 0)); - line_node->setMaximumSize(QSize(800, 16777215)); - - gridLayout->addWidget(line_node, 3, 0, 1, 1); - - button_remove = new QPushButton(markNodes); - button_remove->setObjectName(QString::fromUtf8("button_remove")); - button_remove->setMinimumSize(QSize(50, 0)); - button_remove->setMaximumSize(QSize(100, 16777215)); - button_remove->setFont(font); - - gridLayout->addWidget(button_remove, 1, 0, 1, 1); - - button_add = new QPushButton(markNodes); - button_add->setObjectName(QString::fromUtf8("button_add")); - button_add->setMaximumSize(QSize(100, 16777215)); - button_add->setFont(font); - - gridLayout->addWidget(button_add, 4, 0, 1, 1); - - buttonBox = new QDialogButtonBox(markNodes); - buttonBox->setObjectName(QString::fromUtf8("buttonBox")); - buttonBox->setOrientation(Qt::Horizontal); - buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok); - - //gridLayout->addWidget(buttonBox, 6, 0, 1, 1); - - line = new QFrame(markNodes); - line->setObjectName(QString::fromUtf8("line")); - line->setFrameShape(QFrame::HLine); - line->setFrameShadow(QFrame::Sunken); - - gridLayout->addWidget(line, 5, 0, 1, 1); - - hLay_bottom_buttonBox = new QHBoxLayout(); - hLay_bottom_buttonBox->setObjectName(QString::fromUtf8("hLay_bottom_buttonBox")); - - QFont fontE; - fontE.setFamily(QString::fromUtf8("Arial")); - label_error = new QLabel(markNodes); - label_error->setObjectName(QString::fromUtf8("label_error")); - QSizePolicy sizePolicy3(QSizePolicy::Preferred, QSizePolicy::Preferred); - sizePolicy3.setHorizontalStretch(0); - sizePolicy3.setVerticalStretch(0); - sizePolicy3.setHeightForWidth(label_error->sizePolicy().hasHeightForWidth()); - label_error->setSizePolicy(sizePolicy3); - label_error->setMinimumSize(QSize(200, 40)); - label_error->setMaximumSize(QSize(800, 40)); - label_error->setFont(fontE); - label_error->setWordWrap(true); - hLay_bottom_buttonBox->addWidget(label_error); - - hLay_bottom_buttonBox->addWidget(buttonBox); - gridLayout->addLayout(hLay_bottom_buttonBox, 6, 0, 1, 1); - - retranslateUi(markNodes); - //QObject::connect(buttonBox, SIGNAL(accepted()), markNodes, SLOT(accept())); - QObject::connect(buttonBox, SIGNAL(rejected()), markNodes, SLOT(reject())); - - QMetaObject::connectSlotsByName(markNodes); - } // setupUi - - void retranslateUi(QDialog *markNodes) - { - markNodes->setWindowTitle(QCoreApplication::translate("markNodes", "Mark Interesting Nodes", nullptr)); - label_node->setText(QCoreApplication::translate("markNodes", "Node to add:", nullptr)); -#if QT_CONFIG(tooltip) - line_node->setToolTip(QCoreApplication::translate("markNodes", "

Name of scenegraph node to add to list of "interesting" nodes

", nullptr)); -#endif // QT_CONFIG(tooltip) - button_remove->setText(QCoreApplication::translate("markNodes", "Remove", nullptr)); - button_add->setText(QCoreApplication::translate("markNodes", "Add New", nullptr)); - label_error->setText(QCoreApplication::translate("markNodes", "", nullptr)); - } // retranslateUi - -}; - -namespace Ui { - class markNodes: public Ui_markNodes {}; -} // namespace Ui - -QT_END_NAMESPACE - -#endif // __OPENSPACE_UI_LAUNCHER___UI_MARKNODES___H__ diff --git a/apps/OpenSpace/ext/launcher/src/marknodes.cpp b/apps/OpenSpace/ext/launcher/src/marknodes.cpp index db842ffb72..6afa95319c 100644 --- a/apps/OpenSpace/ext/launcher/src/marknodes.cpp +++ b/apps/OpenSpace/ext/launcher/src/marknodes.cpp @@ -23,87 +23,118 @@ ****************************************************************************************/ #include "marknodes.h" -#include "./ui_marknodes.h" -#include -#include -#include -markNodes::markNodes(openspace::Profile* imported, QWidget *parent) +#include +#include +#include +#include +#include +#include +#include +#include +#include + +MarkNodes::MarkNodes(openspace::Profile* profile, QWidget* parent) : QDialog(parent) - , ui(new Ui::markNodes) - , _imported(imported) - , _data(imported->markNodes()) + , _profile(profile) + , _data(_profile->markNodes()) { - ui->setupUi(this); + QBoxLayout* layout = new QVBoxLayout(this); + _list = new QListWidget; + connect( + _list, &QListWidget::itemSelectionChanged, + this, &MarkNodes::listItemSelected + ); + _list->setAlternatingRowColors(true); + _list->setMovement(QListView::Free); + _list->setResizeMode(QListView::Adjust); for (size_t i = 0; i < _data.size(); ++i) { _markedNodesListItems.push_back( - new QListWidgetItem(QString(_data[i].c_str())) + new QListWidgetItem(QString::fromStdString(_data[i])) ); - ui->list->addItem(_markedNodesListItems[i]); + _list->addItem(_markedNodesListItems[i]); } + layout->addWidget(_list); - ui->line_node->setText(""); + _removeButton = new QPushButton("Remove"); + connect(_removeButton, &QPushButton::clicked, this, &MarkNodes::listItemRemove); + layout->addWidget(_removeButton); - connect(ui->list, SIGNAL(itemSelectionChanged()), this, SLOT(listItemSelected())); - connect(ui->button_add, SIGNAL(clicked()), this, SLOT(listItemAdded())); - connect(ui->button_remove, SIGNAL(clicked()), this, SLOT(listItemRemove())); - connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(parseSelections())); + { + QBoxLayout* box = new QHBoxLayout; + box->addWidget(new QLabel("Node to add:")); + _newNode = new QLineEdit; + _newNode->setToolTip( + "Name of scenegraph node to add to list of \"interesting\" nodes" + ); + box->addWidget(_newNode); + + QPushButton* addButton = new QPushButton("Add new"); + connect(addButton, &QPushButton::clicked, this, &MarkNodes::listItemAdded); + box->addWidget(addButton); + layout->addLayout(box); + } + { + QDialogButtonBox* buttons = new QDialogButtonBox; + buttons->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel); + QObject::connect( + buttons, &QDialogButtonBox::accepted, + this, &MarkNodes::parseSelections + ); + QObject::connect(buttons, &QDialogButtonBox::rejected, this, &MarkNodes::reject); + layout->addWidget(buttons); + } } -void markNodes::listItemSelected(void) { - ui->button_remove->setDisabled(false); +void MarkNodes::listItemSelected(void) { + _removeButton->setEnabled(true); } -void markNodes::listItemAdded(void) { - if (ui->line_node->text().length() == 0) { +void MarkNodes::listItemAdded(void) { + if (_newNode->text().isEmpty()) { return; } - std::string itemToAdd = ui->line_node->text().toUtf8().constData(); - auto idx = std::find(_data.begin(), _data.end(), itemToAdd); - if (idx != _data.end()) { - ui->list->setCurrentRow(std::distance(_data.begin(), idx)); + std::string itemToAdd = _newNode->text().toStdString(); + const auto it = std::find(_data.cbegin(), _data.cend(), itemToAdd); + if (it != _data.end()) { + _list->setCurrentRow(std::distance(_data.cbegin(), it)); } else { _data.push_back(itemToAdd); - _markedNodesListItems.push_back(new QListWidgetItem(ui->line_node->text())); - ui->list->addItem(_markedNodesListItems.back()); + _markedNodesListItems.push_back(new QListWidgetItem(_newNode->text())); + _list->addItem(_markedNodesListItems.back()); - //Scroll down to that blank line highlighted - ui->list->setCurrentItem(_markedNodesListItems.back()); + // Scroll down to that blank line highlighted + _list->setCurrentItem(_markedNodesListItems.back()); } - //Blank-out entry again - ui->line_node->setText(""); + // Blank-out entry again + _newNode->clear(); } -void markNodes::listItemRemove(void) { - QListWidgetItem *item = ui->list->currentItem(); - int index = ui->list->row(item); +void MarkNodes::listItemRemove() { + QListWidgetItem* item = _list->currentItem(); + int index = _list->row(item); if (index < 0 || index >= _markedNodesListItems.size()) { return; } - ui->list->takeItem(index); + _list->takeItem(index); _data.erase(_data.begin() + index); _markedNodesListItems.erase(_markedNodesListItems.begin() + index); } -void markNodes::parseSelections() { - _imported->setMarkNodes(_data); +void MarkNodes::parseSelections() { + _profile->setMarkNodes(_data); accept(); } -markNodes::~markNodes() { - delete ui; -} - -void markNodes::keyPressEvent(QKeyEvent *evt) -{ - if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) { - if (ui->line_node->text().length() > 0 && ui->line_node->hasFocus()) { +void MarkNodes::keyPressEvent(QKeyEvent *evt) { + if (evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) { + if (_newNode->text().length() > 0 && _newNode->hasFocus()) { listItemAdded(); return; } diff --git a/apps/OpenSpace/ext/launcher/src/marknodes.ui b/apps/OpenSpace/ext/launcher/src/marknodes.ui deleted file mode 100644 index 49e46e5af8..0000000000 --- a/apps/OpenSpace/ext/launcher/src/marknodes.ui +++ /dev/null @@ -1,199 +0,0 @@ - - - markNodes - - - - 0 - 0 - 295 - 500 - - - - - 280 - 500 - - - - - 1000 - 800 - - - - Mark Interesting Nodes - - - - - - - 0 - 0 - - - - - 0 - 50 - - - - - 16777215 - 1000 - - - - - Arial - - - - true - - - QListView::Free - - - QListView::Adjust - - - - - - - - 0 - 0 - - - - - Arial - 12 - - - - Node to add: - - - - - - - - 200 - 0 - - - - - 800 - 16777215 - - - - <html><head/><body><p>Name of scenegraph node to add to list of &quot;interesting&quot; nodes</p></body></html> - - - - - - - - 50 - 0 - - - - - 100 - 16777215 - - - - - Arial - - - - Remove - - - - - - - - 100 - 16777215 - - - - - Arial - - - - Add New - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - Qt::Horizontal - - - - - - - - - buttonBox - accepted() - markNodes - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - markNodes - reject() - - - 316 - 260 - - - 286 - 274 - - - - - diff --git a/apps/OpenSpace/ext/launcher/src/profileedit.cpp b/apps/OpenSpace/ext/launcher/src/profileedit.cpp index 23fe9845e7..c92721c002 100644 --- a/apps/OpenSpace/ext/launcher/src/profileedit.cpp +++ b/apps/OpenSpace/ext/launcher/src/profileedit.cpp @@ -220,7 +220,7 @@ void ProfileEdit::openCamera() { void ProfileEdit::openMarkNodes() { ui->label_error->setText(""); if (_pData) { - _markNodes = new markNodes(_pData); + _markNodes = new MarkNodes(_pData, this); _markNodes->exec(); labelText(_pData, _pData->markNodes().size(), "Mark Interesting Nodes", ui->label_marknodes