From c9e26c45fb4f0af02e92747cca1e6400bb434c76 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Tue, 5 Mar 2019 21:35:11 -0500 Subject: [PATCH] Prototype of VariableView and EditVariableDialog user interface. --- glabels/CMakeLists.txt | 3 + glabels/EditVariableDialog.cpp | 128 +++++++++++++++++ glabels/EditVariableDialog.h | 73 ++++++++++ glabels/VariablesView.cpp | 62 ++++++++ glabels/VariablesView.h | 5 + glabels/ui/EditVariableDialog.ui | 237 +++++++++++++++++++++++++++++++ glabels/ui/VariablesView.ui | 171 +++++++++++++++++++--- model/CMakeLists.txt | 1 + model/Variable.cpp | 74 ++++++++++ model/Variable.h | 84 +++++++++++ translations/glabels_C.ts | 98 +++++++++++++ 11 files changed, 913 insertions(+), 23 deletions(-) create mode 100644 glabels/EditVariableDialog.cpp create mode 100644 glabels/EditVariableDialog.h create mode 100644 glabels/ui/EditVariableDialog.ui create mode 100644 model/Variable.cpp create mode 100644 model/Variable.h diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index 715d63d..df14917 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -16,6 +16,7 @@ set (glabels_sources ColorPaletteButtonItem.cpp ColorSwatch.cpp Cursors.cpp + EditVariableDialog.cpp FieldButton.cpp File.cpp Help.cpp @@ -52,6 +53,7 @@ set (glabels_qobject_headers ColorPaletteDialog.h ColorPaletteItem.h ColorPaletteButtonItem.h + EditVariableDialog.h FieldButton.h File.h LabelEditor.h @@ -73,6 +75,7 @@ set (glabels_qobject_headers set (glabels_forms ui/AboutDialog.ui + ui/EditVariableDialog.ui ui/MergeView.ui ui/ObjectEditor.ui ui/PreferencesDialog.ui diff --git a/glabels/EditVariableDialog.cpp b/glabels/EditVariableDialog.cpp new file mode 100644 index 0000000..ea7d0f3 --- /dev/null +++ b/glabels/EditVariableDialog.cpp @@ -0,0 +1,128 @@ +/* EditVariableDialog.cpp + * + * Copyright (C) 2019 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#include "EditVariableDialog.h" + +#include "model/Settings.h" + + +namespace glabels +{ + + /// + /// Constructor + /// + EditVariableDialog::EditVariableDialog( QWidget *parent ) + : QDialog(parent) + { + setupUi( this ); + } + + + /// + /// Set variable + /// + void EditVariableDialog::setVariable( const model::Variable& variable ) + { + typeCombo->setCurrentIndex( variable.type() ); + nameEdit->setText( variable.name() ); + valueEdit->setText( variable.value() ); + incrementCombo->setCurrentIndex( variable.incrementPolicy() ); + stepSizeEdit->setText( variable.stepSize() ); + + updateControls(); + } + + + /// + /// Get variable + /// + model::Variable EditVariableDialog::variable() const + { + return model::Variable( static_cast(typeCombo->currentIndex()), + nameEdit->text(), + valueEdit->text(), + static_cast(incrementCombo->currentIndex()), + stepSizeEdit->text() ); + } + + + /// + /// typeCombo Changed + /// + void EditVariableDialog::onTypeComboChanged() + { + updateControls(); + } + + + /// + /// valueEdit Changed + /// + void EditVariableDialog::onValueEditChanged() + { + } + + + /// + /// incrementCombo Changed + /// + void EditVariableDialog::onIncrementComboChanged() + { + updateControls(); + } + + + /// + /// stepSizeEdit Changed + /// + void EditVariableDialog::onStepSizeEditChanged() + { + } + + + /// + /// update controls + /// + void EditVariableDialog::updateControls() + { + model::Variable::Type type = static_cast(typeCombo->currentIndex()); + model::Variable::IncrementPolicy incrementPolicy = static_cast(incrementCombo->currentIndex()); + + if ( type != model::Variable::TYPE_NUMERIC ) + { + incrementCombo->setCurrentIndex( model::Variable::INCREMENT_NEVER ); + } + + if ( incrementPolicy == model::Variable::INCREMENT_NEVER ) + { + stepSizeEdit->setText( "0" ); + } + + incrementLabel->setEnabled( type == model::Variable::TYPE_NUMERIC ); + incrementCombo->setEnabled( type == model::Variable::TYPE_NUMERIC ); + stepSizeLabel->setEnabled( (type == model::Variable::TYPE_NUMERIC) && + (incrementPolicy != model::Variable::INCREMENT_NEVER) ); + stepSizeEdit->setEnabled( (type == model::Variable::TYPE_NUMERIC) && + (incrementPolicy != model::Variable::INCREMENT_NEVER) ); + } + + +} // namespace glabels diff --git a/glabels/EditVariableDialog.h b/glabels/EditVariableDialog.h new file mode 100644 index 0000000..1419f2c --- /dev/null +++ b/glabels/EditVariableDialog.h @@ -0,0 +1,73 @@ +/* EditVariableDialog.h + * + * Copyright (C) 2019 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#ifndef EditVariableDialog_h +#define EditVariableDialog_h + + +#include "ui_EditVariableDialog.h" +#include "model/Variable.h" + + +namespace glabels +{ + + /// + /// New Label Dialog Widget + /// + class EditVariableDialog : public QDialog, public Ui_EditVariableDialog + { + Q_OBJECT + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// + public: + EditVariableDialog( QWidget *parent = nullptr ); + + + ///////////////////////////////// + // Public methods + ///////////////////////////////// + void setVariable( const model::Variable& variable ); + model::Variable variable() const; + + + ///////////////////////////////// + // Slots + ///////////////////////////////// + private slots: + void onTypeComboChanged(); + void onValueEditChanged(); + void onIncrementComboChanged(); + void onStepSizeEditChanged(); + + + ///////////////////////////////// + // Private methods + ///////////////////////////////// + void updateControls(); + + }; + +} + + +#endif // EditVariableDialog_h diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index 7505d12..ffe64b8 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -20,6 +20,8 @@ #include "VariablesView.h" +#include "EditVariableDialog.h" + #include @@ -55,8 +57,68 @@ namespace glabels mModel = model; mUndoRedoModel = undoRedoModel; + updateControls(); + //connect( mModel, SIGNAL(variablesChanged()), this, SLOT(onVariablesChanged()) ); } + /// + /// table Selection Changed + /// + void VariablesView::onTableSelectionChanged() + { + updateControls(); + } + + + /// + /// addButton Clicked + /// + void VariablesView::onAddButtonClicked() + { + EditVariableDialog dialog( this ); + + model::Variable v( model::Variable::TYPE_NUMERIC, + "x", + "0", + model::Variable::INCREMENT_NEVER, + "0" ); + dialog.setVariable( v ); + + if ( dialog.exec() == QDialog::Accepted ) + { + qDebug() << "Add OK."; + } + } + + + /// + /// editButton Clicked + /// + void VariablesView::onEditButtonClicked() + { + } + + + /// + /// deleteButton Clicked + /// + void VariablesView::onDeleteButtonClicked() + { + } + + + /// + /// update controls + /// + void VariablesView::updateControls() + { + bool hasSelection = !table->selectedItems().isEmpty(); + + editButton->setEnabled( hasSelection ); + deleteButton->setEnabled( hasSelection ); + } + + } // namespace glabels diff --git a/glabels/VariablesView.h b/glabels/VariablesView.h index e045dd4..f648cd5 100644 --- a/glabels/VariablesView.h +++ b/glabels/VariablesView.h @@ -60,12 +60,17 @@ namespace glabels // Slots ///////////////////////////////// private slots: + void onTableSelectionChanged(); + void onAddButtonClicked(); + void onEditButtonClicked(); + void onDeleteButtonClicked(); ///////////////////////////////// // Private methods ///////////////////////////////// private: + void updateControls(); ///////////////////////////////// diff --git a/glabels/ui/EditVariableDialog.ui b/glabels/ui/EditVariableDialog.ui new file mode 100644 index 0000000..8cd925e --- /dev/null +++ b/glabels/ui/EditVariableDialog.ui @@ -0,0 +1,237 @@ + + + EditVariableDialog + + + + 0 + 0 + 471 + 237 + + + + Dialog + + + + + + + + Variable Type: + + + + + + + + Numeric + + + + + String + + + + + + + + Name: + + + + + + + + + + Value: + + + + + + + + + + Increment: + + + + + + + + + + Never + + + + + Per Copy + + + + + Per Merge Record + + + + + Per Page + + + + + + + + Step Size: + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + EditVariableDialog + accept() + + + 227 + 214 + + + 157 + 236 + + + + + buttonBox + rejected() + EditVariableDialog + reject() + + + 295 + 220 + + + 286 + 236 + + + + + typeCombo + currentIndexChanged(int) + EditVariableDialog + onTypeComboChanged() + + + 179 + 30 + + + 33 + 161 + + + + + valueEdit + textChanged(QString) + EditVariableDialog + onValueEditChanged() + + + 212 + 86 + + + 63 + 166 + + + + + incrementCombo + currentIndexChanged(int) + EditVariableDialog + onIncrementComboChanged() + + + 170 + 123 + + + 97 + 176 + + + + + stepSizeEdit + textChanged(QString) + EditVariableDialog + onStepSizeEditChanged() + + + 344 + 125 + + + 333 + 166 + + + + + + onTypeComboChanged() + onValueEditChanged() + onIncrementComboChanged() + onStepSizeEditChanged() + + diff --git a/glabels/ui/VariablesView.ui b/glabels/ui/VariablesView.ui index df37af4..04ec15b 100644 --- a/glabels/ui/VariablesView.ui +++ b/glabels/ui/VariablesView.ui @@ -6,50 +6,106 @@ 0 0 - 570 + 1105 605 Form - + - - - 12 + + + + 0 + 0 + - - 12 + + <html><head/><body><p><span style=" font-size:18pt;">Variables</span></p></body></html> - - 12 + + + + + + QAbstractItemView::SingleSelection - - 12 + + QAbstractItemView::SelectRows + + 5 + + + + Name + + + + + Type + + + + + Value + + + + + Increment + + + + + Step Size + + + + + + - - - - 0 - 0 - + + + <html><head/><body><p>Add variable</p></body></html> - <html><head/><body><p><span style=" font-size:18pt;">Variables</span></p></body></html> + Add - + + + <html><head/><body><p>Edit selected variable</p></body></html> + + + Edit + + + + + + + <html><head/><body><p>Delete selected variable</p></body></html> + + + Delete + + + + + - Qt::Vertical + Qt::Horizontal - 20 - 40 + 40 + 20 @@ -59,11 +115,80 @@ - + + + addButton + clicked() + VariablesView + onAddButtonClicked() + + + 63 + 586 + + + 98 + 598 + + + + + editButton + clicked() + VariablesView + onEditButtonClicked() + + + 167 + 576 + + + 317 + 608 + + + + + deleteButton + clicked() + VariablesView + onDeleteButtonClicked() + + + 245 + 575 + + + 508 + 613 + + + + + table + itemSelectionChanged() + VariablesView + onTableSelectionChanged() + + + 380 + 258 + + + 787 + 610 + + + + onSelectAllButtonClicked() onUnselectAllButtonClicked() onLocationButtonClicked() onFormatComboActivated() + onAddButtonClicked() + onEditButtonClicked() + onDeleteButtonClicked() + onTableSelectionChanged() diff --git a/model/CMakeLists.txt b/model/CMakeLists.txt index ee1af03..100d5bf 100644 --- a/model/CMakeLists.txt +++ b/model/CMakeLists.txt @@ -56,6 +56,7 @@ set (Model_sources Template.cpp TextNode.cpp Units.cpp + Variable.cpp Vendor.cpp XmlCategoryParser.cpp XmlLabelCreator.cpp diff --git a/model/Variable.cpp b/model/Variable.cpp new file mode 100644 index 0000000..3eb309d --- /dev/null +++ b/model/Variable.cpp @@ -0,0 +1,74 @@ +/* Variable.cpp + * + * Copyright (C) 2013-2016 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#include "Variable.h" + + +namespace glabels +{ + namespace model + { + + Variable::Variable( Variable::Type type, + const QString& name, + const QString& value, + Variable::IncrementPolicy incrementPolicy, + const QString& stepSize ) + : mType(type), + mName(name), + mValue(value), + mIncrementPolicy(incrementPolicy), + mStepSize(stepSize) + { + // empty + } + + + Variable::Type Variable::type() const + { + return mType; + } + + + QString Variable::name() const + { + return mName; + } + + + QString Variable::value() const + { + return mValue; + } + + + Variable::IncrementPolicy Variable::incrementPolicy() const + { + return mIncrementPolicy; + } + + + QString Variable::stepSize() const + { + return mStepSize; + } + + } +} diff --git a/model/Variable.h b/model/Variable.h new file mode 100644 index 0000000..333857f --- /dev/null +++ b/model/Variable.h @@ -0,0 +1,84 @@ +/* Variable.h + * + * Copyright (C) 2019 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#ifndef model_Variable_h +#define model_Variable_h + + +#include + + +namespace glabels +{ + namespace model + { + + class Variable + { + public: + enum Type + { + TYPE_NUMERIC, + TYPE_STRING + }; + + enum IncrementPolicy + { + INCREMENT_NEVER, + INCREMENT_PER_COPY, + INCREMENT_PER_MERGE_RECORD, + INCREMENT_PER_PAGE + }; + + + public: + Variable() = default; + + Variable( Type type, + const QString& name, + const QString& value, + IncrementPolicy incrementPolicy = INCREMENT_NEVER, + const QString& stepSize = "0" ); + + virtual ~Variable() = default; + + + Type type() const; + QString name() const; + QString value() const; + IncrementPolicy incrementPolicy() const; + QString stepSize() const; + + + + private: + Type mType; + QString mName; + QString mValue; + IncrementPolicy mIncrementPolicy; + QString mStepSize; + + }; + + } +} + + +#endif // model_Variable_h diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index fc1cd75..844a98f 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -178,6 +178,57 @@ + + EditVariableDialog + + Dialog + + + + Variable Type: + + + + Numeric + + + + String + + + + Name: + + + + Value: + + + + Increment: + + + + Never + + + + Per Copy + + + + Per Merge Record + + + + Per Page + + + + Step Size: + + + Factory @@ -1031,6 +1082,53 @@ + + VariablesView + + Name + + + + Type + + + + Value + + + + Increment + + + + Step Size + + + + <html><head/><body><p>Add variable</p></body></html> + + + + Add + + + + <html><head/><body><p>Edit selected variable</p></body></html> + + + + Edit + + + + <html><head/><body><p>Delete selected variable</p></body></html> + + + + Delete + + + glabels::AboutDialog