Cleanup of Properties

This commit is contained in:
Alexander Bock
2020-10-12 12:08:55 +02:00
parent 5e375329b3
commit 7b4d29c8de
7 changed files with 235 additions and 795 deletions

View File

@@ -131,7 +131,7 @@ private:
Ui::ProfileEdit *ui;
QWidget* _parent;
Meta* _meta;
properties* _properties;
Properties* _properties;
Modules* _modules;
Keybindings* _keybindings;
Assets* _assets;

View File

@@ -28,18 +28,33 @@
#include <QDialog>
#include <openspace/scene/profile.h>
#include <QWidget>
#include <QListWidgetItem>
QT_BEGIN_NAMESPACE
namespace Ui {
class properties;
}
QT_END_NAMESPACE
class QComboBox;
class QDialogButtonBox;
class QLabel;
class QLineEdit;
class QListWidget;
class QPushButton;
class properties : public QDialog
{
Q_OBJECT
class Properties : public QDialog {
Q_OBJECT
public:
/**
* Constructor for properties class
*
* \param imported The #openspace::Profile object containing all data of the
* new or imported profile.
* \param parent Pointer to parent Qt widget (optional)
*/
Properties(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();
@@ -50,31 +65,6 @@ public slots:
void transitionToEditMode();
void parseSelections();
public:
/**
* Constructor for properties 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 properties(openspace::Profile* imported, QWidget *parent = nullptr);
/**
* Destructor for properties class
*/
~properties();
/**
* Handles keypress while the Qt dialog window is open
*
* \param evt #QKeyEvent object for the key press event
*/
void keyPressEvent(QKeyEvent *evt);
protected:
//void resizeEvent(QResizeEvent* event);
private:
QString createOneLineSummary(openspace::Profile::Property p);
void transitionFromEditMode();
@@ -82,13 +72,24 @@ private:
bool areRequiredFormsFilled();
bool isLineEmpty(int index);
Ui::properties *ui;
QWidget* _parent;
openspace::Profile* _imported;
openspace::Profile* _profile;
std::vector<openspace::Profile::Property> _data;
bool _editModeNewItem = false;
const openspace::Profile::Property kBlank
= {openspace::Profile::Property::SetType::SetPropertyValue, "", ""};
QListWidget* _list = nullptr;
QPushButton* _addButton = nullptr;
QPushButton* _removeButton = nullptr;
QLabel* _commandLabel = nullptr;
QComboBox* _commandCombo = nullptr;
QLabel* _propertyLabel = nullptr;
QLineEdit* _propertyEdit = nullptr;
QLabel* _valueLabel = nullptr;
QLineEdit* _valueEdit = nullptr;
QPushButton* _saveButton = nullptr;
QPushButton* _cancelButton = nullptr;
QDialogButtonBox* _buttonBox = nullptr;
QLabel* _errorMsg = nullptr;
};
#endif // __OPENSPACE_UI_LAUNCHER___PROPERTIES___H__

View File

@@ -1,274 +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_PROPERTIES___H__
#define __OPENSPACE_UI_LAUNCHER___UI_PROPERTIES___H__
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QDialog>
#include <QtWidgets/QDialogButtonBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QListWidget>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QSpacerItem>
#include <QtWidgets/QVBoxLayout>
QT_BEGIN_NAMESPACE
class Ui_properties
{
public:
QVBoxLayout *verticalLayout;
QListWidget *list;
QHBoxLayout *horizontalLayout;
QPushButton *button_add;
QPushButton *button_remove;
QSpacerItem *horizontalSpacer;
QFrame *line;
QLabel *label_command;
QComboBox *combo_command;
QLabel *label_property;
QLineEdit *line_property;
QLabel *label_value;
QLineEdit *line_value;
QHBoxLayout *horizontalLayout_2;
QPushButton *button_save;
QPushButton *button_cancel;
QSpacerItem *horizontalSpacer_2;
QFrame *line_2;
QHBoxLayout *hLay_bottom_buttonBox;
QLabel *label_error;
QDialogButtonBox *buttonBox;
void setupUi(QDialog *properties)
{
if (properties->objectName().isEmpty())
properties->setObjectName(QString::fromUtf8("properties"));
properties->resize(591, 448);
properties->setMaximumSize(QSize(1600, 1000));
verticalLayout = new QVBoxLayout(properties);
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
list = new QListWidget(properties);
list->setObjectName(QString::fromUtf8("list"));
QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(list->sizePolicy().hasHeightForWidth());
list->setSizePolicy(sizePolicy);
list->setMinimumSize(QSize(0, 150));
list->setMaximumSize(QSize(1600, 800));
QFont font;
font.setFamily(QString::fromUtf8("Arial"));
list->setFont(font);
list->setAlternatingRowColors(true);
list->setMovement(QListView::Free);
list->setResizeMode(QListView::Adjust);
verticalLayout->addWidget(list);
horizontalLayout = new QHBoxLayout();
horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
button_add = new QPushButton(properties);
button_add->setObjectName(QString::fromUtf8("button_add"));
button_add->setMinimumSize(QSize(90, 0));
button_add->setMaximumSize(QSize(110, 16777215));
horizontalLayout->addWidget(button_add);
button_remove = new QPushButton(properties);
button_remove->setObjectName(QString::fromUtf8("button_remove"));
button_remove->setMinimumSize(QSize(90, 0));
button_remove->setMaximumSize(QSize(110, 16777215));
horizontalLayout->addWidget(button_remove);
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout->addItem(horizontalSpacer);
verticalLayout->addLayout(horizontalLayout);
line = new QFrame(properties);
line->setObjectName(QString::fromUtf8("line"));
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
verticalLayout->addWidget(line);
label_command = new QLabel(properties);
label_command->setObjectName(QString::fromUtf8("label_command"));
QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Fixed);
sizePolicy1.setHorizontalStretch(0);
sizePolicy1.setVerticalStretch(0);
sizePolicy1.setHeightForWidth(label_command->sizePolicy().hasHeightForWidth());
label_command->setSizePolicy(sizePolicy1);
QFont font1;
font1.setFamily(QString::fromUtf8("Arial"));
font1.setPointSize(12);
label_command->setFont(font1);
verticalLayout->addWidget(label_command);
combo_command = new QComboBox(properties);
combo_command->setObjectName(QString::fromUtf8("combo_command"));
QSizePolicy sizePolicy2(QSizePolicy::Fixed, QSizePolicy::Fixed);
sizePolicy2.setHorizontalStretch(0);
sizePolicy2.setVerticalStretch(0);
sizePolicy2.setHeightForWidth(combo_command->sizePolicy().hasHeightForWidth());
combo_command->setSizePolicy(sizePolicy2);
combo_command->setMinimumSize(QSize(200, 0));
combo_command->setMaximumSize(QSize(300, 16777215));
combo_command->setFont(font);
verticalLayout->addWidget(combo_command);
label_property = new QLabel(properties);
label_property->setObjectName(QString::fromUtf8("label_property"));
sizePolicy1.setHeightForWidth(label_property->sizePolicy().hasHeightForWidth());
label_property->setSizePolicy(sizePolicy1);
label_property->setMinimumSize(QSize(100, 0));
label_property->setMaximumSize(QSize(140, 16777215));
label_property->setFont(font1);
verticalLayout->addWidget(label_property);
line_property = new QLineEdit(properties);
line_property->setObjectName(QString::fromUtf8("line_property"));
line_property->setMinimumSize(QSize(350, 0));
line_property->setMaximumSize(QSize(1600, 16777215));
verticalLayout->addWidget(line_property);
label_value = new QLabel(properties);
label_value->setObjectName(QString::fromUtf8("label_value"));
sizePolicy1.setHeightForWidth(label_value->sizePolicy().hasHeightForWidth());
label_value->setSizePolicy(sizePolicy1);
label_value->setMinimumSize(QSize(100, 0));
label_value->setMaximumSize(QSize(140, 16777215));
label_value->setFont(font1);
verticalLayout->addWidget(label_value);
line_value = new QLineEdit(properties);
line_value->setObjectName(QString::fromUtf8("line_value"));
line_value->setMinimumSize(QSize(350, 0));
line_value->setMaximumSize(QSize(600, 16777215));
verticalLayout->addWidget(line_value);
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
button_save = new QPushButton(properties);
button_save->setObjectName(QString::fromUtf8("button_save"));
button_save->setMinimumSize(QSize(90, 0));
button_save->setMaximumSize(QSize(110, 16777215));
horizontalLayout_2->addWidget(button_save);
button_cancel = new QPushButton(properties);
button_cancel->setObjectName(QString::fromUtf8("button_cancel"));
button_cancel->setMinimumSize(QSize(90, 0));
button_cancel->setMaximumSize(QSize(110, 16777215));
horizontalLayout_2->addWidget(button_cancel);
horizontalSpacer_2 = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
horizontalLayout_2->addItem(horizontalSpacer_2);
verticalLayout->addLayout(horizontalLayout_2);
line_2 = new QFrame(properties);
line_2->setObjectName(QString::fromUtf8("line_2"));
line_2->setFrameShape(QFrame::HLine);
line_2->setFrameShadow(QFrame::Sunken);
verticalLayout->addWidget(line_2);
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(properties);
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);
buttonBox = new QDialogButtonBox(properties);
buttonBox->setObjectName(QString::fromUtf8("buttonBox"));
buttonBox->setOrientation(Qt::Horizontal);
buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
hLay_bottom_buttonBox->addWidget(buttonBox);
verticalLayout->addLayout(hLay_bottom_buttonBox);
retranslateUi(properties);
//QObject::connect(buttonBox, SIGNAL(accepted()), properties, SLOT(accept()));
QObject::connect(buttonBox, SIGNAL(rejected()), properties, SLOT(reject()));
QMetaObject::connectSlotsByName(properties);
} // setupUi
void retranslateUi(QDialog *properties)
{
properties->setWindowTitle(QCoreApplication::translate("properties", "Set Property Values", nullptr));
button_add->setText(QCoreApplication::translate("properties", "Add New", nullptr));
button_remove->setText(QCoreApplication::translate("properties", "Remove", nullptr));
label_command->setText(QCoreApplication::translate("properties", "Property Set Command", nullptr));
label_property->setText(QCoreApplication::translate("properties", "Property", nullptr));
#if QT_CONFIG(tooltip)
line_property->setToolTip(QCoreApplication::translate("properties", "<html><head/><body><p>Exact string is required for the property to be set</p></body></html>", nullptr));
#endif // QT_CONFIG(tooltip)
label_value->setText(QCoreApplication::translate("properties", "Value to Set", nullptr));
button_save->setText(QCoreApplication::translate("properties", "Save", nullptr));
button_cancel->setText(QCoreApplication::translate("properties", "Cancel", nullptr));
label_error->setText(QCoreApplication::translate("properties", "", nullptr));
} // retranslateUi
};
namespace Ui {
class properties: public Ui_properties {};
} // namespace Ui
QT_END_NAMESPACE
#endif // __OPENSPACE_UI_LAUNCHER___UI_PROPERTIES___H__

View File

@@ -76,8 +76,7 @@ Camera::Camera(openspace::Profile* profile, QWidget *parent)
}
{
QWidget* footer = new QWidget;
QBoxLayout* footerLayout = new QHBoxLayout(footer);
QBoxLayout* footerLayout = new QHBoxLayout;
_errorMsg = new QLabel;
_errorMsg->setObjectName("error-message");
@@ -90,7 +89,7 @@ Camera::Camera(openspace::Profile* profile, QWidget *parent)
connect(buttons, &QDialogButtonBox::rejected, this, &Camera::reject);
footerLayout->addWidget(buttons);
layout->addWidget(footer);
layout->addLayout(footerLayout);
}
if (_profile->camera().has_value()) {

View File

@@ -143,7 +143,7 @@ void ProfileEdit::openModules() {
void ProfileEdit::openProperties() {
ui->label_error->setText("");
if (_pData) {
_properties = new properties(_pData);
_properties = new Properties(_pData, this);
_properties->exec();
labelText(_pData, _pData->properties().size(), "Properties",
ui->label_properties

View File

@@ -22,38 +22,130 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <openspace/scene/profile.h>
#include "properties.h"
#include "./ui_properties.h"
#include <qevent.h>
#include <QComboBox>
#include <QDialogButtonBox>
#include <QEvent>
#include <QKeyEvent>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QPushButton>
#include <QVBoxLayout>
#include <iostream>
properties::properties(openspace::Profile* imported, QWidget *parent)
: QDialog(parent)
, ui(new Ui::properties)
, _imported(imported)
, _data(imported->properties())
{
ui->setupUi(this);
namespace {
const openspace::Profile::Property kBlank {
openspace::Profile::Property::SetType::SetPropertyValue,
"",
""
};
}
for (size_t i = 0; i < _data.size(); ++i) {
ui->list->addItem(new QListWidgetItem(createOneLineSummary(_data[i])));
Properties::Properties(openspace::Profile* profile, QWidget *parent)
: QDialog(parent)
, _profile(profile)
, _data(_profile->properties())
{
setWindowTitle("Profile Editor");
QBoxLayout* layout = new QVBoxLayout(this);
{
_list = new QListWidget;
connect(
_list, &QListWidget::itemSelectionChanged,
this, &Properties::listItemSelected
);
for (size_t i = 0; i < _data.size(); ++i) {
_list->addItem(new QListWidgetItem(createOneLineSummary(_data[i])));
}
layout->addWidget(_list);
}
{
QBoxLayout* box = new QHBoxLayout;
_addButton = new QPushButton("Add New");
connect(_addButton, &QPushButton::clicked, this, &Properties::listItemAdded);
box->addWidget(_addButton);
_removeButton = new QPushButton("Remove");
connect(_removeButton, &QPushButton::clicked, this, &Properties::listItemRemove);
box->addWidget(_removeButton);
box->addStretch();
layout->addLayout(box);
}
{
QFrame* line = new QFrame;
line->setFrameShape(QFrame::HLine);
line->setFrameShadow(QFrame::Sunken);
layout->addWidget(line);
}
{
_commandLabel = new QLabel("Property Set Command");
layout->addWidget(_commandLabel);
_commandCombo = new QComboBox;
_commandCombo->addItems({ "SetPropertyValue", "SetPropertyValueSingle" });
layout->addWidget(_commandCombo);
_propertyLabel = new QLabel("Property");
layout->addWidget(_propertyLabel);
_propertyEdit = new QLineEdit;
_propertyEdit->setToolTip("Exact string is required for the property to be set");
layout->addWidget(_propertyEdit);
_valueLabel = new QLabel("Value to Set");
layout->addWidget(_valueLabel);
_valueEdit = new QLineEdit;
layout->addWidget(_valueEdit);
{
QBoxLayout* box = new QHBoxLayout;
_saveButton = new QPushButton("Save");
connect(_saveButton, &QPushButton::clicked, this, &Properties::listItemSave);
box->addWidget(_saveButton);
_cancelButton = new QPushButton("Cancel");
connect(
_cancelButton, &QPushButton::clicked,
this, &Properties::listItemCancelSave
);
box->addWidget(_cancelButton);
box->addStretch();
layout->addLayout(box);
}
}
{
QBoxLayout* footerLayout = new QHBoxLayout;
_errorMsg = new QLabel;
_errorMsg->setObjectName("error-message");
_errorMsg->setWordWrap(true);
footerLayout->addWidget(_errorMsg);
_buttonBox = new QDialogButtonBox;
_buttonBox->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Cancel);
connect(
_buttonBox, &QDialogButtonBox::accepted,
this, &Properties::parseSelections
);
QObject::connect(
_buttonBox, &QDialogButtonBox::rejected,
this, &Properties::reject
);
footerLayout->addWidget(_buttonBox);
layout->addLayout(footerLayout);
}
connect(ui->list, SIGNAL(itemSelectionChanged()), this, SLOT(listItemSelected()));
connect(ui->button_add, SIGNAL(clicked()), this, SLOT(listItemAdded()));
connect(ui->button_save, SIGNAL(clicked()), this, SLOT(listItemSave()));
connect(ui->button_cancel, SIGNAL(clicked()), this, SLOT(listItemCancelSave()));
connect(ui->button_remove, SIGNAL(clicked()), this, SLOT(listItemRemove()));
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(parseSelections()));
QStringList commandOptions { "SetPropertyValue", "SetPropertyValueSingle" };
ui->combo_command->addItems(commandOptions);
transitionFromEditMode();
}
QString properties::createOneLineSummary(openspace::Profile::Property p) {
QString Properties::createOneLineSummary(openspace::Profile::Property p) {
QString summary = QString(p.name.c_str());
summary += " = ";
summary += QString(p.value.c_str());
@@ -65,72 +157,72 @@ QString properties::createOneLineSummary(openspace::Profile::Property p) {
return summary;
}
void properties::listItemSelected(void) {
QListWidgetItem *item = ui->list->currentItem();
int index = ui->list->row(item);
void Properties::listItemSelected() {
QListWidgetItem* item = _list->currentItem();
int index = _list->row(item);
if (_data.size() > 0) {
openspace::Profile::Property& p = _data[index];
if (p.setType == openspace::Profile::Property::SetType::SetPropertyValue) {
ui->combo_command->setCurrentIndex(0);
_commandCombo->setCurrentIndex(0);
}
else {
ui->combo_command->setCurrentIndex(1);
_commandCombo->setCurrentIndex(1);
}
ui->line_property->setText(QString(p.name.c_str()));
ui->line_value->setText(QString(p.value.c_str()));
_propertyEdit->setText(QString::fromStdString(p.name));
_valueEdit->setText(QString::fromStdString(p.value));
}
transitionToEditMode();
}
bool properties::isLineEmpty(int index) {
bool Properties::isLineEmpty(int index) {
bool isEmpty = true;
if (ui->list->item(index)->text().compare("") != 0) {
if (!_list->item(index)->text().isEmpty()) {
isEmpty = false;
}
if ((_data.size() > 0) && (_data.at(0).name.compare("") != 0)) {
if (!_data.empty() && !_data.at(0).name.empty()) {
isEmpty = false;
}
return isEmpty;
}
void properties::listItemAdded(void) {
int currentListSize = ui->list->count();
void Properties::listItemAdded(void) {
int currentListSize = _list->count();
if ((currentListSize == 1) && (isLineEmpty(0))) {
//Special case where list is "empty" but really has one line that is blank.
// This is done because QListWidget does not seem to like having its sole
// remaining item being removed.
_data.at(0) = kBlank;
ui->list->item(0)->setText(" (Enter details below & click 'Save')");
ui->list->setCurrentRow(0);
_list->item(0)->setText(" (Enter details below & click 'Save')");
_list->setCurrentRow(0);
transitionToEditMode();
}
else {
_data.push_back(kBlank);
ui->list->addItem(new QListWidgetItem(" (Enter details below & click 'Save')"));
_list->addItem(new QListWidgetItem(" (Enter details below & click 'Save')"));
//Scroll down to that blank line highlighted
ui->list->setCurrentRow(ui->list->count() - 1);
_list->setCurrentRow(_list->count() - 1);
}
//Blank-out the 2 text fields, set combo box to index 0
ui->combo_command->setCurrentIndex(0);
ui->line_property->setText(QString(_data.back().name.c_str()));
ui->line_value->setText(QString(_data.back().value.c_str()));
ui->combo_command->setFocus(Qt::OtherFocusReason);
// Blank-out the 2 text fields, set combo box to index 0
_commandCombo->setCurrentIndex(0);
_propertyEdit->setText(QString(_data.back().name.c_str()));
_valueEdit->setText(QString(_data.back().value.c_str()));
_commandCombo->setFocus(Qt::OtherFocusReason);
_editModeNewItem = true;
}
void properties::listItemSave(void) {
void Properties::listItemSave(void) {
if (!areRequiredFormsFilled()) {
return;
}
QListWidgetItem *item = ui->list->currentItem();
int index = ui->list->row(item);
QListWidgetItem* item = _list->currentItem();
int index = _list->row(item);
if ( _data.size() > 0) {
if (ui->combo_command->currentIndex() == 0) {
if (_commandCombo->currentIndex() == 0) {
_data[index].setType
= openspace::Profile::Property::SetType::SetPropertyValue;
}
@@ -138,33 +230,33 @@ void properties::listItemSave(void) {
_data[index].setType
= openspace::Profile::Property::SetType::SetPropertyValueSingle;
}
_data[index].name = ui->line_property->text().toUtf8().constData();
_data[index].value = ui->line_value->text().toUtf8().constData();
ui->list->item(index)->setText(createOneLineSummary(_data[index]));
_data[index].name = _propertyEdit->text().toStdString();
_data[index].value = _valueEdit->text().toStdString();
_list->item(index)->setText(createOneLineSummary(_data[index]));
}
transitionFromEditMode();
_editModeNewItem = false;
}
bool properties::areRequiredFormsFilled() {
bool Properties::areRequiredFormsFilled() {
bool requiredFormsFilled = true;
QString errors;
if (ui->line_property->text().length() == 0) {
if (_propertyEdit->text().length() == 0) {
errors += "Missing property name";
requiredFormsFilled = false;
}
if (ui->line_value->text().length() == 0) {
if (_valueEdit->text().length() == 0) {
if (errors.length() > 0) {
errors += ", ";
}
errors += "Missing value";
requiredFormsFilled = false;
}
ui->label_error->setText("<font color='red'>" + errors + "</font>");
_errorMsg->setText("<font color='red'>" + errors + "</font>");
return requiredFormsFilled;
}
void properties::listItemCancelSave(void) {
void Properties::listItemCancelSave(void) {
listItemSelected();
transitionFromEditMode();
if (_editModeNewItem) {
@@ -177,19 +269,19 @@ void properties::listItemCancelSave(void) {
_editModeNewItem = false;
}
void properties::listItemRemove(void) {
if (ui->list->count() > 0) {
if (ui->list->currentRow() >= 0 && ui->list->currentRow() < ui->list->count()) {
if (ui->list->count() == 1) {
void Properties::listItemRemove(void) {
if (_list->count() > 0) {
if (_list->currentRow() >= 0 && _list->currentRow() < _list->count()) {
if (_list->count() == 1) {
//Special case where last remaining item is being removed (QListWidget
// doesn't like the final item being removed so instead clear it)
_data.at(0) = kBlank;
ui->list->item(0)->setText("");
_list->item(0)->setText("");
}
else {
int index = ui->list->currentRow();
if (index >= 0 && index < ui->list->count()) {
delete ui->list->takeItem(index);
int index = _list->currentRow();
if (index >= 0 && index < _list->count()) {
delete _list->takeItem(index);
if (_data.size() > 0) {
_data.erase(_data.begin() + index);
}
@@ -200,62 +292,57 @@ void properties::listItemRemove(void) {
transitionFromEditMode();
}
void properties::transitionToEditMode(void) {
ui->list->setDisabled(true);
ui->button_add->setDisabled(true);
ui->button_remove->setDisabled(true);
ui->button_cancel->setDisabled(true);
ui->button_save->setDisabled(true);
ui->buttonBox->setDisabled(true);
void Properties::transitionToEditMode(void) {
_list->setDisabled(true);
_addButton->setDisabled(true);
_removeButton->setDisabled(true);
_saveButton->setDisabled(true);
_cancelButton->setDisabled(true);
_buttonBox->setDisabled(true);
ui->label_command->setText("<font color='black'>Property Set Command</font>");
ui->label_property->setText("<font color='black'>Property</font>");
ui->label_value->setText("<font color='black'>Value to set</font>");
_commandLabel->setText("<font color='black'>Property Set Command</font>");
_propertyLabel->setText("<font color='black'>Property</font>");
_valueLabel->setText("<font color='black'>Value to set</font>");
editBoxDisabled(false);
ui->label_error->setText("");
_errorMsg->setText("");
}
void properties::transitionFromEditMode(void) {
ui->list->setDisabled(false);
ui->button_add->setDisabled(false);
ui->button_remove->setDisabled(false);
ui->button_cancel->setDisabled(false);
ui->button_save->setDisabled(false);
ui->buttonBox->setDisabled(false);
void Properties::transitionFromEditMode(void) {
_list->setDisabled(false);
_addButton->setDisabled(false);
_removeButton->setDisabled(false);
_saveButton->setDisabled(false);
_cancelButton->setDisabled(false);
_buttonBox->setDisabled(false);
ui->label_command->setText("<font color='light gray'>Property Set Command</font>");
ui->label_property->setText("<font color='light gray'>Property</font>");
ui->label_value->setText("<font color='light gray'>Value to set</font>");
_commandLabel->setText("<font color='light gray'>Property Set Command</font>");
_propertyLabel->setText("<font color='light gray'>Property</font>");
_valueLabel->setText("<font color='light gray'>Value to set</font>");
editBoxDisabled(true);
ui->label_error->setText("");
_errorMsg->setText("");
}
void properties::editBoxDisabled(bool disabled) {
ui->label_command->setDisabled(disabled);
ui->combo_command->setDisabled(disabled);
ui->label_property->setDisabled(disabled);
ui->line_property->setDisabled(disabled);
ui->label_value->setDisabled(disabled);
ui->line_value->setDisabled(disabled);
ui->button_cancel->setDisabled(disabled);
ui->button_save->setDisabled(disabled);
void Properties::editBoxDisabled(bool disabled) {
_commandLabel->setDisabled(disabled);
_commandCombo->setDisabled(disabled);
_propertyLabel->setDisabled(disabled);
_propertyEdit->setDisabled(disabled);
_valueLabel->setDisabled(disabled);
_valueEdit->setDisabled(disabled);
_saveButton->setDisabled(disabled);
_cancelButton->setDisabled(disabled);
}
void properties::parseSelections() {
//Handle case with only one remaining but empty line
void Properties::parseSelections() {
// Handle case with only one remaining but empty line
if ((_data.size() == 1) && (_data.at(0).name.compare("") == 0)) {
_data.clear();
}
_imported->setProperties(_data);
_profile->setProperties(_data);
accept();
}
properties::~properties() {
delete ui;
}
void properties::keyPressEvent(QKeyEvent *evt)
{
void Properties::keyPressEvent(QKeyEvent* evt) {
if(evt->key() == Qt::Key_Enter || evt->key() == Qt::Key_Return) {
if (_editModeNewItem) {
listItemSave();

View File

@@ -1,373 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>properties</class>
<widget class="QDialog" name="properties">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>591</width>
<height>448</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>1600</width>
<height>1000</height>
</size>
</property>
<property name="windowTitle">
<string>Set Property Values</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="list">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>150</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1600</width>
<height>800</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>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="button_add">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Add New</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_remove">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_command">
<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>Property Set Command</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="combo_command">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>300</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<family>Arial</family>
</font>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_property">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Property</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="line_property">
<property name="minimumSize">
<size>
<width>350</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1600</width>
<height>16777215</height>
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Exact string is required for the property to be set&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_value">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>140</width>
<height>16777215</height>
</size>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Value to Set</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="line_value">
<property name="minimumSize">
<size>
<width>350</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>600</width>
<height>16777215</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="button_save">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_cancel">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>110</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<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>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>properties</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>properties</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>