Cleanup MarkNodes

This commit is contained in:
Alexander Bock
2020-10-11 23:38:58 +02:00
parent 5b28208890
commit b8a685b513
6 changed files with 107 additions and 461 deletions

View File

@@ -26,19 +26,32 @@
#define __OPENSPACE_UI_LAUNCHER___MARKNODES___H__
#include <QDialog>
#include <QWidget>
#include <QListWidgetItem>
#include <openspace/scene/profile.h>
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<QListWidgetItem*> _markedNodesListItems;
openspace::Profile* _imported;
openspace::Profile* _profile;
std::vector<std::string> _data;
QListWidget* _list = nullptr;
QPushButton* _removeButton = nullptr;
QLineEdit* _newNode = nullptr;
};
#endif // __OPENSPACE_UI_LAUNCHER___MARKNODES___H__

View File

@@ -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;

View File

@@ -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 <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QDialog>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QListWidget>
#include <QtWidgets/QPushButton>
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", "<html><head/><body><p>Name of scenegraph node to add to list of &quot;interesting&quot; nodes</p></body></html>", 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__

View File

@@ -23,87 +23,118 @@
****************************************************************************************/
#include "marknodes.h"
#include "./ui_marknodes.h"
#include <qevent.h>
#include <iterator>
#include <QKeyEvent>
markNodes::markNodes(openspace::Profile* imported, QWidget *parent)
#include <openspace/scene/profile.h>
#include <QDialogButtonBox>
#include <QEvent>
#include <QKeyEvent>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QVBoxLayout>
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;
}

View File

@@ -1,199 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>markNodes</class>
<widget class="QDialog" name="markNodes">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>295</width>
<height>500</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>280</width>
<height>500</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1000</width>
<height>800</height>
</size>
</property>
<property name="windowTitle">
<string>Mark Interesting Nodes</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QListWidget" name="list">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>1000</height>
</size>
</property>
<property name="font">
<font>
<family>Arial</family>
</font>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="movement">
<enum>QListView::Free</enum>
</property>
<property name="resizeMode">
<enum>QListView::Adjust</enum>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_node">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Node to add:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLineEdit" name="line_node">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>800</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string extracomment="Module name is required">&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Name of scenegraph node to add to list of &amp;quot;interesting&amp;quot; nodes&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="button_remove">
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<family>Arial</family>
</font>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="button_add">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<family>Arial</family>
</font>
</property>
<property name="text">
<string>Add New</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>markNodes</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>markNodes</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -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