From b9b792272c4c12aa6709401b92e5127ee1ed4bd8 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 8 Dec 2018 12:53:04 -0500 Subject: [PATCH 01/32] Created placeholder for Variables page in UI. --- glabels/CMakeLists.txt | 3 + glabels/Icons.h | 10 + glabels/MainWindow.cpp | 54 ++++- glabels/MainWindow.h | 7 + glabels/VariablesView.cpp | 62 +++++ glabels/VariablesView.h | 83 +++++++ glabels/icons.qrc | 1 + .../icons/flat/48x48/glabels-variables.svg | 15 ++ glabels/ui/MergeView.ui | 13 +- glabels/ui/ObjectEditor.ui | 4 +- glabels/ui/PrintView.ui | 2 +- glabels/ui/PropertiesView.ui | 2 +- glabels/ui/StartupView.ui | 2 +- glabels/ui/TemplateDesignerApplyPage.ui | 2 +- glabels/ui/TemplateDesignerCdPage.ui | 2 +- glabels/ui/TemplateDesignerContinuousPage.ui | 2 +- glabels/ui/TemplateDesignerEllipsePage.ui | 2 +- glabels/ui/TemplateDesignerIntroPage.ui | 2 +- glabels/ui/TemplateDesignerNLayoutsPage.ui | 2 +- glabels/ui/TemplateDesignerNamePage.ui | 2 +- glabels/ui/TemplateDesignerOneLayoutPage.ui | 2 +- glabels/ui/TemplateDesignerPageSizePage.ui | 2 +- glabels/ui/TemplateDesignerPathPage.ui | 2 +- glabels/ui/TemplateDesignerRectPage.ui | 2 +- glabels/ui/TemplateDesignerRoundPage.ui | 2 +- glabels/ui/TemplateDesignerShapePage.ui | 2 +- glabels/ui/TemplateDesignerTwoLayoutPage.ui | 2 +- glabels/ui/VariablesView.ui | 69 ++++++ translations/glabels_C.ts | 229 +++++++----------- 29 files changed, 418 insertions(+), 166 deletions(-) create mode 100644 glabels/VariablesView.cpp create mode 100644 glabels/VariablesView.h create mode 100644 glabels/icons/flat/48x48/glabels-variables.svg create mode 100644 glabels/ui/VariablesView.ui diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index 41305c0..715d63d 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -39,6 +39,7 @@ set (glabels_sources TemplatePicker.cpp TemplatePickerItem.cpp UndoRedoModel.cpp + VariablesView.cpp ) set (glabels_qobject_headers @@ -67,6 +68,7 @@ set (glabels_qobject_headers TemplateDesigner.h TemplatePicker.h UndoRedoModel.h + VariablesView.h ) set (glabels_forms @@ -92,6 +94,7 @@ set (glabels_forms ui/TemplateDesignerOneLayoutPage.ui ui/TemplateDesignerTwoLayoutPage.ui ui/TemplateDesignerApplyPage.ui + ui/VariablesView.ui ) set (glabels_resource_files diff --git a/glabels/Icons.h b/glabels/Icons.h index 5f02ed2..37dd081 100644 --- a/glabels/Icons.h +++ b/glabels/Icons.h @@ -473,6 +473,16 @@ namespace glabels }; + class Variables : public QIcon + { + public: + Variables() + { + addPixmap( QPixmap( ":icons/flat/48x48/glabels-variables.svg" ) ); + } + }; + + class ZoomBestFit : public QIcon { public: diff --git a/glabels/MainWindow.cpp b/glabels/MainWindow.cpp index 2dcbdaf..4d39842 100644 --- a/glabels/MainWindow.cpp +++ b/glabels/MainWindow.cpp @@ -31,6 +31,7 @@ #include "PropertiesView.h" #include "StartupView.h" #include "UndoRedoModel.h" +#include "VariablesView.h" #include "model/Db.h" #include "model/Model.h" @@ -51,7 +52,8 @@ namespace EDITOR_PAGE_INDEX = 1, PROPERTIES_PAGE_INDEX = 2, MERGE_PAGE_INDEX = 3, - PRINT_PAGE_INDEX = 4, + VARIABLES_PAGE_INDEX = 4, + PRINT_PAGE_INDEX = 5, }; } @@ -76,6 +78,7 @@ namespace glabels QWidget* editorPage = createEditorPage(); QWidget* propertiesPage = createPropertiesPage(); QWidget* mergePage = createMergePage(); + QWidget* variablesPage = createVariablesPage(); QWidget* printPage = createPrintPage(); // Table of contents widget @@ -141,6 +144,18 @@ namespace glabels mMergeAction = mContents->addWidget( mMergeButton ); group->addButton( mMergeButton ); + // Add "Variables" page + mPages->addWidget( variablesPage ); + mVariablesButton = new QToolButton( this ); + mVariablesButton->setIcon( Icons::Variables() ); + mVariablesButton->setText( tr("Variables") ); + mVariablesButton->setToolButtonStyle( Qt::ToolButtonTextUnderIcon ); + mVariablesButton->setCheckable( true ); + mVariablesButton->setSizePolicy( QSizePolicy::MinimumExpanding, + QSizePolicy::Preferred ); + mVariablesAction = mContents->addWidget( mVariablesButton ); + group->addButton( mVariablesButton ); + // Add "Print" page mPages->addWidget( printPage ); mPrintButton = new QToolButton( this ); @@ -175,6 +190,7 @@ namespace glabels connect( mEditorButton, SIGNAL(toggled(bool)), this, SLOT(changePage(bool))); connect( mPropertiesButton, SIGNAL(toggled(bool)), this, SLOT(changePage(bool))); connect( mMergeButton, SIGNAL(toggled(bool)), this, SLOT(changePage(bool))); + connect( mVariablesButton, SIGNAL(toggled(bool)), this, SLOT(changePage(bool))); connect( mPrintButton, SIGNAL(toggled(bool)), this, SLOT(changePage(bool))); connect( mLabelEditor, SIGNAL(zoomChanged()), this, SLOT(onZoomChanged()) ); connect( QApplication::clipboard(), SIGNAL(dataChanged()), this, SLOT(clipboardChanged()) ); @@ -217,7 +233,8 @@ namespace glabels mPropertiesView->setModel( mModel, mUndoRedoModel ); mLabelEditor->setModel( mModel, mUndoRedoModel ); mObjectEditor->setModel( mModel, mUndoRedoModel ); - mMergeView->setModel( mModel , mUndoRedoModel ); + mMergeView->setModel( mModel, mUndoRedoModel ); + mVariablesView->setModel( mModel, mUndoRedoModel ); mPrintView->setModel( mModel ); mEditorButton->setChecked( true ); @@ -306,6 +323,11 @@ namespace glabels fileShowMergePageAction->setStatusTip( tr("Select project Merge mode") ); connect( fileShowMergePageAction, SIGNAL(triggered()), this, SLOT(fileShowMergePage()) ); + fileShowVariablesPageAction = new QAction( tr("&Variables") , this ); + fileShowVariablesPageAction->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_4 ) ); + fileShowVariablesPageAction->setStatusTip( tr("Select project Variables mode") ); + connect( fileShowVariablesPageAction, SIGNAL(triggered()), this, SLOT(fileShowVariablesPage()) ); + fileShowPrintPageAction = new QAction( tr("&Print") , this ); fileShowPrintPageAction->setShortcut( QKeySequence::Print ); fileShowPrintPageAction->setStatusTip( tr("Select project Print mode") ); @@ -585,6 +607,7 @@ namespace glabels fileMenu->addAction( fileShowEditorPageAction ); fileMenu->addAction( fileShowPropertiesPageAction ); fileMenu->addAction( fileShowMergePageAction ); + fileMenu->addAction( fileShowVariablesPageAction ); fileMenu->addAction( fileShowPrintPageAction ); fileMenu->addSeparator(); fileMenu->addAction( fileTemplateDesignerAction ); @@ -795,6 +818,17 @@ namespace glabels } + /// + /// Create Variables Page + /// + QWidget* MainWindow::createVariablesPage() + { + mVariablesView = new VariablesView(); + + return mVariablesView; + } + + /// /// Create Print Page /// @@ -819,6 +853,7 @@ namespace glabels bool isEditorPage = mEditorButton->isChecked(); bool isPropertiesPage = mPropertiesButton->isChecked(); bool isMergePage = mMergeButton->isChecked(); + bool isVariablesPage = mVariablesButton->isChecked(); bool isPrintPage = mPrintButton->isChecked(); // What is the current selection state? @@ -831,6 +866,7 @@ namespace glabels mEditorAction->setVisible( !isWelcomePage ); mPropertiesAction->setVisible( !isWelcomePage ); mMergeAction->setVisible( !isWelcomePage ); + mVariablesAction->setVisible( !isWelcomePage ); mPrintAction->setVisible( !isWelcomePage ); // File actions @@ -841,6 +877,7 @@ namespace glabels fileShowEditorPageAction->setEnabled( !isWelcomePage && !isEditorPage ); fileShowPropertiesPageAction->setEnabled( !isWelcomePage && !isPropertiesPage ); fileShowMergePageAction->setEnabled( !isWelcomePage && !isMergePage ); + fileShowVariablesPageAction->setEnabled( !isWelcomePage && !isVariablesPage ); fileShowPrintPageAction->setEnabled( !isWelcomePage && !isPrintPage ); fileTemplateDesignerAction->setEnabled( true ); fileCloseAction->setEnabled( true ); @@ -1036,6 +1073,10 @@ namespace glabels { mPages->setCurrentIndex( MERGE_PAGE_INDEX ); } + else if ( mVariablesButton->isChecked() ) + { + mPages->setCurrentIndex( VARIABLES_PAGE_INDEX ); + } else if ( mPrintButton->isChecked() ) { mPages->setCurrentIndex( PRINT_PAGE_INDEX ); @@ -1118,6 +1159,15 @@ namespace glabels } + /// + /// File->Show Variables Page + /// + void MainWindow::fileShowVariablesPage() + { + mVariablesButton->setChecked( true ); + } + + /// /// File->Show Print Page /// diff --git a/glabels/MainWindow.h b/glabels/MainWindow.h index 6166173..268a161 100644 --- a/glabels/MainWindow.h +++ b/glabels/MainWindow.h @@ -47,6 +47,7 @@ namespace glabels class PropertiesView; class StartupView; class UndoRedoModel; + class VariablesView; /// @@ -96,6 +97,7 @@ namespace glabels void fileShowEditorPage(); void fileShowPropertiesPage(); void fileShowMergePage(); + void fileShowVariablesPage(); void fileShowPrintPage(); void fileTemplateDesigner(); void fileClose(); @@ -171,6 +173,7 @@ namespace glabels QWidget* createEditorPage(); QWidget* createPropertiesPage(); QWidget* createMergePage(); + QWidget* createVariablesPage(); QWidget* createPrintPage(); void manageActions(); @@ -217,12 +220,14 @@ namespace glabels QToolButton* mEditorButton; QToolButton* mPropertiesButton; QToolButton* mMergeButton; + QToolButton* mVariablesButton; QToolButton* mPrintButton; QAction* mWelcomeAction; QAction* mEditorAction; QAction* mPropertiesAction; QAction* mMergeAction; + QAction* mVariablesAction; QAction* mPrintAction; QStackedWidget* mPages; @@ -232,6 +237,7 @@ namespace glabels ObjectEditor* mObjectEditor; PropertiesView* mPropertiesView; MergeView* mMergeView; + VariablesView* mVariablesView; PrintView* mPrintView; QLabel* zoomInfoLabel; @@ -244,6 +250,7 @@ namespace glabels QAction* fileShowEditorPageAction; QAction* fileShowPropertiesPageAction; QAction* fileShowMergePageAction; + QAction* fileShowVariablesPageAction; QAction* fileShowPrintPageAction; QAction* fileTemplateDesignerAction; QAction* fileCloseAction; diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp new file mode 100644 index 0000000..7505d12 --- /dev/null +++ b/glabels/VariablesView.cpp @@ -0,0 +1,62 @@ +/* VariablesView.cpp + * + * Copyright (C) 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 "VariablesView.h" + +#include + + +namespace glabels +{ + + /// + /// Constructor + /// + VariablesView::VariablesView( QWidget *parent ) + : QWidget(parent), mModel(nullptr), mUndoRedoModel(nullptr) + { + setupUi( this ); + + titleLabel->setText( QString( "%1" ).arg( tr("Variables") ) ); + } + + + /// + /// Destructor + /// + VariablesView::~VariablesView() + { + // empty + } + + + /// + /// Set Model + /// + void VariablesView::setModel( model::Model* model, UndoRedoModel* undoRedoModel ) + { + mModel = model; + mUndoRedoModel = undoRedoModel; + + //connect( mModel, SIGNAL(variablesChanged()), this, SLOT(onVariablesChanged()) ); + } + + +} // namespace glabels diff --git a/glabels/VariablesView.h b/glabels/VariablesView.h new file mode 100644 index 0000000..e045dd4 --- /dev/null +++ b/glabels/VariablesView.h @@ -0,0 +1,83 @@ +/* VariablesView.h + * + * Copyright (C) 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 . + */ + +#ifndef VariablesView_h +#define VariablesView_h + + +#include "ui_VariablesView.h" + +#include "model/Model.h" + + +namespace glabels +{ + + // Forward references + class UndoRedoModel; + + + /// + /// Variables Property Editor Widget + /// + class VariablesView : public QWidget, public Ui_VariablesView + { + Q_OBJECT + + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// + public: + VariablesView( QWidget *parent = nullptr ); + ~VariablesView() override; + + + ///////////////////////////////// + // Public methods + ///////////////////////////////// + void setModel( model::Model* model, UndoRedoModel* undoRedoModel ); + + + ///////////////////////////////// + // Slots + ///////////////////////////////// + private slots: + + + ///////////////////////////////// + // Private methods + ///////////////////////////////// + private: + + + ///////////////////////////////// + // Private Data + ///////////////////////////////// + private: + model::Model* mModel; + UndoRedoModel* mUndoRedoModel; + + }; + +} + + +#endif // VariablesView_h diff --git a/glabels/icons.qrc b/glabels/icons.qrc index 8d4f777..faa0f30 100644 --- a/glabels/icons.qrc +++ b/glabels/icons.qrc @@ -102,6 +102,7 @@ icons/flat/48x48/glabels-merge.svg icons/flat/48x48/glabels-print.svg icons/flat/48x48/glabels-properties.svg + icons/flat/48x48/glabels-variables.svg icons/apps/48x48/glabels.svg icons/apps/128x128/glabels.svg diff --git a/glabels/icons/flat/48x48/glabels-variables.svg b/glabels/icons/flat/48x48/glabels-variables.svg new file mode 100644 index 0000000..9b47813 --- /dev/null +++ b/glabels/icons/flat/48x48/glabels-variables.svg @@ -0,0 +1,15 @@ + + + + + + + + + + + diff --git a/glabels/ui/MergeView.ui b/glabels/ui/MergeView.ui index e73b77a..e29278c 100644 --- a/glabels/ui/MergeView.ui +++ b/glabels/ui/MergeView.ui @@ -11,12 +11,21 @@ - Form + Form - + + 12 + + + 12 + + + 12 + + 12 diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index 3e0589e..0493a38 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -7,7 +7,7 @@ 0 0 400 - 640 + 648 @@ -29,7 +29,7 @@ - Form + Form diff --git a/glabels/ui/PrintView.ui b/glabels/ui/PrintView.ui index d4ea498..ac76237 100644 --- a/glabels/ui/PrintView.ui +++ b/glabels/ui/PrintView.ui @@ -17,7 +17,7 @@ - Form + Form diff --git a/glabels/ui/PropertiesView.ui b/glabels/ui/PropertiesView.ui index 60c0632..0f27550 100644 --- a/glabels/ui/PropertiesView.ui +++ b/glabels/ui/PropertiesView.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/StartupView.ui b/glabels/ui/StartupView.ui index 246e5c0..0aca3cb 100644 --- a/glabels/ui/StartupView.ui +++ b/glabels/ui/StartupView.ui @@ -11,7 +11,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerApplyPage.ui b/glabels/ui/TemplateDesignerApplyPage.ui index d0ed63b..3b1b913 100644 --- a/glabels/ui/TemplateDesignerApplyPage.ui +++ b/glabels/ui/TemplateDesignerApplyPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerCdPage.ui b/glabels/ui/TemplateDesignerCdPage.ui index f61fa31..a9add20 100644 --- a/glabels/ui/TemplateDesignerCdPage.ui +++ b/glabels/ui/TemplateDesignerCdPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerContinuousPage.ui b/glabels/ui/TemplateDesignerContinuousPage.ui index 8960aa6..d3cc112 100644 --- a/glabels/ui/TemplateDesignerContinuousPage.ui +++ b/glabels/ui/TemplateDesignerContinuousPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerEllipsePage.ui b/glabels/ui/TemplateDesignerEllipsePage.ui index 53dec92..0ea9ee5 100644 --- a/glabels/ui/TemplateDesignerEllipsePage.ui +++ b/glabels/ui/TemplateDesignerEllipsePage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerIntroPage.ui b/glabels/ui/TemplateDesignerIntroPage.ui index 90665ff..9b397cb 100644 --- a/glabels/ui/TemplateDesignerIntroPage.ui +++ b/glabels/ui/TemplateDesignerIntroPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerNLayoutsPage.ui b/glabels/ui/TemplateDesignerNLayoutsPage.ui index df42ffd..e88dd2f 100644 --- a/glabels/ui/TemplateDesignerNLayoutsPage.ui +++ b/glabels/ui/TemplateDesignerNLayoutsPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerNamePage.ui b/glabels/ui/TemplateDesignerNamePage.ui index 9bf0d13..a9ed4d7 100644 --- a/glabels/ui/TemplateDesignerNamePage.ui +++ b/glabels/ui/TemplateDesignerNamePage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerOneLayoutPage.ui b/glabels/ui/TemplateDesignerOneLayoutPage.ui index 508cfd4..315266d 100644 --- a/glabels/ui/TemplateDesignerOneLayoutPage.ui +++ b/glabels/ui/TemplateDesignerOneLayoutPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerPageSizePage.ui b/glabels/ui/TemplateDesignerPageSizePage.ui index 38c631f..41686e7 100644 --- a/glabels/ui/TemplateDesignerPageSizePage.ui +++ b/glabels/ui/TemplateDesignerPageSizePage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerPathPage.ui b/glabels/ui/TemplateDesignerPathPage.ui index 2f78452..3b59a4c 100644 --- a/glabels/ui/TemplateDesignerPathPage.ui +++ b/glabels/ui/TemplateDesignerPathPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerRectPage.ui b/glabels/ui/TemplateDesignerRectPage.ui index 7265e8f..a4a4758 100644 --- a/glabels/ui/TemplateDesignerRectPage.ui +++ b/glabels/ui/TemplateDesignerRectPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerRoundPage.ui b/glabels/ui/TemplateDesignerRoundPage.ui index c51aa03..2a6651d 100644 --- a/glabels/ui/TemplateDesignerRoundPage.ui +++ b/glabels/ui/TemplateDesignerRoundPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerShapePage.ui b/glabels/ui/TemplateDesignerShapePage.ui index 0466fbb..a471d6c 100644 --- a/glabels/ui/TemplateDesignerShapePage.ui +++ b/glabels/ui/TemplateDesignerShapePage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/TemplateDesignerTwoLayoutPage.ui b/glabels/ui/TemplateDesignerTwoLayoutPage.ui index d7cc9dc..e3cc62a 100644 --- a/glabels/ui/TemplateDesignerTwoLayoutPage.ui +++ b/glabels/ui/TemplateDesignerTwoLayoutPage.ui @@ -23,7 +23,7 @@ - Form + Form diff --git a/glabels/ui/VariablesView.ui b/glabels/ui/VariablesView.ui new file mode 100644 index 0000000..df37af4 --- /dev/null +++ b/glabels/ui/VariablesView.ui @@ -0,0 +1,69 @@ + + + VariablesView + + + + 0 + 0 + 570 + 605 + + + + Form + + + + + + 12 + + + 12 + + + 12 + + + 12 + + + + + + 0 + 0 + + + + <html><head/><body><p><span style=" font-size:18pt;">Variables</span></p></body></html> + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + onSelectAllButtonClicked() + onUnselectAllButtonClicked() + onLocationButtonClicked() + onFormatComboActivated() + + diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index c3f29d2..fc1cd75 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -251,10 +251,6 @@ MergeView - - Form - - Source @@ -287,7 +283,7 @@ ObjectEditor - Form + Object properties @@ -314,6 +310,14 @@ Word + + Anywhere + + + + None + + Allow printing to shrink text to fit object @@ -374,14 +378,6 @@ File - - None - - - - Anywhere - - Select File... @@ -470,10 +466,6 @@ Opacity: - - Object properties - - PreferencesDialog @@ -516,22 +508,6 @@ PrintView - - Form - - - - Page - - - - of - - - - nn - - Copies @@ -568,13 +544,21 @@ Print + + Page + + + + of + + + + nn + + PropertiesView - - Form - - Product @@ -615,6 +599,14 @@ Change product + + Adjustable Parameters + + + + Label length: + + Orientation @@ -635,14 +627,6 @@ Similar Products - - Adjustable Parameters - - - - Label length: - - SelectProductDialog @@ -705,10 +689,6 @@ StartupView - - Form - - Welcome to gLabels. Let's get started: @@ -732,10 +712,6 @@ TemplateDesignerApplyPage - - Form - - You have completed the gLabels Product Template Designer. If you wish to accept and save your product template, click "Save." @@ -748,7 +724,11 @@ TemplateDesignerCdPage - Form + 6. Margin: + + + + 1. Outer radius: @@ -760,28 +740,16 @@ - 1. Outer radius: + 3. Clipping width: 5. Waste: - - 3. Clipping width: - - - - 6. Margin: - - TemplateDesignerContinuousPage - - Form - - <html><head/><body><p>Click &quot;Cancel&quot; to quit, or click &quot;Back&quot; to begin with a different product.</p></body></html> @@ -789,14 +757,6 @@ TemplateDesignerEllipsePage - - Form - - - - 3. Waste: - - 2. Height: @@ -805,6 +765,10 @@ 1. Width: + + 3. Waste: + + 4. Margin: @@ -812,10 +776,6 @@ TemplateDesignerIntroPage - - Form - - <html><head/><body><p>This dialog will help you create a custom product template. Let's get started:</p></body></html> @@ -839,10 +799,6 @@ TemplateDesignerNLayoutsPage - - Form - - A layout is a set of labels or cards that can be arranged in a simple grid. Most products only need one layout, as in the first example below. The second example illustrates when two layouts are needed. @@ -871,40 +827,32 @@ TemplateDesignerNamePage - Form + (e.g. "Mailing Labels," "Business Cards," ...) Brand: - - (e.g. Avery, Acme, ...) - - Part #: - - (e.g. 8163A) - - Description: - (e.g. "Mailing Labels," "Business Cards," ...) + (e.g. 8163A) + + + + (e.g. Avery, Acme, ...) TemplateDesignerOneLayoutPage - - Form - - Number across (nx): @@ -937,15 +885,7 @@ TemplateDesignerPageSizePage - Form - - - - Page size: - - - - Width: + Roll width: @@ -953,16 +893,16 @@ - Roll width: + Width: + + + + Page size: TemplateDesignerPathPage - - Form - - <html><head/><body><p>Click &quot;Cancel&quot; to quit, or click &quot;Back&quot; to begin with a different product.</p></body></html> @@ -971,15 +911,7 @@ TemplateDesignerRectPage - Form - - - - 1. Width: - - - - 2. Height: + 4. Horizontal waste: @@ -987,13 +919,17 @@ - 4. Horizontal waste: + 1. Width: 5. Vertical waste: + + 2. Height: + + 6. Margin (X): @@ -1010,11 +946,7 @@ TemplateDesignerRoundPage - Form - - - - 2. Waste: + 3. Margin @@ -1022,16 +954,12 @@ - 3. Margin + 2. Waste: TemplateDesignerShapePage - - Form - - Rectangular or square (can have rounded corners) @@ -1051,10 +979,6 @@ TemplateDesignerTwoLayoutPage - - Form - - Distance from left edge (x0): @@ -1197,6 +1121,10 @@ Welcome + + Edit + + Properties @@ -1206,11 +1134,11 @@ - Print + Variables - Edit + Print @@ -1269,6 +1197,14 @@ Select project Merge mode + + &Variables + + + + Select project Variables mode + + &Print @@ -1920,11 +1856,11 @@ - Copy + Roll - Roll + Copy @@ -2102,6 +2038,13 @@ + + glabels::VariablesView + + Variables + + + glabels::barcode::Backends @@ -2240,6 +2183,10 @@ IEC18004 (QRCode) + + Australia Post Standard + + Australia Post Reply Paid @@ -2292,10 +2239,6 @@ Code 49 - - Australia Post Standard - - Code 128 (Mode C suppression) From c9e26c45fb4f0af02e92747cca1e6400bb434c76 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Tue, 5 Mar 2019 21:35:11 -0500 Subject: [PATCH 02/32] 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 From 6255939f39c309f35feafac9285e0bafc453952b Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 16 Mar 2019 18:12:17 -0400 Subject: [PATCH 03/32] Closed MVC loop for VariablesView. --- glabels/EditVariableDialog.cpp | 26 ++++---- glabels/VariablesView.cpp | 108 +++++++++++++++++++++++++++++++-- glabels/VariablesView.h | 3 + model/CMakeLists.txt | 2 + model/Model.cpp | 24 ++++++++ model/Model.h | 6 ++ model/Variable.cpp | 73 +++++++++++++++++++--- model/Variable.h | 49 +++++++++------ model/Variables.cpp | 90 +++++++++++++++++++++++++++ model/Variables.h | 85 ++++++++++++++++++++++++++ translations/glabels_C.ts | 27 +++++++++ 11 files changed, 448 insertions(+), 45 deletions(-) create mode 100644 model/Variables.cpp create mode 100644 model/Variables.h diff --git a/glabels/EditVariableDialog.cpp b/glabels/EditVariableDialog.cpp index ea7d0f3..62de4db 100644 --- a/glabels/EditVariableDialog.cpp +++ b/glabels/EditVariableDialog.cpp @@ -41,10 +41,10 @@ namespace glabels /// void EditVariableDialog::setVariable( const model::Variable& variable ) { - typeCombo->setCurrentIndex( variable.type() ); + typeCombo->setCurrentIndex( static_cast(variable.type()) ); nameEdit->setText( variable.name() ); valueEdit->setText( variable.value() ); - incrementCombo->setCurrentIndex( variable.incrementPolicy() ); + incrementCombo->setCurrentIndex( static_cast(variable.increment()) ); stepSizeEdit->setText( variable.stepSize() ); updateControls(); @@ -59,7 +59,7 @@ namespace glabels return model::Variable( static_cast(typeCombo->currentIndex()), nameEdit->text(), valueEdit->text(), - static_cast(incrementCombo->currentIndex()), + static_cast(incrementCombo->currentIndex()), stepSizeEdit->text() ); } @@ -104,24 +104,24 @@ namespace glabels void EditVariableDialog::updateControls() { model::Variable::Type type = static_cast(typeCombo->currentIndex()); - model::Variable::IncrementPolicy incrementPolicy = static_cast(incrementCombo->currentIndex()); + model::Variable::Increment increment = static_cast(incrementCombo->currentIndex()); - if ( type != model::Variable::TYPE_NUMERIC ) + if ( type != model::Variable::Type::NUMERIC ) { - incrementCombo->setCurrentIndex( model::Variable::INCREMENT_NEVER ); + incrementCombo->setCurrentIndex( static_cast(model::Variable::Increment::NEVER) ); } - if ( incrementPolicy == model::Variable::INCREMENT_NEVER ) + if ( increment == 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) ); + incrementLabel->setEnabled( type == model::Variable::Type::NUMERIC ); + incrementCombo->setEnabled( type == model::Variable::Type::NUMERIC ); + stepSizeLabel->setEnabled( (type == model::Variable::Type::NUMERIC) && + (increment != model::Variable::Increment::NEVER) ); + stepSizeEdit->setEnabled( (type == model::Variable::Type::NUMERIC) && + (increment != model::Variable::Increment::NEVER) ); } diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index ffe64b8..c737b71 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -22,9 +22,22 @@ #include "EditVariableDialog.h" +#include #include +namespace +{ + enum ICol { + I_COL_NAME = 0, + I_COL_TYPE = 1, + I_COL_VALUE = 2, + I_COL_INCREMENT = 3, + I_COL_STEP_SIZE = 4 + }; +} + + namespace glabels { @@ -58,8 +71,9 @@ namespace glabels mUndoRedoModel = undoRedoModel; updateControls(); + loadTable(); - //connect( mModel, SIGNAL(variablesChanged()), this, SLOT(onVariablesChanged()) ); + connect( mModel, SIGNAL(variablesChanged()), this, SLOT(onVariablesChanged()) ); } @@ -79,16 +93,17 @@ namespace glabels { EditVariableDialog dialog( this ); - model::Variable v( model::Variable::TYPE_NUMERIC, + model::Variable v( model::Variable::Type::NUMERIC, "x", "0", - model::Variable::INCREMENT_NEVER, + model::Variable::Increment::NEVER, "0" ); dialog.setVariable( v ); if ( dialog.exec() == QDialog::Accepted ) { - qDebug() << "Add OK."; + mModel->variables()->addVariable( dialog.variable() ); + selectVariable( dialog.variable().name() ); } } @@ -98,6 +113,22 @@ namespace glabels /// void VariablesView::onEditButtonClicked() { + int iRow = table->selectedItems()[0]->row(); + QString name = table->item( iRow, I_COL_NAME )->text(); + + if ( mModel->variables()->hasVariable( name ) ) + { + model::Variable v = mModel->variables()->value( name ); + + EditVariableDialog dialog( this ); + dialog.setVariable( v ); + + if ( dialog.exec() == QDialog::Accepted ) + { + mModel->variables()->replaceVariable( name, dialog.variable() ); + selectVariable( dialog.variable().name() ); + } + } } @@ -106,6 +137,20 @@ namespace glabels /// void VariablesView::onDeleteButtonClicked() { + int iRow = table->selectedItems()[0]->row(); + + QString name = table->item( iRow, I_COL_NAME )->text(); + mModel->variables()->deleteVariable( name ); + } + + + /// + /// Variables Changed + /// + void VariablesView::onVariablesChanged() + { + // Reload table from variables + loadTable(); } @@ -121,4 +166,59 @@ namespace glabels } + /// + /// load table from variables + /// + void VariablesView::loadTable() + { + table->clearContents(); + table->setRowCount( mModel->variables()->size() ); + + int iRow = 0; + for( const auto& v : *mModel->variables() ) + { + auto* typeItem = new QTableWidgetItem( model::Variable::typeToI18nString(v.type()) ); + typeItem->setFlags( typeItem->flags() ^ Qt::ItemIsEditable ); + table->setItem( iRow, I_COL_TYPE, typeItem ); + + auto* nameItem = new QTableWidgetItem( v.name() ); + nameItem->setFlags( nameItem->flags() ^ Qt::ItemIsEditable ); + table->setItem( iRow, I_COL_NAME, nameItem ); + + auto* valueItem = new QTableWidgetItem( v.value() ); + valueItem->setFlags( valueItem->flags() ^ Qt::ItemIsEditable ); + table->setItem( iRow, I_COL_VALUE, valueItem ); + + auto* incrementItem = new QTableWidgetItem( model::Variable::incrementToI18nString(v.increment()) ); + incrementItem->setFlags( incrementItem->flags() ^ Qt::ItemIsEditable ); + table->setItem( iRow, I_COL_INCREMENT, incrementItem ); + + auto* stepSizeItem = new QTableWidgetItem( v.stepSize() ); + stepSizeItem->setFlags( stepSizeItem->flags() ^ Qt::ItemIsEditable ); + table->setItem( iRow, I_COL_STEP_SIZE, stepSizeItem ); + + table->showRow( iRow ); + iRow++; + } + } + + + void VariablesView::selectVariable( const QString& name ) + { + int iRow = 0; + for( const auto& v : *mModel->variables() ) + { + if ( v.name() == name ) + { + qDebug() << "Selecting row " << iRow; + table->setCurrentCell( iRow, 0, + (QItemSelectionModel::Select|QItemSelectionModel::Rows) ); + break; + } + + iRow++; + } + } + + } // namespace glabels diff --git a/glabels/VariablesView.h b/glabels/VariablesView.h index f648cd5..93dca3d 100644 --- a/glabels/VariablesView.h +++ b/glabels/VariablesView.h @@ -64,6 +64,7 @@ namespace glabels void onAddButtonClicked(); void onEditButtonClicked(); void onDeleteButtonClicked(); + void onVariablesChanged(); ///////////////////////////////// @@ -71,6 +72,8 @@ namespace glabels ///////////////////////////////// private: void updateControls(); + void loadTable(); + void selectVariable( const QString& name ); ///////////////////////////////// diff --git a/model/CMakeLists.txt b/model/CMakeLists.txt index 100d5bf..fc7db0c 100644 --- a/model/CMakeLists.txt +++ b/model/CMakeLists.txt @@ -57,6 +57,7 @@ set (Model_sources TextNode.cpp Units.cpp Variable.cpp + Variables.cpp Vendor.cpp XmlCategoryParser.cpp XmlLabelCreator.cpp @@ -81,6 +82,7 @@ set (Model_qobject_headers ModelTextObject.h PageRenderer.h Settings.h + Variables.h ) qt5_wrap_cpp (Model_moc_sources ${Model_qobject_headers}) diff --git a/model/Model.cpp b/model/Model.cpp index b0eb83d..896970d 100644 --- a/model/Model.cpp +++ b/model/Model.cpp @@ -57,7 +57,10 @@ namespace glabels Model::Model() : mUntitledInstance(0), mModified(true), mRotate(false) { + mVariables = new Variables(); mMerge = new merge::None(); + + connect( mVariables, SIGNAL(changed()), this, SLOT(onVariablesChanged()) ); } @@ -66,6 +69,7 @@ namespace glabels /// Model::~Model() { + delete mVariables; delete mMerge; } @@ -302,6 +306,15 @@ namespace glabels } + /// + /// Get variables object + /// + Variables* Model::variables() const + { + return mVariables; + } + + /// /// Get merge object /// @@ -451,6 +464,17 @@ namespace glabels } + /// + /// Variables Changed Slot + /// + void Model::onVariablesChanged() + { + setModified(); + emit changed(); + emit variablesChanged(); + } + + /// /// Merge Source Changed Slot /// diff --git a/model/Model.h b/model/Model.h index 992606e..13b9f4c 100644 --- a/model/Model.h +++ b/model/Model.h @@ -24,6 +24,7 @@ #include "Settings.h" #include "Template.h" +#include "Variables.h" #include "merge/Merge.h" #include "merge/Record.h" @@ -76,6 +77,7 @@ namespace glabels void sizeChanged(); void selectionChanged(); void modifiedChanged(); + void variablesChanged(); void mergeChanged(); void mergeSourceChanged(); void mergeSelectionChanged(); @@ -107,6 +109,8 @@ namespace glabels const QList& objectList() const; + Variables* variables() const; + merge::Merge* merge() const; void setMerge( merge::Merge* merge ); @@ -213,6 +217,7 @@ namespace glabels private slots: void onObjectChanged(); void onObjectMoved(); + void onVariablesChanged(); void onMergeSourceChanged(); void onMergeSelectionChanged(); @@ -229,6 +234,7 @@ namespace glabels QList mObjectList; + Variables* mVariables; merge::Merge* mMerge; }; diff --git a/model/Variable.cpp b/model/Variable.cpp index 3eb309d..e4a3432 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -26,15 +26,15 @@ namespace glabels namespace model { - Variable::Variable( Variable::Type type, - const QString& name, - const QString& value, - Variable::IncrementPolicy incrementPolicy, - const QString& stepSize ) + Variable::Variable( Variable::Type type, + const QString& name, + const QString& value, + Variable::Increment increment, + const QString& stepSize ) : mType(type), mName(name), mValue(value), - mIncrementPolicy(incrementPolicy), + mIncrement(increment), mStepSize(stepSize) { // empty @@ -59,9 +59,9 @@ namespace glabels } - Variable::IncrementPolicy Variable::incrementPolicy() const + Variable::Increment Variable::increment() const { - return mIncrementPolicy; + return mIncrement; } @@ -70,5 +70,62 @@ namespace glabels return mStepSize; } + + QString Variable::typeToI18nString( Type type ) + { + switch (type) + { + case Type::NUMERIC: + return tr("Numeric"); + case Type::STRING: + return tr("String"); + } + } + + + QString Variable::typeToIdString( Type type ) + { + switch (type) + { + case Type::NUMERIC: + return "numeric"; + case Type::STRING: + return "string"; + } + } + + + QString Variable::incrementToI18nString( Increment increment ) + { + switch (increment) + { + case Increment::NEVER: + return tr("Never"); + case Increment::PER_COPY: + return tr("Per copy"); + case Increment::PER_MERGE_RECORD: + return tr("Per merge record"); + case Increment::PER_PAGE: + return tr("Per page"); + } + } + + + QString Variable::incrementToIdString( Increment increment ) + { + switch (increment) + { + case Increment::NEVER: + return "never"; + case Increment::PER_COPY: + return "per_copy"; + case Increment::PER_MERGE_RECORD: + return "per_merge_record"; + case Increment::PER_PAGE: + return "per_page"; + } + } + + } } diff --git a/model/Variable.h b/model/Variable.h index 333857f..d314642 100644 --- a/model/Variable.h +++ b/model/Variable.h @@ -22,6 +22,7 @@ #define model_Variable_h +#include #include @@ -32,19 +33,21 @@ namespace glabels class Variable { + Q_DECLARE_TR_FUNCTIONS(Variable) + public: - enum Type + enum class Type { - TYPE_NUMERIC, - TYPE_STRING + NUMERIC, + STRING }; - enum IncrementPolicy + enum class Increment { - INCREMENT_NEVER, - INCREMENT_PER_COPY, - INCREMENT_PER_MERGE_RECORD, - INCREMENT_PER_PAGE + NEVER, + PER_COPY, + PER_MERGE_RECORD, + PER_PAGE }; @@ -54,26 +57,32 @@ namespace glabels Variable( Type type, const QString& name, const QString& value, - IncrementPolicy incrementPolicy = INCREMENT_NEVER, + Increment increment = Increment::NEVER, const QString& stepSize = "0" ); virtual ~Variable() = default; - Type type() const; - QString name() const; - QString value() const; - IncrementPolicy incrementPolicy() const; - QString stepSize() const; - + Type type() const; + QString name() const; + QString value() const; + Increment increment() const; + QString stepSize() const; + + + static QString typeToI18nString( Type type ); + static QString typeToIdString( Type type ); + + static QString incrementToI18nString( Increment increment ); + static QString incrementToIdString( Increment increment ); private: - Type mType; - QString mName; - QString mValue; - IncrementPolicy mIncrementPolicy; - QString mStepSize; + Type mType; + QString mName; + QString mValue; + Increment mIncrement; + QString mStepSize; }; diff --git a/model/Variables.cpp b/model/Variables.cpp new file mode 100644 index 0000000..24d414f --- /dev/null +++ b/model/Variables.cpp @@ -0,0 +1,90 @@ +/* Variables.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 "Variables.h" + +#include + + +namespace glabels +{ + namespace model + { + /// + /// Copy constructor + /// + Variables::Variables( const Variables* variables ) + : QMap(*variables) + { + } + + + /// + /// Clone + /// + Variables* Variables::clone() const + { + return new Variables( this ); + } + + + /// + /// Do we have variable? + /// + bool Variables::hasVariable( const QString& name ) const + { + return contains(name); + } + + + /// + /// Add variable ( will replace if name is the same ) + /// + void Variables::addVariable( const Variable& variable ) + { + insert( variable.name(), variable ); + emit changed(); + } + + + /// + /// Delete variable + /// + void Variables::deleteVariable( const QString& name ) + { + remove( name ); + emit changed(); + } + + + /// + /// Replace variable + /// + void Variables::replaceVariable( const QString& origName, const Variable& variable ) + { + remove( origName ); + insert( variable.name(), variable ); + emit changed(); + } + + + } // namespace model + +} // namespace glabels diff --git a/model/Variables.h b/model/Variables.h new file mode 100644 index 0000000..0c1a020 --- /dev/null +++ b/model/Variables.h @@ -0,0 +1,85 @@ +/* Variables.h + * + * 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 . + */ + +#ifndef model_Variables_h +#define model_Variables_h + + +#include "Variable.h" + +#include +#include +#include + + +namespace glabels +{ + namespace model + { + + /// + /// Variables Collection + /// + class Variables : public QObject, public QMap + { + Q_OBJECT + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// + public: + Variables() = default; + Variables( const Variables* variables ); + + + ///////////////////////////////// + // Object duplication + ///////////////////////////////// + Variables* clone() const; + + + ///////////////////////////////// + // Methods + ///////////////////////////////// + bool hasVariable( const QString& name ) const; + void addVariable( const Variable& variable ); + void deleteVariable( const QString& name ); + void replaceVariable( const QString& name, const Variable& variable ); + + + ///////////////////////////////// + // Signals + ///////////////////////////////// + signals: + void changed(); + + + ///////////////////////////////// + // Private data + ///////////////////////////////// + private: + + }; + + } +} + + +#endif // model_Variables_h diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 844a98f..59305a8 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1082,6 +1082,33 @@ + + Variable + + Numeric + + + + String + + + + Never + + + + Per copy + + + + Per merge record + + + + Per page + + + VariablesView From d05c6fbfd2bc045eeb98029d9cc26a19584d0282 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 17 Mar 2019 14:24:55 -0400 Subject: [PATCH 04/32] Fleshed out input validation for EditVariableDialog. --- glabels/EditVariableDialog.cpp | 84 +++++++++++++++++++++++++++++--- glabels/EditVariableDialog.h | 2 + glabels/VariablesView.cpp | 1 - glabels/ui/EditVariableDialog.ui | 53 ++++++++------------ translations/glabels_C.ts | 24 --------- 5 files changed, 97 insertions(+), 67 deletions(-) diff --git a/glabels/EditVariableDialog.cpp b/glabels/EditVariableDialog.cpp index 62de4db..2abcb12 100644 --- a/glabels/EditVariableDialog.cpp +++ b/glabels/EditVariableDialog.cpp @@ -22,6 +22,26 @@ #include "model/Settings.h" +#include + + +namespace +{ + // All variable types. (must be in sorted order) + const QVector allTypes = { + glabels::model::Variable::Type::NUMERIC, + glabels::model::Variable::Type::STRING + }; + + // All variable increments. (must be in sorted order) + const QVector allIncrements = { + glabels::model::Variable::Increment::NEVER, + glabels::model::Variable::Increment::PER_COPY, + glabels::model::Variable::Increment::PER_MERGE_RECORD, + glabels::model::Variable::Increment::PER_PAGE + }; +} + namespace glabels { @@ -33,6 +53,19 @@ namespace glabels : QDialog(parent) { setupUi( this ); + + QRegularExpression reIdentifier( "[a-zA-Z_][a-zA-Z_0-9]*" ); + nameEdit->setValidator( new QRegularExpressionValidator( reIdentifier ) ); + + for ( auto type : allTypes ) + { + typeCombo->addItem( model::Variable::typeToI18nString( type ) ); + } + + for ( auto type : allIncrements ) + { + incrementCombo->addItem( model::Variable::incrementToI18nString( type ) ); + } } @@ -64,6 +97,15 @@ namespace glabels } + /// + /// nameEdit Changed + /// + void EditVariableDialog::onNameEditChanged() + { + validateCurrentInputs(); + } + + /// /// typeCombo Changed /// @@ -78,6 +120,7 @@ namespace glabels /// void EditVariableDialog::onValueEditChanged() { + validateCurrentInputs(); } @@ -95,6 +138,7 @@ namespace glabels /// void EditVariableDialog::onStepSizeEditChanged() { + validateCurrentInputs(); } @@ -103,25 +147,49 @@ namespace glabels /// void EditVariableDialog::updateControls() { - model::Variable::Type type = static_cast(typeCombo->currentIndex()); - model::Variable::Increment increment = static_cast(incrementCombo->currentIndex()); + auto type = static_cast(typeCombo->currentIndex()); + auto increment = static_cast(incrementCombo->currentIndex()); - if ( type != model::Variable::Type::NUMERIC ) + if ( type == model::Variable::Type::NUMERIC ) { + valueEdit->setValidator( new QDoubleValidator() ); + stepSizeEdit->setValidator( new QDoubleValidator() ); + + if ( increment == model::Variable::Increment::NEVER ) + { + stepSizeEdit->setText( "0" ); + } + } + else + { + valueEdit->setValidator( nullptr ); + stepSizeEdit->setValidator( nullptr ); incrementCombo->setCurrentIndex( static_cast(model::Variable::Increment::NEVER) ); + stepSizeEdit->setText( "" ); } - if ( increment == 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) && (increment != model::Variable::Increment::NEVER) ); stepSizeEdit->setEnabled( (type == model::Variable::Type::NUMERIC) && (increment != model::Variable::Increment::NEVER) ); + + validateCurrentInputs(); + } + + + /// + /// validate current inputs + /// + void EditVariableDialog::validateCurrentInputs() + { + bool hasValidIdentifier = nameEdit->hasAcceptableInput(); + bool hasValidValue = valueEdit->hasAcceptableInput(); + bool hasValidStepSize = stepSizeEdit->hasAcceptableInput(); + + bool isValid = hasValidIdentifier && hasValidValue && hasValidStepSize; + buttonBox->button(QDialogButtonBox::Ok)->setEnabled( isValid ); } diff --git a/glabels/EditVariableDialog.h b/glabels/EditVariableDialog.h index 1419f2c..8c57a20 100644 --- a/glabels/EditVariableDialog.h +++ b/glabels/EditVariableDialog.h @@ -54,6 +54,7 @@ namespace glabels // Slots ///////////////////////////////// private slots: + void onNameEditChanged(); void onTypeComboChanged(); void onValueEditChanged(); void onIncrementComboChanged(); @@ -64,6 +65,7 @@ namespace glabels // Private methods ///////////////////////////////// void updateControls(); + void validateCurrentInputs(); }; diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index c737b71..088fe70 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -210,7 +210,6 @@ namespace glabels { if ( v.name() == name ) { - qDebug() << "Selecting row " << iRow; table->setCurrentCell( iRow, 0, (QItemSelectionModel::Select|QItemSelectionModel::Rows) ); break; diff --git a/glabels/ui/EditVariableDialog.ui b/glabels/ui/EditVariableDialog.ui index 8cd925e..11399a7 100644 --- a/glabels/ui/EditVariableDialog.ui +++ b/glabels/ui/EditVariableDialog.ui @@ -24,18 +24,7 @@ - - - - Numeric - - - - - String - - - + @@ -67,28 +56,7 @@ - - - - Never - - - - - Per Copy - - - - - Per Merge Record - - - - - Per Page - - - + @@ -227,11 +195,28 @@ + + nameEdit + textChanged(QString) + EditVariableDialog + onNameEditChanged() + + + 371 + 62 + + + 393 + 165 + + + onTypeComboChanged() onValueEditChanged() onIncrementComboChanged() onStepSizeEditChanged() + onNameEditChanged() diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 59305a8..29dc951 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -188,14 +188,6 @@ Variable Type: - - Numeric - - - - String - - Name: @@ -208,22 +200,6 @@ Increment: - - Never - - - - Per Copy - - - - Per Merge Record - - - - Per Page - - Step Size: From dab2c1986217c88ceee0e604062c1d6b1cc00946 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 17 Mar 2019 14:35:29 -0400 Subject: [PATCH 05/32] Add window titles to "Add Variable" and "Edit Variable" dialogs. --- glabels/VariablesView.cpp | 2 ++ translations/glabels_C.ts | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index 088fe70..0546566 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -99,6 +99,7 @@ namespace glabels model::Variable::Increment::NEVER, "0" ); dialog.setVariable( v ); + dialog.setWindowTitle( tr("Add Variable") ); if ( dialog.exec() == QDialog::Accepted ) { @@ -122,6 +123,7 @@ namespace glabels EditVariableDialog dialog( this ); dialog.setVariable( v ); + dialog.setWindowTitle( tr("Edit Variable") ); if ( dialog.exec() == QDialog::Accepted ) { diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 29dc951..5708957 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -2145,6 +2145,14 @@ Variables + + Add Variable + + + + Edit Variable + + glabels::barcode::Backends From 879092deaa387bcff849f231c66694b391c3b2a2 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 17 Mar 2019 19:55:05 -0400 Subject: [PATCH 06/32] Updated substitution field spec and TODO document. --- docs/SUBSTITUTION-FIELD-SPEC.md | 39 +++++++++++++++++++-------------- docs/TODO.md | 12 ++++++++++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/docs/SUBSTITUTION-FIELD-SPEC.md b/docs/SUBSTITUTION-FIELD-SPEC.md index b69ff38..ddfc2ef 100644 --- a/docs/SUBSTITUTION-FIELD-SPEC.md +++ b/docs/SUBSTITUTION-FIELD-SPEC.md @@ -17,6 +17,28 @@ modifiers = modifier [ ":" modifiers ] ; modifier = format-modifier | default-value-modifier | new-line-modifier; ``` + +Field Names +----------- +Field names can refer to either [Document Merge Fields](#document-merge-fields) or [User Variables](#user-variables). If a document merge field and a user variable share the same name, the document merge field takes precidence. Its syntax is simply: + +```ebnf +field-name = merge-field-name | user-variable-name ; +``` + +### Document Merge Fields +Document merge fields are the primary source of substitution fields. A document merge field represents a field from an external data source, such as a CSV file. The valid syntax for a document merge field name is determined by the merge source, with the following exception. Merge field names cannot contain either a colon (":") or closing curly bracket ("}"). + +### User Variables +Substitution fields can also refer to user variables. The syntax for valid user variable names is + +```ebnf +letter = "a" | "b" | ... | "z" | "A" | ... | "Z"; +digit = "0" | "1" | "2" | ... | "9"; +user-variable-name = ( letter | "_" ) , { letter | digit | "_" } ; +``` + + Modifiers --------- ### Format-Modifier (`%`) @@ -89,20 +111,3 @@ ${CITY} ${STATE} ${ZIP} `${ADDR2}` would be printed on its own line, only if it is set and non-empty. -Document Merge Fields ---------------------- -Document merge fields are the primary source of substitution fields. A document merge field represents a field from an external data source, such as a CSV file. - -User Defined Variables ----------------------- -Alternatively, merge fields can refer to user defined variables. - -Built-In Variables ------------------- -Potentially, merge fields may also refer to built-in variables. Candidates include: - - LABEL_NUMBER - - PAGE_NUMBER - - DATE - - TIME - - FILE_NAME - diff --git a/docs/TODO.md b/docs/TODO.md index 6eb3cb8..039f682 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -29,3 +29,15 @@ Add support for "Continuous Roll" labels Write help documentation ------------------------ + + +To Do List for gLabels 4.1 -- 2019-03-17 +======================================== + +Create a "built-in" merge source +-------------------------------- +As an alternative to external merge sources, let the user edit the merge source +in situ. The user can add fields. The user can add records using those fields. +The user created database will become part of the glabels project file. +For simple databases, such as a small address list, this would be much easier +to deal with than creating it externally. From 3a425f932a1fee57f46c3e25d8a6105d141a286f Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 17 Mar 2019 22:38:45 -0400 Subject: [PATCH 07/32] Include variables in glabels project file. --- glabels/ui/VariablesView.ui | 3 +++ model/Variable.cpp | 42 +++++++++++++++++++++++++++++++++ model/Variable.h | 10 ++++---- model/XmlLabelCreator.cpp | 35 +++++++++++++++++++++++++++ model/XmlLabelCreator.h | 3 +++ model/XmlLabelParser.cpp | 47 +++++++++++++++++++++++++++++++------ model/XmlLabelParser.h | 3 ++- templates/glabels-4.0.dtd | 20 +++++++++++++++- 8 files changed, 150 insertions(+), 13 deletions(-) diff --git a/glabels/ui/VariablesView.ui b/glabels/ui/VariablesView.ui index 04ec15b..801bb2c 100644 --- a/glabels/ui/VariablesView.ui +++ b/glabels/ui/VariablesView.ui @@ -38,6 +38,9 @@ 5 + + false + Name diff --git a/model/Variable.cpp b/model/Variable.cpp index e4a3432..b424a6b 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -95,6 +95,23 @@ namespace glabels } + Variable::Type Variable::idStringToType( const QString& string ) + { + if ( string == "numeric" ) + { + return Type::NUMERIC; + } + else if ( string == "string" ) + { + return Type::STRING; + } + else + { + return Type::STRING; // Default + } + } + + QString Variable::incrementToI18nString( Increment increment ) { switch (increment) @@ -127,5 +144,30 @@ namespace glabels } + Variable::Increment Variable::idStringToIncrement( const QString& string ) + { + if ( string == "never" ) + { + return Increment::NEVER; + } + else if ( string == "per_copy" ) + { + return Increment::PER_COPY; + } + else if ( string == "per_merge_record" ) + { + return Increment::PER_MERGE_RECORD; + } + else if ( string == "per_page" ) + { + return Increment::PER_PAGE; + } + else + { + return Increment::NEVER; // Default + } + } + + } } diff --git a/model/Variable.h b/model/Variable.h index d314642..0a90733 100644 --- a/model/Variable.h +++ b/model/Variable.h @@ -70,11 +70,13 @@ namespace glabels QString stepSize() const; - static QString typeToI18nString( Type type ); - static QString typeToIdString( Type type ); + static QString typeToI18nString( Type type ); + static QString typeToIdString( Type type ); + static Type idStringToType( const QString& string ); - static QString incrementToI18nString( Increment increment ); - static QString incrementToIdString( Increment increment ); + static QString incrementToI18nString( Increment increment ); + static QString incrementToIdString( Increment increment ); + static Increment idStringToIncrement( const QString& string ); private: diff --git a/model/XmlLabelCreator.cpp b/model/XmlLabelCreator.cpp index 87b3114..2a31cf0 100644 --- a/model/XmlLabelCreator.cpp +++ b/model/XmlLabelCreator.cpp @@ -29,6 +29,7 @@ #include "ModelImageObject.h" #include "ModelTextObject.h" #include "DataCache.h" +#include "Variables.h" #include "XmlTemplateCreator.h" #include "XmlUtil.h" @@ -116,6 +117,11 @@ namespace glabels createMergeNode( root, label ); } + if ( label->variables()->size() != 0 ) + { + createVariablesNode( root, label ); + } + createDataNode( root, label->objectList() ); } @@ -466,6 +472,35 @@ namespace glabels } + void + XmlLabelCreator::createVariablesNode( QDomElement &parent, const Model* label ) + { + QDomDocument doc = parent.ownerDocument(); + QDomElement node = doc.createElement( "Variables" ); + parent.appendChild( node ); + + for ( const auto& v : *label->variables() ) + { + createVariableNode( node, v ); + } + } + + + void + XmlLabelCreator::createVariableNode( QDomElement &parent, const Variable& v ) + { + QDomDocument doc = parent.ownerDocument(); + QDomElement node = doc.createElement( "Variable" ); + parent.appendChild( node ); + + XmlUtil::setStringAttr( node, "type", Variable::typeToIdString( v.type() ) ); + XmlUtil::setStringAttr( node, "name", v.name() ); + XmlUtil::setStringAttr( node, "value", v.value() ); + XmlUtil::setStringAttr( node, "increment", Variable::incrementToIdString( v.increment() ) ); + XmlUtil::setStringAttr( node, "stepSize", v.stepSize() ); + } + + void XmlLabelCreator::createDataNode( QDomElement &parent, const QList& objects ) { diff --git a/model/XmlLabelCreator.h b/model/XmlLabelCreator.h index 93c235e..2e3d87a 100644 --- a/model/XmlLabelCreator.h +++ b/model/XmlLabelCreator.h @@ -40,6 +40,7 @@ namespace glabels class ModelImageObject; class ModelBarcodeObject; class ModelTextObject; + class Variable; /// @@ -72,6 +73,8 @@ namespace glabels static void createAffineAttrs( QDomElement &node, const ModelObject* object ); static void createShadowAttrs( QDomElement &node, const ModelObject* object ); static void createMergeNode( QDomElement &parent, const Model* label ); + static void createVariablesNode( QDomElement &parent, const Model* label ); + static void createVariableNode( QDomElement &parent, const Variable& v ); static void createDataNode( QDomElement &parent, const QList& objects ); static void createPngFileNode( QDomElement &parent, const QString& name, const QImage& image ); static void createSvgFileNode( QDomElement &parent, const QString& name, const QByteArray& svg ); diff --git a/model/XmlLabelParser.cpp b/model/XmlLabelParser.cpp index 779149c..9412dd7 100644 --- a/model/XmlLabelParser.cpp +++ b/model/XmlLabelParser.cpp @@ -286,6 +286,10 @@ namespace glabels { parseMergeNode( child.toElement(), label ); } + else if ( tagName == "Variables" ) + { + parseVariablesNode( child.toElement(), label ); + } else if ( tagName == "Data" ) { /* Handled in pass 1. */ @@ -719,6 +723,42 @@ namespace glabels } + void + XmlLabelParser::parseVariablesNode( const QDomElement &node, Model* label ) + { + for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() ) + { + QString tagName = child.toElement().tagName(); + + if ( tagName == "Variable" ) + { + parseVariableNode( child.toElement(), label ); + } + else if ( !child.isComment() ) + { + qWarning() << "Unexpected" << node.tagName() << "child:" << tagName; + } + } + } + + + void + XmlLabelParser::parseVariableNode( const QDomElement &node, Model* label ) + { + QString typeString = XmlUtil::getStringAttr( node, "type", "string" ); + QString name = XmlUtil::getStringAttr( node, "name", "unknown" ); + QString value = XmlUtil::getStringAttr( node, "value", "0" ); + QString incrementString = XmlUtil::getStringAttr( node, "increment", "never" ); + QString stepSize = XmlUtil::getStringAttr( node, "stepSize", "0" ); + + auto type = Variable::idStringToType( typeString ); + auto increment = Variable::idStringToIncrement( incrementString ); + + Variable v( type, name, value, increment, stepSize ); + label->variables()->addVariable( v ); + } + + void XmlLabelParser::parseDataNode( const QDomElement &node, DataCache& data ) { @@ -738,13 +778,6 @@ namespace glabels } - void - XmlLabelParser::parsePixdataNode( const QDomElement& node, DataCache& data ) - { - // TODO, compatibility with glabels-3 - } - - void XmlLabelParser::parseFileNode( const QDomElement& node, DataCache& data ) { diff --git a/model/XmlLabelParser.h b/model/XmlLabelParser.h index f135860..c13edf4 100644 --- a/model/XmlLabelParser.h +++ b/model/XmlLabelParser.h @@ -68,8 +68,9 @@ namespace glabels static QString parsePNode( const QDomElement &node ); static bool parseRotateAttr( const QDomElement &node ); static void parseMergeNode( const QDomElement &node, Model* label ); + static void parseVariablesNode( const QDomElement &node, Model* label ); + static void parseVariableNode( const QDomElement &node, Model* label ); static void parseDataNode( const QDomElement &node, DataCache& data ); - static void parsePixdataNode( const QDomElement &node, DataCache& data ); static void parseFileNode( const QDomElement &node, DataCache& data ); }; diff --git a/templates/glabels-4.0.dtd b/templates/glabels-4.0.dtd index 5834460..a883c94 100644 --- a/templates/glabels-4.0.dtd +++ b/templates/glabels-4.0.dtd @@ -87,6 +87,10 @@ iec16022)" --> + + + + @@ -139,7 +143,7 @@ - + + + + + + + + + From ff15eb1d7e023a9a52e57d2881ec194f8dd86252 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Fri, 22 Mar 2019 20:06:57 -0400 Subject: [PATCH 08/32] Disable focus on QTableWidgets. No more annoying highlighted cell. --- glabels/ui/MergeView.ui | 6 +++++- glabels/ui/VariablesView.ui | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/glabels/ui/MergeView.ui b/glabels/ui/MergeView.ui index e29278c..89517fd 100644 --- a/glabels/ui/MergeView.ui +++ b/glabels/ui/MergeView.ui @@ -98,7 +98,11 @@ - + + + Qt::NoFocus + + diff --git a/glabels/ui/VariablesView.ui b/glabels/ui/VariablesView.ui index 801bb2c..5758b63 100644 --- a/glabels/ui/VariablesView.ui +++ b/glabels/ui/VariablesView.ui @@ -29,6 +29,9 @@ + + Qt::NoFocus + QAbstractItemView::SingleSelection @@ -41,6 +44,9 @@ false + + true + Name From dedbe073128f3d0807110448492c10ea2178d570 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Fri, 22 Mar 2019 23:23:50 -0400 Subject: [PATCH 09/32] Populate VariablesView headers in class rather than ui/. --- glabels/VariablesView.cpp | 39 +++++++++++++++++++++++++++++++----- glabels/ui/VariablesView.ui | 27 +------------------------ translations/glabels_C.ts | 40 ++++++++++++++++++------------------- 3 files changed, 55 insertions(+), 51 deletions(-) diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index 0546566..a54a43f 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -29,11 +29,13 @@ namespace { enum ICol { - I_COL_NAME = 0, - I_COL_TYPE = 1, - I_COL_VALUE = 2, - I_COL_INCREMENT = 3, - I_COL_STEP_SIZE = 4 + I_COL_NAME, + I_COL_TYPE, + I_COL_VALUE, + I_COL_INCREMENT, + I_COL_STEP_SIZE, + I_COL_DUMMY, + N_COLS }; } @@ -50,6 +52,33 @@ namespace glabels setupUi( this ); titleLabel->setText( QString( "%1" ).arg( tr("Variables") ) ); + + table->setColumnCount( N_COLS ); + + auto* nameHeaderItem = new QTableWidgetItem( tr("Name") ); + nameHeaderItem->setFlags( nameHeaderItem->flags() ^ Qt::ItemIsEditable ); + table->setHorizontalHeaderItem( I_COL_NAME, nameHeaderItem ); + + auto* typeHeaderItem = new QTableWidgetItem( tr("Type") ); + typeHeaderItem->setFlags( typeHeaderItem->flags() ^ Qt::ItemIsEditable ); + table->setHorizontalHeaderItem( I_COL_TYPE, typeHeaderItem ); + + auto* valueHeaderItem = new QTableWidgetItem( tr("Value") ); + valueHeaderItem->setFlags( valueHeaderItem->flags() ^ Qt::ItemIsEditable ); + table->setHorizontalHeaderItem( I_COL_VALUE, valueHeaderItem ); + + auto* incrementHeaderItem = new QTableWidgetItem( tr("Increment") ); + incrementHeaderItem->setFlags( incrementHeaderItem->flags() ^ Qt::ItemIsEditable ); + table->setHorizontalHeaderItem( I_COL_INCREMENT, incrementHeaderItem ); + + auto* stepSizeHeaderItem = new QTableWidgetItem( tr("Step Size") ); + stepSizeHeaderItem->setFlags( stepSizeHeaderItem->flags() ^ Qt::ItemIsEditable ); + table->setHorizontalHeaderItem( I_COL_STEP_SIZE, stepSizeHeaderItem ); + + auto* dummyHeaderItem = new QTableWidgetItem(); + dummyHeaderItem->setFlags( Qt::NoItemFlags ); + table->setHorizontalHeaderItem( I_COL_DUMMY, dummyHeaderItem ); + table->horizontalHeader()->setStretchLastSection( true ); } diff --git a/glabels/ui/VariablesView.ui b/glabels/ui/VariablesView.ui index 5758b63..a801498 100644 --- a/glabels/ui/VariablesView.ui +++ b/glabels/ui/VariablesView.ui @@ -39,7 +39,7 @@ QAbstractItemView::SelectRows - 5 + 0 false @@ -47,31 +47,6 @@ true - - - Name - - - - - Type - - - - - Value - - - - - Increment - - - - - Step Size - - diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 5708957..fb84528 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1087,26 +1087,6 @@ VariablesView - - Name - - - - Type - - - - Value - - - - Increment - - - - Step Size - - <html><head/><body><p>Add variable</p></body></html> @@ -2153,6 +2133,26 @@ Edit Variable + + Name + + + + Type + + + + Value + + + + Increment + + + + Step Size + + glabels::barcode::Backends From 37f0a8890d195084d02800357072896f69ee77d4 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 24 Mar 2019 17:49:41 -0400 Subject: [PATCH 10/32] Implemented variable substitution in simple print jobs. --- glabels/EditVariableDialog.cpp | 42 +++++-- glabels/LabelEditor.cpp | 2 +- glabels/VariablesView.cpp | 6 +- glabels/ui/EditVariableDialog.ui | 6 +- model/Model.cpp | 4 +- model/Model.h | 5 +- model/ModelBarcodeObject.cpp | 13 +- model/ModelBarcodeObject.h | 19 ++- model/ModelBoxObject.cpp | 10 +- model/ModelBoxObject.h | 12 +- model/ModelEllipseObject.cpp | 10 +- model/ModelEllipseObject.h | 12 +- model/ModelImageObject.cpp | 10 +- model/ModelImageObject.h | 12 +- model/ModelLineObject.cpp | 10 +- model/ModelLineObject.h | 12 +- model/ModelObject.cpp | 9 +- model/ModelObject.h | 19 ++- model/ModelTextObject.cpp | 21 ++-- model/ModelTextObject.h | 27 +++- model/PageRenderer.cpp | 62 +++++---- model/PageRenderer.h | 4 +- model/RawText.cpp | 4 +- model/RawText.h | 2 +- model/SubstitutionField.cpp | 18 ++- model/SubstitutionField.h | 3 +- model/Variable.cpp | 139 ++++++++++++++++++--- model/Variable.h | 21 +++- model/Variables.cpp | 48 +++++++ model/Variables.h | 5 + model/XmlLabelCreator.cpp | 2 +- model/XmlLabelParser.cpp | 4 +- model/unit_tests/TestSubstitutionField.cpp | 106 +++++++++------- translations/glabels_C.ts | 38 +++--- 34 files changed, 524 insertions(+), 193 deletions(-) diff --git a/glabels/EditVariableDialog.cpp b/glabels/EditVariableDialog.cpp index 2abcb12..4d3b84d 100644 --- a/glabels/EditVariableDialog.cpp +++ b/glabels/EditVariableDialog.cpp @@ -29,8 +29,9 @@ namespace { // All variable types. (must be in sorted order) const QVector allTypes = { - glabels::model::Variable::Type::NUMERIC, - glabels::model::Variable::Type::STRING + glabels::model::Variable::Type::STRING, + glabels::model::Variable::Type::INTEGER, + glabels::model::Variable::Type::FLOATING_POINT }; // All variable increments. (must be in sorted order) @@ -76,7 +77,7 @@ namespace glabels { typeCombo->setCurrentIndex( static_cast(variable.type()) ); nameEdit->setText( variable.name() ); - valueEdit->setText( variable.value() ); + valueEdit->setText( variable.initialValue() ); incrementCombo->setCurrentIndex( static_cast(variable.increment()) ); stepSizeEdit->setText( variable.stepSize() ); @@ -150,8 +151,20 @@ namespace glabels auto type = static_cast(typeCombo->currentIndex()); auto increment = static_cast(incrementCombo->currentIndex()); - if ( type == model::Variable::Type::NUMERIC ) + switch (type) { + + case model::Variable::Type::INTEGER: + valueEdit->setValidator( new QIntValidator() ); + stepSizeEdit->setValidator( new QIntValidator() ); + + if ( increment == model::Variable::Increment::NEVER ) + { + stepSizeEdit->setText( "0" ); + } + break; + + case model::Variable::Type::FLOATING_POINT: valueEdit->setValidator( new QDoubleValidator() ); stepSizeEdit->setValidator( new QDoubleValidator() ); @@ -159,21 +172,24 @@ namespace glabels { stepSizeEdit->setText( "0" ); } - } - else - { + break; + + default: valueEdit->setValidator( nullptr ); stepSizeEdit->setValidator( nullptr ); incrementCombo->setCurrentIndex( static_cast(model::Variable::Increment::NEVER) ); stepSizeEdit->setText( "" ); + break; + } - incrementLabel->setEnabled( type == model::Variable::Type::NUMERIC ); - incrementCombo->setEnabled( type == model::Variable::Type::NUMERIC ); - stepSizeLabel->setEnabled( (type == model::Variable::Type::NUMERIC) && - (increment != model::Variable::Increment::NEVER) ); - stepSizeEdit->setEnabled( (type == model::Variable::Type::NUMERIC) && - (increment != model::Variable::Increment::NEVER) ); + bool isNumeric = ( type == model::Variable::Type::INTEGER ) || + ( type == model::Variable::Type::FLOATING_POINT ); + + incrementLabel->setEnabled( isNumeric ); + incrementCombo->setEnabled( isNumeric ); + stepSizeLabel->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) ); + stepSizeEdit->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) ); validateCurrentInputs(); } diff --git a/glabels/LabelEditor.cpp b/glabels/LabelEditor.cpp index ef7fe05..82c272a 100644 --- a/glabels/LabelEditor.cpp +++ b/glabels/LabelEditor.cpp @@ -1157,7 +1157,7 @@ namespace glabels void LabelEditor::drawObjectsLayer( QPainter* painter ) { - mModel->draw( painter ); + mModel->draw( painter, true, nullptr, nullptr ); } diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index a54a43f..9487085 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -63,7 +63,7 @@ namespace glabels typeHeaderItem->setFlags( typeHeaderItem->flags() ^ Qt::ItemIsEditable ); table->setHorizontalHeaderItem( I_COL_TYPE, typeHeaderItem ); - auto* valueHeaderItem = new QTableWidgetItem( tr("Value") ); + auto* valueHeaderItem = new QTableWidgetItem( tr("Initial Value") ); valueHeaderItem->setFlags( valueHeaderItem->flags() ^ Qt::ItemIsEditable ); table->setHorizontalHeaderItem( I_COL_VALUE, valueHeaderItem ); @@ -122,7 +122,7 @@ namespace glabels { EditVariableDialog dialog( this ); - model::Variable v( model::Variable::Type::NUMERIC, + model::Variable v( model::Variable::Type::INTEGER, "x", "0", model::Variable::Increment::NEVER, @@ -216,7 +216,7 @@ namespace glabels nameItem->setFlags( nameItem->flags() ^ Qt::ItemIsEditable ); table->setItem( iRow, I_COL_NAME, nameItem ); - auto* valueItem = new QTableWidgetItem( v.value() ); + auto* valueItem = new QTableWidgetItem( v.initialValue() ); valueItem->setFlags( valueItem->flags() ^ Qt::ItemIsEditable ); table->setItem( iRow, I_COL_VALUE, valueItem ); diff --git a/glabels/ui/EditVariableDialog.ui b/glabels/ui/EditVariableDialog.ui index 11399a7..af81a20 100644 --- a/glabels/ui/EditVariableDialog.ui +++ b/glabels/ui/EditVariableDialog.ui @@ -19,7 +19,7 @@ - Variable Type: + Variable type: @@ -39,7 +39,7 @@ - Value: + Initial value: @@ -61,7 +61,7 @@ - Step Size: + Step size: diff --git a/model/Model.cpp b/model/Model.cpp index 896970d..4fe8b34 100644 --- a/model/Model.cpp +++ b/model/Model.cpp @@ -1476,11 +1476,11 @@ namespace glabels /// /// Draw label objects /// - void Model::draw( QPainter* painter, bool inEditor, merge::Record* record ) const + void Model::draw( QPainter* painter, bool inEditor, merge::Record* record, Variables* variables ) const { foreach ( ModelObject* object, mObjectList ) { - object->draw( painter, inEditor, record ); + object->draw( painter, inEditor, record, variables ); } } diff --git a/model/Model.h b/model/Model.h index 13b9f4c..cfd74c8 100644 --- a/model/Model.h +++ b/model/Model.h @@ -208,7 +208,10 @@ namespace glabels // Drawing operations ///////////////////////////////// public: - void draw( QPainter* painter, bool inEditor = true, merge::Record* record = nullptr ) const; + void draw( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const; ///////////////////////////////// diff --git a/model/ModelBarcodeObject.cpp b/model/ModelBarcodeObject.cpp index 315632e..3b65e10 100644 --- a/model/ModelBarcodeObject.cpp +++ b/model/ModelBarcodeObject.cpp @@ -311,7 +311,8 @@ namespace glabels /// void ModelBarcodeObject::drawShadow( QPainter* painter, bool inEditor, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { // Barcodes don't support shadows. } @@ -322,7 +323,8 @@ namespace glabels /// void ModelBarcodeObject::drawObject( QPainter* painter, bool inEditor, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { QColor bcColor = mBcColorNode.color( record ); @@ -332,7 +334,7 @@ namespace glabels } else { - drawBc( painter, bcColor, record ); + drawBc( painter, bcColor, record, variables ); } } @@ -450,7 +452,8 @@ namespace glabels void ModelBarcodeObject::drawBc( QPainter* painter, const QColor& color, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { painter->setPen( QPen( color ) ); @@ -458,7 +461,7 @@ namespace glabels bc->setChecksum(mBcChecksumFlag); bc->setShowText(mBcTextFlag); - bc->build( mBcData.expand( record ).toStdString(), mW.pt(), mH.pt() ); + bc->build( mBcData.expand( record, variables ).toStdString(), mW.pt(), mH.pt() ); glbarcode::QtRenderer renderer(painter); bc->render( renderer ); diff --git a/model/ModelBarcodeObject.h b/model/ModelBarcodeObject.h index 4931ddf..bd32091 100644 --- a/model/ModelBarcodeObject.h +++ b/model/ModelBarcodeObject.h @@ -126,8 +126,16 @@ namespace glabels // Drawing operations /////////////////////////////////////////////////////////////// protected: - void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override; - void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override; + void drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + + void drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + QPainterPath hoverPath( double scale ) const override; @@ -139,7 +147,12 @@ namespace glabels void update(); void drawBcInEditor( QPainter* painter, const QColor& color ) const; - void drawBc( QPainter* painter, const QColor& color, merge::Record* record ) const; + + void drawBc( QPainter* painter, + const QColor& color, + merge::Record* record, + Variables* variables ) const; + void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const; diff --git a/model/ModelBoxObject.cpp b/model/ModelBoxObject.cpp index 94e81d5..24a61c6 100644 --- a/model/ModelBoxObject.cpp +++ b/model/ModelBoxObject.cpp @@ -103,7 +103,10 @@ namespace glabels /// /// Draw shadow of object /// - void ModelBoxObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const + void ModelBoxObject::drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const { QColor lineColor = mLineColorNode.color( record ); QColor fillColor = mFillColorNode.color( record ); @@ -148,7 +151,10 @@ namespace glabels /// /// Draw object itself /// - void ModelBoxObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const + void ModelBoxObject::drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const { QColor lineColor = mLineColorNode.color( record ); QColor fillColor = mFillColorNode.color( record ); diff --git a/model/ModelBoxObject.h b/model/ModelBoxObject.h index 8705c99..3c784c6 100644 --- a/model/ModelBoxObject.h +++ b/model/ModelBoxObject.h @@ -72,8 +72,16 @@ namespace glabels // Drawing operations /////////////////////////////////////////////////////////////// protected: - void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override; - void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override; + void drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + + void drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + QPainterPath hoverPath( double scale ) const override; }; diff --git a/model/ModelEllipseObject.cpp b/model/ModelEllipseObject.cpp index c3ca82e..e9e58fd 100644 --- a/model/ModelEllipseObject.cpp +++ b/model/ModelEllipseObject.cpp @@ -103,7 +103,10 @@ namespace glabels /// /// Draw shadow of object /// - void ModelEllipseObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const + void ModelEllipseObject::drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const { QColor lineColor = mLineColorNode.color( record ); QColor fillColor = mFillColorNode.color( record ); @@ -148,7 +151,10 @@ namespace glabels /// /// Draw object itself /// - void ModelEllipseObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const + void ModelEllipseObject::drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const { QColor lineColor = mLineColorNode.color( record ); QColor fillColor = mFillColorNode.color( record ); diff --git a/model/ModelEllipseObject.h b/model/ModelEllipseObject.h index e26e9ba..cd22cc9 100644 --- a/model/ModelEllipseObject.h +++ b/model/ModelEllipseObject.h @@ -72,8 +72,16 @@ namespace glabels // Drawing operations /////////////////////////////////////////////////////////////// protected: - void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override; - void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override; + void drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + + void drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + QPainterPath hoverPath( double scale ) const override; }; diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp index 5848625..bc9eb18 100644 --- a/model/ModelImageObject.cpp +++ b/model/ModelImageObject.cpp @@ -395,7 +395,10 @@ namespace glabels /// /// Draw shadow of object /// - void ModelImageObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const + void ModelImageObject::drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const { QRectF destRect( 0, 0, mW.pt(), mH.pt() ); @@ -424,7 +427,10 @@ namespace glabels /// /// Draw object itself /// - void ModelImageObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const + void ModelImageObject::drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const { QRectF destRect( 0, 0, mW.pt(), mH.pt() ); diff --git a/model/ModelImageObject.h b/model/ModelImageObject.h index ba87078..d1c62a0 100644 --- a/model/ModelImageObject.h +++ b/model/ModelImageObject.h @@ -132,8 +132,16 @@ namespace glabels // Drawing operations /////////////////////////////////////////////////////////////// protected: - void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override; - void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override; + void drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + + void drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + QPainterPath hoverPath( double scale ) const override; diff --git a/model/ModelLineObject.cpp b/model/ModelLineObject.cpp index 5d7b5e1..9223f91 100644 --- a/model/ModelLineObject.cpp +++ b/model/ModelLineObject.cpp @@ -186,7 +186,10 @@ namespace glabels /// /// Draw shadow of object /// - void ModelLineObject::drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const + void ModelLineObject::drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const { QColor lineColor = mLineColorNode.color( record ); QColor shadowColor = mShadowColorNode.color( record ); @@ -204,7 +207,10 @@ namespace glabels /// /// Draw object itself /// - void ModelLineObject::drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const + void ModelLineObject::drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const { QColor lineColor = mLineColorNode.color( record ); diff --git a/model/ModelLineObject.h b/model/ModelLineObject.h index 16cfdb6..a09670e 100644 --- a/model/ModelLineObject.h +++ b/model/ModelLineObject.h @@ -97,8 +97,16 @@ namespace glabels // Drawing operations /////////////////////////////////////////////////////////////// protected: - void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override; - void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override; + void drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + + void drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + QPainterPath hoverPath( double scale ) const override; diff --git a/model/ModelObject.cpp b/model/ModelObject.cpp index 637352c..c79c9f2 100644 --- a/model/ModelObject.cpp +++ b/model/ModelObject.cpp @@ -1200,7 +1200,10 @@ namespace glabels /// /// Draw object + shadow /// - void ModelObject::draw( QPainter* painter, bool inEditor, merge::Record* record ) const + void ModelObject::draw( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const { painter->save(); painter->translate( mX0.pt(), mY0.pt() ); @@ -1210,12 +1213,12 @@ namespace glabels painter->save(); painter->translate( mShadowX.pt(), mShadowY.pt() ); painter->setMatrix( mMatrix, true ); - drawShadow( painter, inEditor, record ); + drawShadow( painter, inEditor, record, variables ); painter->restore(); } painter->setMatrix( mMatrix, true ); - drawObject( painter, inEditor, record ); + drawObject( painter, inEditor, record, variables ); painter->restore(); } diff --git a/model/ModelObject.h b/model/ModelObject.h index 6af51e8..e7a6c2f 100644 --- a/model/ModelObject.h +++ b/model/ModelObject.h @@ -27,6 +27,7 @@ #include "Handles.h" #include "Outline.h" #include "TextNode.h" +#include "Variables.h" #include "barcode/Style.h" #include "merge/Record.h" @@ -403,12 +404,24 @@ namespace glabels // Drawing operations /////////////////////////////////////////////////////////////// public: - void draw( QPainter* painter, bool inEditor, merge::Record* record ) const; + void draw( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const; + void drawSelectionHighlight( QPainter* painter, double scale ) const; protected: - virtual void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const = 0; - virtual void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const = 0; + virtual void drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const = 0; + + virtual void drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const = 0; + virtual QPainterPath hoverPath( double scale ) const = 0; virtual void sizeUpdated(); diff --git a/model/ModelTextObject.cpp b/model/ModelTextObject.cpp index 434d48b..45c259e 100644 --- a/model/ModelTextObject.cpp +++ b/model/ModelTextObject.cpp @@ -518,7 +518,8 @@ namespace glabels /// void ModelTextObject::drawShadow( QPainter* painter, bool inEditor, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { QColor textColor = mTextColorNode.color( record ); @@ -533,7 +534,7 @@ namespace glabels } else { - drawText( painter, shadowColor, record ); + drawText( painter, shadowColor, record, variables ); } } } @@ -544,7 +545,8 @@ namespace glabels /// void ModelTextObject::drawObject( QPainter* painter, bool inEditor, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { QColor textColor = mTextColorNode.color( record ); @@ -554,7 +556,7 @@ namespace glabels } else { - drawText( painter, textColor, record ); + drawText( painter, textColor, record, variables ); } } @@ -696,7 +698,8 @@ namespace glabels void ModelTextObject::drawText( QPainter* painter, const QColor& color, - merge::Record* record ) const + merge::Record* record, + Variables* variables ) const { painter->save(); @@ -704,7 +707,7 @@ namespace glabels QFont font; font.setFamily( mFontFamily ); - font.setPointSizeF( mTextAutoShrink ? autoShrinkFontSize( record ) : mFontSize ); + font.setPointSizeF( mTextAutoShrink ? autoShrinkFontSize( record, variables ) : mFontSize ); font.setWeight( mFontWeight ); font.setItalic( mFontItalicFlag ); font.setUnderline( mFontUnderlineFlag ); @@ -716,7 +719,7 @@ namespace glabels QFontMetricsF fontMetrics( font ); double dy = fontMetrics.lineSpacing() * mTextLineSpacing; - QTextDocument document( mText.expand( record ) ); + QTextDocument document( mText.expand( record, variables ) ); QList layouts; @@ -790,7 +793,7 @@ namespace glabels /// Determine auto shrink font size /// double - ModelTextObject::autoShrinkFontSize( merge::Record* record ) const + ModelTextObject::autoShrinkFontSize( merge::Record* record, Variables* variables ) const { QFont font; font.setFamily( mFontFamily ); @@ -802,7 +805,7 @@ namespace glabels textOption.setAlignment( mTextHAlign ); textOption.setWrapMode( mTextWrapMode ); - QTextDocument document( mText.expand( record ) ); + QTextDocument document( mText.expand( record, variables ) ); double candidateSize = mFontSize; while ( candidateSize > 1.0 ) diff --git a/model/ModelTextObject.h b/model/ModelTextObject.h index 1ab62c6..d15a624 100644 --- a/model/ModelTextObject.h +++ b/model/ModelTextObject.h @@ -185,8 +185,16 @@ namespace glabels // Drawing operations /////////////////////////////////////////////////////////////// protected: - void drawShadow( QPainter* painter, bool inEditor, merge::Record* record ) const override; - void drawObject( QPainter* painter, bool inEditor, merge::Record* record ) const override; + void drawShadow( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + + void drawObject( QPainter* painter, + bool inEditor, + merge::Record* record, + Variables* variables ) const override; + QPainterPath hoverPath( double scale ) const override; @@ -196,10 +204,17 @@ namespace glabels private: void sizeUpdated() override; void update(); - void drawTextInEditor( QPainter* painter, const QColor& color ) const; - void drawText( QPainter* painter, const QColor&color, merge::Record* record ) const; - QString expandText( QString text, merge::Record* record ) const; - double autoShrinkFontSize( merge::Record* record ) const; + + void drawTextInEditor( QPainter* painter, + const QColor& color ) const; + + void drawText( QPainter* painter, + const QColor& color, + merge::Record* record, + Variables* variables ) const; + + double autoShrinkFontSize( merge::Record* record, + Variables* variables ) const; /////////////////////////////////////////////////////////////// diff --git a/model/PageRenderer.cpp b/model/PageRenderer.cpp index 9c2b702..f1ada0f 100644 --- a/model/PageRenderer.cpp +++ b/model/PageRenderer.cpp @@ -47,7 +47,7 @@ namespace glabels PageRenderer::PageRenderer( const Model* model ) - : mModel(nullptr), mMerge(nullptr), mNCopies(0), mStartLabel(0), mLastLabel(0), + : mModel(nullptr), mMerge(nullptr), mVariables(nullptr), mNCopies(0), mStartLabel(0), mLastLabel(0), mPrintOutlines(false), mPrintCropMarks(false), mPrintReverse(false), mIPage(0), mIsMerge(false), mNPages(0), mNLabelsPerPage(0) { @@ -65,6 +65,7 @@ namespace glabels connect( mModel, SIGNAL(changed()), this, SLOT(onModelChanged()) ); onModelChanged(); + mVariables = mModel->variables(); } @@ -249,37 +250,44 @@ namespace glabels void PageRenderer::printSimplePage( QPainter* painter, int iPage ) const { - int iStart = 0; - int iEnd = mNLabelsPerPage; - - if ( iPage == 0 ) - { - iStart = mStartLabel; - } - - if ( (mLastLabel / mNLabelsPerPage) == iPage ) - { - iEnd = mLastLabel % mNLabelsPerPage; - } - printCropMarks( painter ); - for ( int i = iStart; i < iEnd; i++ ) + int iCopy = 0; + int iLabel = mStartLabel; + int iCurrentPage = 0; + mVariables->resetVariables(); + + while ( (iCopy < mNCopies) && (iCurrentPage <= iPage) ) { - painter->save(); + if ( iCurrentPage == iPage ) + { + int i = iLabel % mNLabelsPerPage; + + painter->save(); - painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() ); + painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() ); - painter->save(); + painter->save(); - clipLabel( painter ); - printLabel( painter, nullptr ); + clipLabel( painter ); + printLabel( painter, nullptr, mVariables ); - painter->restore(); // From before clip + painter->restore(); // From before clip - printOutline( painter ); + printOutline( painter ); - painter->restore(); // From before translation + painter->restore(); // From before translation + } + + iCopy++; + iLabel++; + iCurrentPage = iLabel / mNLabelsPerPage; + + mVariables->incrementVariablesOnCopy(); + if ( (iLabel % mNLabelsPerPage) == 0 /* starting a new page */ ) + { + mVariables->incrementVariablesOnPage(); + } } } @@ -317,7 +325,7 @@ namespace glabels painter->save(); clipLabel( painter ); - printLabel( painter, records[iRecord] ); + printLabel( painter, records[iRecord], mVariables ); painter->restore(); // From before clip @@ -411,7 +419,9 @@ namespace glabels } - void PageRenderer::printLabel( QPainter* painter, merge::Record* record ) const + void PageRenderer::printLabel( QPainter* painter, + merge::Record* record, + Variables* variables ) const { painter->save(); @@ -427,7 +437,7 @@ namespace glabels painter->scale( -1, 1 ); } - mModel->draw( painter, false, record ); + mModel->draw( painter, false, record, variables ); painter->restore(); } diff --git a/model/PageRenderer.h b/model/PageRenderer.h index 2db3ae4..08c93a9 100644 --- a/model/PageRenderer.h +++ b/model/PageRenderer.h @@ -23,6 +23,7 @@ #include "Point.h" +#include "Variables.h" #include "merge/Merge.h" #include "merge/Record.h" @@ -100,7 +101,7 @@ namespace glabels void printCropMarks( QPainter* painter ) const; void printOutline( QPainter* painter ) const; void clipLabel( QPainter* painter ) const; - void printLabel( QPainter* painter, merge::Record* record ) const; + void printLabel( QPainter* painter, merge::Record* record, Variables* variables ) const; ///////////////////////////////// @@ -109,6 +110,7 @@ namespace glabels private: const Model* mModel; const merge::Merge* mMerge; + Variables* mVariables; int mNCopies; int mStartLabel; diff --git a/model/RawText.cpp b/model/RawText.cpp index 08ee6bf..ed4cd29 100644 --- a/model/RawText.cpp +++ b/model/RawText.cpp @@ -66,7 +66,7 @@ namespace glabels /// /// Expand all place holders /// - QString RawText::expand( merge::Record* record ) const + QString RawText::expand( merge::Record* record, Variables* variables ) const { QString text; @@ -74,7 +74,7 @@ namespace glabels { if ( token.isField ) { - text += token.field.evaluate( record ); + text += token.field.evaluate( record, variables ); } else { diff --git a/model/RawText.h b/model/RawText.h index 9b19084..2e8ab44 100644 --- a/model/RawText.h +++ b/model/RawText.h @@ -52,7 +52,7 @@ namespace glabels ///////////////////////////////// QString toString() const; std::string toStdString() const; - QString expand( merge::Record* record ) const; + QString expand( merge::Record* record, Variables* variables ) const; bool hasPlaceHolders() const; bool isEmpty() const; diff --git a/model/SubstitutionField.cpp b/model/SubstitutionField.cpp index 178b73e..76c4047 100644 --- a/model/SubstitutionField.cpp +++ b/model/SubstitutionField.cpp @@ -42,21 +42,33 @@ namespace glabels } - QString SubstitutionField::evaluate( const merge::Record* record ) const + QString SubstitutionField::evaluate( const merge::Record* record, + const Variables* variables ) const { QString value = mDefaultValue; - if ( record && record->contains(mFieldName) && !record->value(mFieldName).isEmpty() ) + bool haveRecordField = record && + record->contains(mFieldName) && + !record->value(mFieldName).isEmpty(); + bool haveVariable = variables && + variables->contains(mFieldName) && + !(*variables)[mFieldName].value().isEmpty(); + + if ( haveRecordField ) { value = record->value(mFieldName); } + else if ( haveVariable ) + { + value = (*variables)[mFieldName].value(); + } if ( !mFormatType.isNull() ) { value = formatValue( value ); } - if ( record && record->contains(mFieldName) && !record->value(mFieldName).isEmpty() && mNewLine ) + if ( mNewLine && (haveRecordField || haveVariable) ) { value = "\n" + value; } diff --git a/model/SubstitutionField.h b/model/SubstitutionField.h index ec08a00..baaa255 100644 --- a/model/SubstitutionField.h +++ b/model/SubstitutionField.h @@ -21,6 +21,7 @@ #ifndef model_SubstitutionField_h #define model_SubstitutionField_h +#include "Variables.h" #include "merge/Record.h" @@ -39,7 +40,7 @@ namespace glabels SubstitutionField(); SubstitutionField( const QString& string ); - QString evaluate( const merge::Record* record ) const; + QString evaluate( const merge::Record* record, const Variables* variables ) const; QString fieldName() const; QString defaultValue() const; diff --git a/model/Variable.cpp b/model/Variable.cpp index b424a6b..8b81a86 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -28,12 +28,12 @@ namespace glabels Variable::Variable( Variable::Type type, const QString& name, - const QString& value, + const QString& initialValue, Variable::Increment increment, const QString& stepSize ) : mType(type), mName(name), - mValue(value), + mInitialValue(initialValue), mIncrement(increment), mStepSize(stepSize) { @@ -53,9 +53,9 @@ namespace glabels } - QString Variable::value() const + QString Variable::initialValue() const { - return mValue; + return mInitialValue; } @@ -70,15 +70,110 @@ namespace glabels return mStepSize; } + + void Variable::resetValue() + { + switch (mType) + { + case Type::STRING: + // do nothing + break; + case Type::INTEGER: + mIntegerValue = mInitialValue.toLongLong(); + mIntegerStep = mStepSize.toLongLong(); + break; + case Type::FLOATING_POINT: + mFloatingPointValue = mInitialValue.toDouble(); + mFloatingPointStep = mStepSize.toDouble(); + break; + } + } + + void Variable::incrementValueOnCopy() + { + if ( mIncrement == Increment::PER_COPY ) + { + switch (mType) + { + case Type::STRING: + // do nothing + break; + case Type::INTEGER: + mIntegerValue += mIntegerStep; + break; + case Type::FLOATING_POINT: + mFloatingPointValue += mFloatingPointStep; + break; + } + } + } + + + void Variable::incrementValueOnMerge() + { + if ( mIncrement == Increment::PER_MERGE_RECORD ) + { + switch (mType) + { + case Type::STRING: + // do nothing + break; + case Type::INTEGER: + mIntegerValue += mIntegerStep; + break; + case Type::FLOATING_POINT: + mFloatingPointValue += mFloatingPointStep; + break; + } + } + } + + + void Variable::incrementValueOnPage() + { + if ( mIncrement == Increment::PER_PAGE ) + { + switch (mType) + { + case Type::STRING: + // do nothing + break; + case Type::INTEGER: + mIntegerValue += mIntegerStep; + break; + case Type::FLOATING_POINT: + mFloatingPointValue += mFloatingPointStep; + break; + } + } + } + + + QString Variable::value() const + { + switch (mType) + { + case Type::STRING: + return mInitialValue; + case Type::INTEGER: + return QString::number( mIntegerValue ); + case Type::FLOATING_POINT: + return QString::number( mFloatingPointValue, 'g', 15 ); + } + } + + QString Variable::typeToI18nString( Type type ) { switch (type) { - case Type::NUMERIC: - return tr("Numeric"); case Type::STRING: return tr("String"); + case Type::INTEGER: + return tr("Integer"); + case Type::FLOATING_POINT: + return tr("Floating Point"); } } @@ -87,24 +182,30 @@ namespace glabels { switch (type) { - case Type::NUMERIC: - return "numeric"; case Type::STRING: return "string"; + case Type::INTEGER: + return "integer"; + case Type::FLOATING_POINT: + return "float"; } } - Variable::Type Variable::idStringToType( const QString& string ) + Variable::Type Variable::idStringToType( const QString& id ) { - if ( string == "numeric" ) - { - return Type::NUMERIC; - } - else if ( string == "string" ) + if ( id == "string" ) { return Type::STRING; } + else if ( id == "integer" ) + { + return Type::INTEGER; + } + else if ( id == "float" ) + { + return Type::FLOATING_POINT; + } else { return Type::STRING; // Default @@ -144,21 +245,21 @@ namespace glabels } - Variable::Increment Variable::idStringToIncrement( const QString& string ) + Variable::Increment Variable::idStringToIncrement( const QString& id ) { - if ( string == "never" ) + if ( id == "never" ) { return Increment::NEVER; } - else if ( string == "per_copy" ) + else if ( id == "per_copy" ) { return Increment::PER_COPY; } - else if ( string == "per_merge_record" ) + else if ( id == "per_merge_record" ) { return Increment::PER_MERGE_RECORD; } - else if ( string == "per_page" ) + else if ( id == "per_page" ) { return Increment::PER_PAGE; } diff --git a/model/Variable.h b/model/Variable.h index 0a90733..3feb694 100644 --- a/model/Variable.h +++ b/model/Variable.h @@ -38,8 +38,9 @@ namespace glabels public: enum class Type { - NUMERIC, - STRING + STRING, + INTEGER, + FLOATING_POINT }; enum class Increment @@ -56,7 +57,7 @@ namespace glabels Variable( Type type, const QString& name, - const QString& value, + const QString& initialValue, Increment increment = Increment::NEVER, const QString& stepSize = "0" ); @@ -65,10 +66,15 @@ namespace glabels Type type() const; QString name() const; - QString value() const; + QString initialValue() const; Increment increment() const; QString stepSize() const; + void resetValue(); + void incrementValueOnCopy(); + void incrementValueOnMerge(); + void incrementValueOnPage(); + QString value() const; static QString typeToI18nString( Type type ); static QString typeToIdString( Type type ); @@ -82,10 +88,15 @@ namespace glabels private: Type mType; QString mName; - QString mValue; + QString mInitialValue; Increment mIncrement; QString mStepSize; + long long mIntegerValue; + long long mIntegerStep; + double mFloatingPointValue; + double mFloatingPointStep; + }; } diff --git a/model/Variables.cpp b/model/Variables.cpp index 24d414f..9bf149f 100644 --- a/model/Variables.cpp +++ b/model/Variables.cpp @@ -85,6 +85,54 @@ namespace glabels } + /// + /// Reset variables to their initial values + /// + void Variables::resetVariables() + { + for ( auto& v : *this ) + { + v.resetValue(); + } + } + + + /// + /// Increment variables on copy + /// + void Variables::incrementVariablesOnCopy() + { + for ( auto& v : *this ) + { + v.incrementValueOnCopy(); + } + } + + + /// + /// Increment variables on merge record + /// + void Variables::incrementVariablesOnMerge() + { + for ( auto& v : *this ) + { + v.incrementValueOnMerge(); + } + } + + + /// + /// Increment variables on page + /// + void Variables::incrementVariablesOnPage() + { + for ( auto& v : *this ) + { + v.incrementValueOnPage(); + } + } + + } // namespace model } // namespace glabels diff --git a/model/Variables.h b/model/Variables.h index 0c1a020..ec7b578 100644 --- a/model/Variables.h +++ b/model/Variables.h @@ -63,6 +63,11 @@ namespace glabels void deleteVariable( const QString& name ); void replaceVariable( const QString& name, const Variable& variable ); + void resetVariables(); + void incrementVariablesOnCopy(); + void incrementVariablesOnMerge(); + void incrementVariablesOnPage(); + ///////////////////////////////// // Signals diff --git a/model/XmlLabelCreator.cpp b/model/XmlLabelCreator.cpp index 2a31cf0..a546d14 100644 --- a/model/XmlLabelCreator.cpp +++ b/model/XmlLabelCreator.cpp @@ -495,7 +495,7 @@ namespace glabels XmlUtil::setStringAttr( node, "type", Variable::typeToIdString( v.type() ) ); XmlUtil::setStringAttr( node, "name", v.name() ); - XmlUtil::setStringAttr( node, "value", v.value() ); + XmlUtil::setStringAttr( node, "initialValue", v.initialValue() ); XmlUtil::setStringAttr( node, "increment", Variable::incrementToIdString( v.increment() ) ); XmlUtil::setStringAttr( node, "stepSize", v.stepSize() ); } diff --git a/model/XmlLabelParser.cpp b/model/XmlLabelParser.cpp index 9412dd7..07fd543 100644 --- a/model/XmlLabelParser.cpp +++ b/model/XmlLabelParser.cpp @@ -747,14 +747,14 @@ namespace glabels { QString typeString = XmlUtil::getStringAttr( node, "type", "string" ); QString name = XmlUtil::getStringAttr( node, "name", "unknown" ); - QString value = XmlUtil::getStringAttr( node, "value", "0" ); + QString initialValue = XmlUtil::getStringAttr( node, "initialValue", "0" ); QString incrementString = XmlUtil::getStringAttr( node, "increment", "never" ); QString stepSize = XmlUtil::getStringAttr( node, "stepSize", "0" ); auto type = Variable::idStringToType( typeString ); auto increment = Variable::idStringToIncrement( incrementString ); - Variable v( type, name, value, increment, stepSize ); + Variable v( type, name, initialValue, increment, stepSize ); label->variables()->addVariable( v ); } diff --git a/model/unit_tests/TestSubstitutionField.cpp b/model/unit_tests/TestSubstitutionField.cpp index fa9135a..04476b6 100644 --- a/model/unit_tests/TestSubstitutionField.cpp +++ b/model/unit_tests/TestSubstitutionField.cpp @@ -139,6 +139,8 @@ void TestSubstitutionField::simpleEvaluation() { using namespace glabels; + model::Variables variables; + model::SubstitutionField f1( "${1}" ); model::SubstitutionField f2( "${2}" ); model::SubstitutionField f3( "${3}" ); @@ -150,10 +152,10 @@ void TestSubstitutionField::simpleEvaluation() record1[ "3" ] = "Opqrstu"; record1[ "4" ] = "Vwxyz!@"; - QCOMPARE( f1.evaluate( &record1 ), QString( "Abcdefg" ) ); - QCOMPARE( f2.evaluate( &record1 ), QString( "Hijklmn" ) ); - QCOMPARE( f3.evaluate( &record1 ), QString( "Opqrstu" ) ); - QCOMPARE( f4.evaluate( &record1 ), QString( "Vwxyz!@" ) ); + QCOMPARE( f1.evaluate( &record1, &variables ), QString( "Abcdefg" ) ); + QCOMPARE( f2.evaluate( &record1, &variables ), QString( "Hijklmn" ) ); + QCOMPARE( f3.evaluate( &record1, &variables ), QString( "Opqrstu" ) ); + QCOMPARE( f4.evaluate( &record1, &variables ), QString( "Vwxyz!@" ) ); merge::Record record2; record2[ "1" ] = "1234567"; @@ -161,10 +163,10 @@ void TestSubstitutionField::simpleEvaluation() record2[ "3" ] = "8901234"; record2[ "4" ] = "#$%^&*"; - QCOMPARE( f1.evaluate( &record2 ), QString( "1234567" ) ); - QCOMPARE( f2.evaluate( &record2 ), QString( "FooBar" ) ); - QCOMPARE( f3.evaluate( &record2 ), QString( "8901234" ) ); - QCOMPARE( f4.evaluate( &record2 ), QString( "#$%^&*" ) ); + QCOMPARE( f1.evaluate( &record2, &variables ), QString( "1234567" ) ); + QCOMPARE( f2.evaluate( &record2, &variables ), QString( "FooBar" ) ); + QCOMPARE( f3.evaluate( &record2, &variables ), QString( "8901234" ) ); + QCOMPARE( f4.evaluate( &record2, &variables ), QString( "#$%^&*" ) ); } @@ -172,6 +174,8 @@ void TestSubstitutionField::defaultValueEvaluation() { using namespace glabels; + model::Variables variables; + model::SubstitutionField f1( "${1:=foo1}" ); model::SubstitutionField f2( "${2:=foo2}" ); model::SubstitutionField f3( "${3:=foo3}" ); @@ -183,17 +187,17 @@ void TestSubstitutionField::defaultValueEvaluation() record1[ "3" ] = "Opqrstu"; record1[ "4" ] = "Vwxyz!@"; - QCOMPARE( f1.evaluate( &record1 ), QString( "Abcdefg" ) ); - QCOMPARE( f2.evaluate( &record1 ), QString( "Hijklmn" ) ); - QCOMPARE( f3.evaluate( &record1 ), QString( "Opqrstu" ) ); - QCOMPARE( f4.evaluate( &record1 ), QString( "Vwxyz!@" ) ); + QCOMPARE( f1.evaluate( &record1, &variables ), QString( "Abcdefg" ) ); + QCOMPARE( f2.evaluate( &record1, &variables ), QString( "Hijklmn" ) ); + QCOMPARE( f3.evaluate( &record1, &variables ), QString( "Opqrstu" ) ); + QCOMPARE( f4.evaluate( &record1, &variables ), QString( "Vwxyz!@" ) ); merge::Record record2; // All fields empty - QCOMPARE( f1.evaluate( &record2 ), QString( "foo1" ) ); - QCOMPARE( f2.evaluate( &record2 ), QString( "foo2" ) ); - QCOMPARE( f3.evaluate( &record2 ), QString( "foo3" ) ); - QCOMPARE( f4.evaluate( &record2 ), QString( "foo4" ) ); + QCOMPARE( f1.evaluate( &record2, &variables ), QString( "foo1" ) ); + QCOMPARE( f2.evaluate( &record2, &variables ), QString( "foo2" ) ); + QCOMPARE( f3.evaluate( &record2, &variables ), QString( "foo3" ) ); + QCOMPARE( f4.evaluate( &record2, &variables ), QString( "foo4" ) ); merge::Record record3; record3[ "1" ] = "xyzzy"; @@ -201,10 +205,10 @@ void TestSubstitutionField::defaultValueEvaluation() // Field "3" empty record3[ "4" ] = "plugh"; - QCOMPARE( f1.evaluate( &record3 ), QString( "xyzzy" ) ); - QCOMPARE( f2.evaluate( &record3 ), QString( "foo2" ) ); - QCOMPARE( f3.evaluate( &record3 ), QString( "foo3" ) ); - QCOMPARE( f4.evaluate( &record3 ), QString( "plugh" ) ); + QCOMPARE( f1.evaluate( &record3, &variables ), QString( "xyzzy" ) ); + QCOMPARE( f2.evaluate( &record3, &variables ), QString( "foo2" ) ); + QCOMPARE( f3.evaluate( &record3, &variables ), QString( "foo3" ) ); + QCOMPARE( f4.evaluate( &record3, &variables ), QString( "plugh" ) ); } @@ -212,6 +216,8 @@ void TestSubstitutionField::formattedStringEvaluation() { using namespace glabels; + model::Variables variables; + model::SubstitutionField f1( "${1:%10s}" ); model::SubstitutionField f2( "${2:%10s}" ); model::SubstitutionField f3( "${3:%10s}" ); @@ -233,15 +239,15 @@ void TestSubstitutionField::formattedStringEvaluation() record1[ "7" ] = "-100"; record1[ "8" ] = "3.14"; - QCOMPARE( f1.evaluate( &record1 ), QString( " 0" ) ); - QCOMPARE( f2.evaluate( &record1 ), QString( " 1" ) ); - QCOMPARE( f3.evaluate( &record1 ), QString( " -1" ) ); - QCOMPARE( f4.evaluate( &record1 ), QString( " 3.14" ) ); + QCOMPARE( f1.evaluate( &record1, &variables ), QString( " 0" ) ); + QCOMPARE( f2.evaluate( &record1, &variables ), QString( " 1" ) ); + QCOMPARE( f3.evaluate( &record1, &variables ), QString( " -1" ) ); + QCOMPARE( f4.evaluate( &record1, &variables ), QString( " 3.14" ) ); - QCOMPARE( f5.evaluate( &record1 ), QString( "0 " ) ); - QCOMPARE( f6.evaluate( &record1 ), QString( "100 " ) ); - QCOMPARE( f7.evaluate( &record1 ), QString( "-100 " ) ); - QCOMPARE( f8.evaluate( &record1 ), QString( "3.14 " ) ); + QCOMPARE( f5.evaluate( &record1, &variables ), QString( "0 " ) ); + QCOMPARE( f6.evaluate( &record1, &variables ), QString( "100 " ) ); + QCOMPARE( f7.evaluate( &record1, &variables ), QString( "-100 " ) ); + QCOMPARE( f8.evaluate( &record1, &variables ), QString( "3.14 " ) ); } @@ -249,6 +255,8 @@ void TestSubstitutionField::formattedFloatEvaluation() { using namespace glabels; + model::Variables variables; + model::SubstitutionField f1( "${1:%+5.2f}" ); model::SubstitutionField f2( "${2:%+5.2f}" ); model::SubstitutionField f3( "${3:%+5.2f}" ); @@ -270,15 +278,15 @@ void TestSubstitutionField::formattedFloatEvaluation() record1[ "7" ] = "-100"; record1[ "8" ] = "3.14"; - QCOMPARE( f1.evaluate( &record1 ), QString( "+0.00" ) ); - QCOMPARE( f2.evaluate( &record1 ), QString( "+1.00" ) ); - QCOMPARE( f3.evaluate( &record1 ), QString( "-1.00" ) ); - QCOMPARE( f4.evaluate( &record1 ), QString( "+3.14" ) ); + QCOMPARE( f1.evaluate( &record1, &variables ), QString( "+0.00" ) ); + QCOMPARE( f2.evaluate( &record1, &variables ), QString( "+1.00" ) ); + QCOMPARE( f3.evaluate( &record1, &variables ), QString( "-1.00" ) ); + QCOMPARE( f4.evaluate( &record1, &variables ), QString( "+3.14" ) ); - QCOMPARE( f5.evaluate( &record1 ), QString( "+0.00e+00" ) ); - QCOMPARE( f6.evaluate( &record1 ), QString( "+1.00e+02" ) ); - QCOMPARE( f7.evaluate( &record1 ), QString( "-1.00e+02" ) ); - QCOMPARE( f8.evaluate( &record1 ), QString( "+3.14e+00" ) ); + QCOMPARE( f5.evaluate( &record1, &variables ), QString( "+0.00e+00" ) ); + QCOMPARE( f6.evaluate( &record1, &variables ), QString( "+1.00e+02" ) ); + QCOMPARE( f7.evaluate( &record1, &variables ), QString( "-1.00e+02" ) ); + QCOMPARE( f8.evaluate( &record1, &variables ), QString( "+3.14e+00" ) ); } @@ -286,6 +294,8 @@ void TestSubstitutionField::formattedIntEvaluation() { using namespace glabels; + model::Variables variables; + model::SubstitutionField f1( "${1:%08d}" ); model::SubstitutionField f2( "${2:%08d}" ); model::SubstitutionField f3( "${3:%08d}" ); @@ -307,15 +317,15 @@ void TestSubstitutionField::formattedIntEvaluation() record1[ "7" ] = "-1"; record1[ "8" ] = "314"; - QCOMPARE( f1.evaluate( &record1 ), QString( "00000000" ) ); - QCOMPARE( f2.evaluate( &record1 ), QString( "00000001" ) ); - QCOMPARE( f3.evaluate( &record1 ), QString( "-0000001" ) ); - QCOMPARE( f4.evaluate( &record1 ), QString( "00000000" ) ); // Invalid integer value + QCOMPARE( f1.evaluate( &record1, &variables ), QString( "00000000" ) ); + QCOMPARE( f2.evaluate( &record1, &variables ), QString( "00000001" ) ); + QCOMPARE( f3.evaluate( &record1, &variables ), QString( "-0000001" ) ); + QCOMPARE( f4.evaluate( &record1, &variables ), QString( "00000000" ) ); // Invalid integer value - QCOMPARE( f5.evaluate( &record1 ), QString( "00000064" ) ); // 100(decimal) == 64(hex) - QCOMPARE( f6.evaluate( &record1 ), QString( "00000100" ) ); - QCOMPARE( f7.evaluate( &record1 ), QString( "00000000" ) ); // Invalid unsigned integer - QCOMPARE( f8.evaluate( &record1 ), QString( "0000013a" ) ); // 314(decimal) == 13a(hex) + QCOMPARE( f5.evaluate( &record1, &variables ), QString( "00000064" ) ); // 100(decimal) == 64(hex) + QCOMPARE( f6.evaluate( &record1, &variables ), QString( "00000100" ) ); + QCOMPARE( f7.evaluate( &record1, &variables ), QString( "00000000" ) ); // Invalid unsigned integer + QCOMPARE( f8.evaluate( &record1, &variables ), QString( "0000013a" ) ); // 314(decimal) == 13a(hex) } @@ -323,6 +333,8 @@ void TestSubstitutionField::newLineEvaluation() { using namespace glabels; + model::Variables variables; + model::SubstitutionField addr2( "${ADDR2:n}" ); QCOMPARE( addr2.fieldName(), QString( "ADDR2" ) ); QCOMPARE( addr2.newLine(), true ); @@ -336,7 +348,7 @@ void TestSubstitutionField::newLineEvaluation() merge::Record record3; // ADDR2 not defined - QCOMPARE( addr2.evaluate( &record1 ), QString( "\nApt. 5B" ) ); // Prepends a newline - QCOMPARE( addr2.evaluate( &record2 ), QString( "" ) ); // Evaluates empty - QCOMPARE( addr2.evaluate( &record3 ), QString( "" ) ); // Evaluates empty + QCOMPARE( addr2.evaluate( &record1, &variables ), QString( "\nApt. 5B" ) ); // Prepends a newline + QCOMPARE( addr2.evaluate( &record2, &variables ), QString( "" ) ); // Evaluates empty + QCOMPARE( addr2.evaluate( &record3, &variables ), QString( "" ) ); // Evaluates empty } diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index fb84528..f7cdb4e 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -184,24 +184,24 @@ Dialog - - Variable Type: - - Name: - - Value: - - Increment: - Step Size: + Variable type: + + + + Initial value: + + + + Step size: @@ -1060,10 +1060,6 @@ Variable - - Numeric - - String @@ -1084,6 +1080,14 @@ Per page + + Integer + + + + Floating Point + + VariablesView @@ -2141,10 +2145,6 @@ Type - - Value - - Increment @@ -2153,6 +2153,10 @@ Step Size + + Initial Value + + glabels::barcode::Backends From efbb052856a6c46345194895c5ef2ed6331efeec Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 24 Mar 2019 20:22:12 -0400 Subject: [PATCH 11/32] Implemented variables in merge print jobs. --- model/PageRenderer.cpp | 80 +++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 32 deletions(-) diff --git a/model/PageRenderer.cpp b/model/PageRenderer.cpp index f1ada0f..fc27d2c 100644 --- a/model/PageRenderer.cpp +++ b/model/PageRenderer.cpp @@ -294,46 +294,62 @@ namespace glabels void PageRenderer::printMergePage( QPainter* painter, int iPage ) const { - int iRecord = 0; - int iStart = 0; - int iEnd = mNLabelsPerPage; - - if ( iPage == 0 ) - { - iStart = mStartLabel; - } - - if ( (mLastLabel / mNLabelsPerPage) == iPage ) - { - iEnd = mLastLabel % mNLabelsPerPage; - } - - const QList records = mMerge->selectedRecords(); - if ( records.size() ) - { - iRecord = (iPage*mNLabelsPerPage + iStart - mStartLabel) % records.size(); - } - printCropMarks( painter ); - for ( int i = iStart; i < iEnd; i++ ) + int iCopy = 0; + int iLabel = mStartLabel; + int iCurrentPage = 0; + + const QList records = mMerge->selectedRecords(); + int iRecord = 0; + int nRecords = records.size(); + + if ( nRecords == 0 ) { - painter->save(); - - painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() ); + return; + } - painter->save(); + mVariables->resetVariables(); - clipLabel( painter ); - printLabel( painter, records[iRecord], mVariables ); + while ( (iCopy < mNCopies) && (iCurrentPage <= iPage) ) + { + if ( iCurrentPage == iPage ) + { + int i = iLabel % mNLabelsPerPage; + + painter->save(); - painter->restore(); // From before clip - - printOutline( painter ); + painter->translate( mOrigins[i].x().pt(), mOrigins[i].y().pt() ); - painter->restore(); // From before translation + painter->save(); - iRecord = (iRecord + 1) % records.size(); + clipLabel( painter ); + printLabel( painter, records[iRecord], mVariables ); + + painter->restore(); // From before clip + + printOutline( painter ); + + painter->restore(); // From before translation + } + + iRecord = (iRecord + 1) % nRecords; + if ( iRecord == 0 ) + { + iCopy++; + } + iLabel++; + iCurrentPage = iLabel / mNLabelsPerPage; + + mVariables->incrementVariablesOnMerge(); + if ( iRecord == 0 ) + { + mVariables->incrementVariablesOnCopy(); + } + if ( (iLabel % mNLabelsPerPage) == 0 /* starting a new page */ ) + { + mVariables->incrementVariablesOnPage(); + } } } From 54a66dfd8f8d5bf588b4860da2dfadb0287f8e23 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 24 Mar 2019 22:33:40 -0400 Subject: [PATCH 12/32] Increment per item, not per merge record. --- glabels/EditVariableDialog.cpp | 2 +- model/PageRenderer.cpp | 3 ++- model/Variable.cpp | 24 ++++++++++++------------ model/Variable.h | 4 ++-- model/Variables.cpp | 24 ++++++++++++------------ model/Variables.h | 2 +- translations/glabels_C.ts | 8 ++++---- 7 files changed, 34 insertions(+), 33 deletions(-) diff --git a/glabels/EditVariableDialog.cpp b/glabels/EditVariableDialog.cpp index 4d3b84d..4a1135e 100644 --- a/glabels/EditVariableDialog.cpp +++ b/glabels/EditVariableDialog.cpp @@ -37,8 +37,8 @@ namespace // All variable increments. (must be in sorted order) const QVector allIncrements = { glabels::model::Variable::Increment::NEVER, + glabels::model::Variable::Increment::PER_ITEM, glabels::model::Variable::Increment::PER_COPY, - glabels::model::Variable::Increment::PER_MERGE_RECORD, glabels::model::Variable::Increment::PER_PAGE }; } diff --git a/model/PageRenderer.cpp b/model/PageRenderer.cpp index fc27d2c..8af7d17 100644 --- a/model/PageRenderer.cpp +++ b/model/PageRenderer.cpp @@ -283,6 +283,7 @@ namespace glabels iLabel++; iCurrentPage = iLabel / mNLabelsPerPage; + mVariables->incrementVariablesOnItem(); mVariables->incrementVariablesOnCopy(); if ( (iLabel % mNLabelsPerPage) == 0 /* starting a new page */ ) { @@ -341,7 +342,7 @@ namespace glabels iLabel++; iCurrentPage = iLabel / mNLabelsPerPage; - mVariables->incrementVariablesOnMerge(); + mVariables->incrementVariablesOnItem(); if ( iRecord == 0 ) { mVariables->incrementVariablesOnCopy(); diff --git a/model/Variable.cpp b/model/Variable.cpp index 8b81a86..1cdca5d 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -90,9 +90,9 @@ namespace glabels } - void Variable::incrementValueOnCopy() + void Variable::incrementValueOnItem() { - if ( mIncrement == Increment::PER_COPY ) + if ( mIncrement == Increment::PER_ITEM ) { switch (mType) { @@ -110,9 +110,9 @@ namespace glabels } - void Variable::incrementValueOnMerge() + void Variable::incrementValueOnCopy() { - if ( mIncrement == Increment::PER_MERGE_RECORD ) + if ( mIncrement == Increment::PER_COPY ) { switch (mType) { @@ -219,10 +219,10 @@ namespace glabels { case Increment::NEVER: return tr("Never"); + case Increment::PER_ITEM: + return tr("Per item"); case Increment::PER_COPY: return tr("Per copy"); - case Increment::PER_MERGE_RECORD: - return tr("Per merge record"); case Increment::PER_PAGE: return tr("Per page"); } @@ -235,10 +235,10 @@ namespace glabels { case Increment::NEVER: return "never"; + case Increment::PER_ITEM: + return "per_item"; case Increment::PER_COPY: return "per_copy"; - case Increment::PER_MERGE_RECORD: - return "per_merge_record"; case Increment::PER_PAGE: return "per_page"; } @@ -251,14 +251,14 @@ namespace glabels { return Increment::NEVER; } + else if ( id == "per_item" ) + { + return Increment::PER_ITEM; + } else if ( id == "per_copy" ) { return Increment::PER_COPY; } - else if ( id == "per_merge_record" ) - { - return Increment::PER_MERGE_RECORD; - } else if ( id == "per_page" ) { return Increment::PER_PAGE; diff --git a/model/Variable.h b/model/Variable.h index 3feb694..95f3dec 100644 --- a/model/Variable.h +++ b/model/Variable.h @@ -46,8 +46,8 @@ namespace glabels enum class Increment { NEVER, + PER_ITEM, PER_COPY, - PER_MERGE_RECORD, PER_PAGE }; @@ -71,8 +71,8 @@ namespace glabels QString stepSize() const; void resetValue(); + void incrementValueOnItem(); void incrementValueOnCopy(); - void incrementValueOnMerge(); void incrementValueOnPage(); QString value() const; diff --git a/model/Variables.cpp b/model/Variables.cpp index 9bf149f..03fa927 100644 --- a/model/Variables.cpp +++ b/model/Variables.cpp @@ -97,6 +97,18 @@ namespace glabels } + /// + /// Increment variables on item + /// + void Variables::incrementVariablesOnItem() + { + for ( auto& v : *this ) + { + v.incrementValueOnItem(); + } + } + + /// /// Increment variables on copy /// @@ -109,18 +121,6 @@ namespace glabels } - /// - /// Increment variables on merge record - /// - void Variables::incrementVariablesOnMerge() - { - for ( auto& v : *this ) - { - v.incrementValueOnMerge(); - } - } - - /// /// Increment variables on page /// diff --git a/model/Variables.h b/model/Variables.h index ec7b578..379d56f 100644 --- a/model/Variables.h +++ b/model/Variables.h @@ -64,8 +64,8 @@ namespace glabels void replaceVariable( const QString& name, const Variable& variable ); void resetVariables(); + void incrementVariablesOnItem(); void incrementVariablesOnCopy(); - void incrementVariablesOnMerge(); void incrementVariablesOnPage(); diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index f7cdb4e..75a8f11 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1072,10 +1072,6 @@ Per copy - - Per merge record - - Per page @@ -1088,6 +1084,10 @@ Floating Point + + Per item + + VariablesView From 87cc5d7e2203748e49a025d60888ae11ed2cf987 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 30 Mar 2019 12:50:30 -0400 Subject: [PATCH 13/32] Redesigned image selection in ObjectEditor to use new FieldCombo widget. --- glabels/CMakeLists.txt | 2 + glabels/FieldCombo.cpp | 146 +++++++++++++++++++++++++++++ glabels/FieldCombo.h | 94 +++++++++++++++++++ glabels/ObjectEditor.cpp | 27 ++++-- glabels/ObjectEditor.h | 2 +- glabels/ui/ObjectEditor.ui | 182 +++++++++++++++++++------------------ translations/glabels_C.ts | 24 ++--- 7 files changed, 365 insertions(+), 112 deletions(-) create mode 100644 glabels/FieldCombo.cpp create mode 100644 glabels/FieldCombo.h diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index df14917..d03daa7 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -18,6 +18,7 @@ set (glabels_sources Cursors.cpp EditVariableDialog.cpp FieldButton.cpp + FieldCombo.cpp File.cpp Help.cpp Icons.cpp @@ -55,6 +56,7 @@ set (glabels_qobject_headers ColorPaletteButtonItem.h EditVariableDialog.h FieldButton.h + FieldCombo.h File.h LabelEditor.h MainWindow.h diff --git a/glabels/FieldCombo.cpp b/glabels/FieldCombo.cpp new file mode 100644 index 0000000..0a41107 --- /dev/null +++ b/glabels/FieldCombo.cpp @@ -0,0 +1,146 @@ +/* FieldCombo.cpp + * + * Copyright (C) 2014-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 "FieldCombo.h" + +#include +#include + + +namespace glabels +{ + + /// + /// Constructor + /// + FieldCombo::FieldCombo( QWidget* parent ) + : QComboBox(parent) + { + connect( this, SIGNAL(currentIndexChanged(int)), + this, SLOT(onIndexChanged(int)) ); + } + + + /// + /// Is current selection the alternative default selection? + /// + bool FieldCombo::isCurrentSelectionSpecial() const + { + return currentIndex() == 0; + } + + + /// + /// Return current selection + /// + QString FieldCombo::currentSelection() const + { + return mFieldNames[ currentIndex() ]; + } + + + /// + /// Set current selection to special + /// + void FieldCombo::setCurrentSelectionToSpecial() + { + setCurrentIndex( 0 ); + } + + + /// + /// Set current selection + /// + void FieldCombo::setCurrentSelection( const QString& key ) + { + setCurrentText( QString( "${%1}" ).arg( key ) ); + } + + + /// + /// Set alternative default selection + /// + void FieldCombo::setSpecialSelectionText( const QString& name ) + { + mName = name; + if ( count() == 0 ) + { + addItem( mName ); + } + else + { + setItemText( 0, mName ); + } + } + + + /// + /// Set field selections + /// + void FieldCombo::setFieldSelections( const merge::Merge* merge, + const model::Variables* variables ) + { + // Clear old keys + clear(); + mFieldNames.clear(); + + // Add default alt selection + addItem( mName ); + mFieldNames.append( mName ); + + // Add merge fields, if any + for ( auto& key : merge->keys() ) + { + addItem( QString( "${%1}" ).arg( key ) ); + mFieldNames.append( key ); + } + + // Add variables, if any + for ( auto& key : variables->keys() ) + { + addItem( QString( "${%1}" ).arg( key ) ); + mFieldNames.append( key ); + } + } + + + /// + /// Clear field selections + /// + void FieldCombo::clearFieldSelections() + { + clear(); + mFieldNames.clear(); + + addItem( mName ); + mFieldNames.append( mName ); + } + + + /// + /// onMenuKeySelected slot + /// + void FieldCombo::onIndexChanged( int index ) + { + emit selectionChanged(); + } + + +} // namespace glabels diff --git a/glabels/FieldCombo.h b/glabels/FieldCombo.h new file mode 100644 index 0000000..a748628 --- /dev/null +++ b/glabels/FieldCombo.h @@ -0,0 +1,94 @@ +/* FieldCombo.h + * + * Copyright (C) 2014-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 FieldCombo_h +#define FieldCombo_h + + +#include "model/Variables.h" +#include "merge/Merge.h" + +#include +#include +#include + + +namespace glabels +{ + + /// + /// Field Combo + /// + class FieldCombo : public QComboBox + { + Q_OBJECT + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// + public: + FieldCombo( QWidget* parent = nullptr ); + + + ///////////////////////////////// + // Signals + ///////////////////////////////// + signals: + void selectionChanged(); + + + ///////////////////////////////// + // Public Methods + ///////////////////////////////// + public: + bool isCurrentSelectionSpecial() const; + QString currentSelection() const; + + void setCurrentSelectionToSpecial(); + void setCurrentSelection( const QString& key ); + + void setSpecialSelectionText( const QString& name = "" ); + + void setFieldSelections( const merge::Merge* merge, + const model::Variables* variables ); + + void clearFieldSelections(); + + + ///////////////////////////////// + // Slots + ///////////////////////////////// + private slots: + void onIndexChanged( int index ); + + + ///////////////////////////////// + // Private Data + ///////////////////////////////// + private: + QString mName; + QVector mFieldNames; + + }; + +} + + +#endif // FieldCombo_h diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index f61e9fe..ee2ba24 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -69,7 +69,7 @@ namespace glabels textInsertFieldCombo->setName( tr("Insert Field") ); barcodeInsertFieldCombo->setName( tr("Insert Field") ); - imageFieldCombo->setName( tr("Key") ); + imageFieldCombo->setSpecialSelectionText( tr("Selected File...") ); setEnabled( false ); hidePages(); @@ -120,13 +120,14 @@ namespace glabels model::TextNode filenameNode = mObject->filenameNode(); + imageFileSelectionBox->setVisible( !filenameNode.isField() ); if ( filenameNode.isField() ) { - QString field = QString("${%1}").arg( filenameNode.data() ); - imageFilenameLineEdit->setText( field ); + imageFieldCombo->setCurrentSelection( filenameNode.data() ); } else { + imageFieldCombo->setCurrentSelectionToSpecial(); imageFilenameLineEdit->setText( filenameNode.data() ); } @@ -506,7 +507,7 @@ namespace glabels fillColorButton->setKeys( keys ); textInsertFieldCombo->setKeys( keys ); barcodeInsertFieldCombo->setKeys( keys ); - imageFieldCombo->setKeys( keys ); + imageFieldCombo->setFieldSelections( mModel->merge(), mModel->variables() ); shadowColorButton->setKeys( keys ); } } @@ -616,10 +617,22 @@ namespace glabels } - void ObjectEditor::onImageKeySelected( QString key ) + void ObjectEditor::onImageComboChanged() { - mUndoRedoModel->checkpoint( tr("Set image") ); - mObject->setFilenameNode( model::TextNode( true, key ) ); + imageFileSelectionBox->setVisible( imageFieldCombo->isCurrentSelectionSpecial() ); + + if ( mObject ) + { + mUndoRedoModel->checkpoint( tr("Set image") ); + if ( imageFieldCombo->isCurrentSelectionSpecial() ) + { + mObject->setFilenameNode( model::TextNode( false, imageFilenameLineEdit->text() ) ); + } + else + { + mObject->setFilenameNode( model::TextNode( true, imageFieldCombo->currentSelection() ) ); + } + } } diff --git a/glabels/ObjectEditor.h b/glabels/ObjectEditor.h index 6e84687..311f691 100644 --- a/glabels/ObjectEditor.h +++ b/glabels/ObjectEditor.h @@ -87,7 +87,7 @@ namespace glabels void onLineControlsChanged(); void onFillControlsChanged(); void onImageFileButtonClicked(); - void onImageKeySelected( QString key ); + void onImageComboChanged(); void onPositionControlsChanged(); void onRectSizeControlsChanged(); void onLineSizeControlsChanged(); diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index 0493a38..d213373 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -31,7 +31,7 @@ Form - + @@ -763,77 +763,74 @@ File - - - + + + + + + 0 + 0 + + - - - - 0 - 0 - - - - - 231 - 0 - - - - true - - - None - - + + Selected File... + - - - - - - - 0 - 0 - - - - Select File... - - - - - - - - 0 - 0 - - - - or - - - - - - - - 0 - 0 - - - - - Select Merge Field... - - - - - - - + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 231 + 0 + + + + true + + + None + + + + + + + + 0 + 0 + + + + Browse... + + + + + @@ -1545,6 +1542,14 @@ selectionChanged() + + glabels::FieldCombo + QComboBox +
FieldCombo.h
+ + selectionChanged() + +
@@ -1999,13 +2004,13 @@ - imageFileButton + imageBrowseButton clicked() ObjectEditor onImageFileButtonClicked() - 133 + 365 175 @@ -2014,22 +2019,6 @@ - - imageFieldCombo - keySelected(QString) - ObjectEditor - onImageKeySelected(QString) - - - 302 - 175 - - - 397 - 32 - - - textEdit textChanged() @@ -2190,6 +2179,22 @@ + + imageFieldCombo + selectionChanged() + ObjectEditor + onImageComboChanged() + + + 283 + 118 + + + 398 + 18 + + + onChanged() @@ -2206,5 +2211,6 @@ onTextInsertFieldKeySelected(QString) onBarcodeControlsChanged() onBarcodeInsertFieldKeySelected(QString) + onImageComboChanged() diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 75a8f11..f131f4f 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -405,18 +405,6 @@ File - - Select File... - - - - or - - - - Select Merge Field... - - Line/Fill @@ -493,6 +481,10 @@ Opacity: + + Browse... + + PreferencesDialog @@ -1760,10 +1752,6 @@ Insert Field - - Key - - Original size @@ -1900,6 +1888,10 @@ Shadow + + Selected File... + + glabels::PrintView From d9a41c66f08dfec65a36628d9324b3fc2ab45524 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 30 Mar 2019 18:59:15 -0400 Subject: [PATCH 14/32] Don't emit selectionChanged if index is invalid. --- glabels/FieldCombo.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/glabels/FieldCombo.cpp b/glabels/FieldCombo.cpp index 0a41107..c2da4a7 100644 --- a/glabels/FieldCombo.cpp +++ b/glabels/FieldCombo.cpp @@ -139,7 +139,10 @@ namespace glabels /// void FieldCombo::onIndexChanged( int index ) { - emit selectionChanged(); + if ( index >= 0 ) + { + emit selectionChanged(); + } } From 4e94933dcf2a93e66680f56ac199d8faae2dfdb1 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 20 Jul 2019 23:18:03 -0400 Subject: [PATCH 15/32] Redesigned FieldButton. --- glabels/FieldButton.cpp | 94 ++++++++---------- glabels/FieldButton.h | 22 +++-- glabels/ObjectEditor.cpp | 19 ++-- glabels/ObjectEditor.h | 2 +- glabels/ui/ObjectEditor.ui | 192 +++++++++++++++++++------------------ translations/glabels_C.ts | 19 ++++ 6 files changed, 182 insertions(+), 166 deletions(-) diff --git a/glabels/FieldButton.cpp b/glabels/FieldButton.cpp index f6c25b6..212a766 100644 --- a/glabels/FieldButton.cpp +++ b/glabels/FieldButton.cpp @@ -1,6 +1,6 @@ /* FieldButton.cpp * - * Copyright (C) 2014-2016 Jim Evins + * Copyright (C) 2014-2019 Jim Evins * * This file is part of gLabels-qt. * @@ -30,79 +30,61 @@ namespace glabels /// /// Constructor /// - FieldButton::FieldButton( QWidget* parent ) - : QComboBox(parent) + FieldButton::FieldButton( QWidget* parent ) : QPushButton(parent) { setEnabled( false ); - - connect( this, SIGNAL(currentIndexChanged(int)), this, SLOT(onIndexChanged(int)) ); + setMenu( &mMenu ); + + connect( &mMenu, SIGNAL(triggered(QAction*)), + this, SLOT(onMenuActionTriggered(QAction*)) ); } - void FieldButton::setName( const QString& name ) - { - mName = name; - if ( count() == 0 ) - { - addItem( mName ); - } - else - { - setItemText( 0, mName ); - } - - // Item 0 is the ComboBox title, not an item intended for selection. So disable it. - const auto* itemModel = qobject_cast(model()); - QStandardItem* item = itemModel->item(0); - item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) ); - } - - - void FieldButton::setKeys( const QStringList& keyList ) + /// + /// Set Keys + /// + void FieldButton::setKeys( const merge::Merge* merge, + const model::Variables* variables ) { // Clear old keys - clear(); - addItem( mName ); + mMenu.clear(); + + // Add merge keys, if any + mMenu.addSection( tr("Merge fields") ); + for ( auto& key : merge->keys() ) + { + auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) ); + action->setData( key ); + } + if ( merge->keys().empty() ) + { + auto* action = mMenu.addAction( "None" ); + action->setEnabled( false ); + } - // Item 0 is the ComboBox title, not an item intended for selection. So disable it. - const auto* itemModel = qobject_cast(model()); - QStandardItem* item = itemModel->item(0); - item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) ); - - // Add new keys - if ( keyList.size() > 0 ) + // Add variable keys, if any + mMenu.addSection( tr("Variables") ); + for ( auto& key : variables->keys() ) { - addItems( keyList ); - setEnabled( true ); + auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) ); + action->setData( key ); } - else + if ( variables->keys().empty() ) { - setEnabled( false ); + auto* action = mMenu.addAction( "None" ); + action->setEnabled( false ); } + + setEnabled( !merge->keys().empty() || !variables->keys().empty() ); } - void FieldButton::clearKeys() - { - clear(); - addItem( mName ); - - setEnabled( false ); - } - - - /// - /// onMenuKeySelected slot + /// onMenuActionTriggered slot /// - void FieldButton::onIndexChanged( int index ) + void FieldButton::onMenuActionTriggered( QAction* action ) { - if ( index > 0 ) - { - emit keySelected( itemText(index) ); - - setCurrentIndex( 0 ); - } + emit keySelected( action->data().toString() ); } } // namespace glabels diff --git a/glabels/FieldButton.h b/glabels/FieldButton.h index 1da2d57..230a86d 100644 --- a/glabels/FieldButton.h +++ b/glabels/FieldButton.h @@ -1,6 +1,6 @@ /* FieldButton.h * - * Copyright (C) 2014-2016 Jim Evins + * Copyright (C) 2019 Jim Evins * * This file is part of gLabels-qt. * @@ -22,8 +22,13 @@ #define FieldButton_h -#include -#include +#include "model/Variables.h" +#include "merge/Merge.h" + +#include +#include +#include +#include namespace glabels @@ -32,7 +37,7 @@ namespace glabels /// /// Field Button /// - class FieldButton : public QComboBox + class FieldButton : public QPushButton { Q_OBJECT @@ -54,23 +59,22 @@ namespace glabels // Public Methods ///////////////////////////////// public: - void setName( const QString& name = "" ); - void setKeys( const QStringList& keyList ); - void clearKeys(); + void setKeys( const merge::Merge* merge, + const model::Variables* variables ); ///////////////////////////////// // Slots ///////////////////////////////// private slots: - void onIndexChanged( int index ); + void onMenuActionTriggered( QAction* action ); ///////////////////////////////// // Private Data ///////////////////////////////// private: - QString mName; + QMenu mMenu; }; diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index ee2ba24..8736ddd 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -67,9 +67,9 @@ namespace glabels barcodeColorButton->init( tr("Default"), QColor(0,0,0,255), QColor(0,0,0,255) ); shadowColorButton->init( tr("Default"), QColor(0,0,0,255), QColor(0,0,0,255) ); - textInsertFieldCombo->setName( tr("Insert Field") ); - barcodeInsertFieldCombo->setName( tr("Insert Field") ); - imageFieldCombo->setSpecialSelectionText( tr("Selected File...") ); + textInsertFieldButton->setText( tr("Insert field") ); + barcodeInsertFieldButton->setText( tr("Insert field") ); + imageFieldCombo->setSpecialSelectionText( tr("Selected file...") ); setEnabled( false ); hidePages(); @@ -93,11 +93,14 @@ namespace glabels this, SLOT(onSelectionChanged()) ); connect( mModel, SIGNAL(mergeSourceChanged()), - this, SLOT(onMergeSourceChanged()) ); + this, SLOT(onFieldsAvailableChanged()) ); + + connect( mModel, SIGNAL(variablesChanged()), + this, SLOT(onFieldsAvailableChanged()) ); onLabelSizeChanged(); onSelectionChanged(); - onMergeSourceChanged(); + onFieldsAvailableChanged(); } @@ -498,15 +501,15 @@ namespace glabels } - void ObjectEditor::onMergeSourceChanged() + void ObjectEditor::onFieldsAvailableChanged() { if ( !mBlocked ) { QStringList keys = mModel->merge()->keys(); lineColorButton->setKeys( keys ); fillColorButton->setKeys( keys ); - textInsertFieldCombo->setKeys( keys ); - barcodeInsertFieldCombo->setKeys( keys ); + textInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); + barcodeInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); imageFieldCombo->setFieldSelections( mModel->merge(), mModel->variables() ); shadowColorButton->setKeys( keys ); } diff --git a/glabels/ObjectEditor.h b/glabels/ObjectEditor.h index 311f691..53cdf5b 100644 --- a/glabels/ObjectEditor.h +++ b/glabels/ObjectEditor.h @@ -80,7 +80,7 @@ namespace glabels void onSettingsChanged(); void onLabelSizeChanged(); void onSelectionChanged(); - void onMergeSourceChanged(); + void onFieldsAvailableChanged(); void onObjectChanged(); void onObjectMoved(); void onObjectDestroyed(); diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index d213373..1a9d51f 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -70,7 +70,7 @@ - 0 + 1 @@ -579,7 +579,11 @@ - + + + Insert field + + @@ -729,7 +733,11 @@ - + + + Insert field + + @@ -1526,14 +1534,6 @@ colorChanged() - - glabels::FieldButton - QComboBox -
FieldButton.h
- - keySelected(QString) - -
glabels::BarcodeMenuButton QPushButton @@ -1550,6 +1550,14 @@ selectionChanged() + + glabels::FieldButton + QPushButton +
FieldButton.h
+ + keySelected(QString) + +
@@ -1658,8 +1666,8 @@ onTextControlsChanged() - 157 - 333 + 160 + 332 396 @@ -1674,8 +1682,8 @@ onTextControlsChanged() - 198 - 333 + 200 + 332 398 @@ -1690,8 +1698,8 @@ onTextControlsChanged() - 238 - 333 + 240 + 332 395 @@ -1706,8 +1714,8 @@ onTextControlsChanged() - 284 - 333 + 286 + 332 393 @@ -1722,8 +1730,8 @@ onTextControlsChanged() - 325 - 333 + 326 + 332 396 @@ -1739,7 +1747,7 @@ 365 - 333 + 332 397 @@ -1754,8 +1762,8 @@ onTextControlsChanged() - 184 - 407 + 189 + 404 394 @@ -1771,7 +1779,7 @@ 178 - 143 + 139 392 @@ -1786,8 +1794,8 @@ onLineControlsChanged() - 137 - 179 + 136 + 174 1 @@ -1802,8 +1810,8 @@ onFillControlsChanged() - 136 - 263 + 135 + 256 6 @@ -1818,8 +1826,8 @@ onPositionControlsChanged() - 159 - 142 + 160 + 138 399 @@ -1834,8 +1842,8 @@ onPositionControlsChanged() - 159 - 179 + 160 + 174 325 @@ -1850,8 +1858,8 @@ onRectSizeControlsChanged() - 159 - 265 + 160 + 258 3 @@ -1866,8 +1874,8 @@ onRectSizeControlsChanged() - 159 - 302 + 160 + 294 0 @@ -1882,8 +1890,8 @@ onResetImageSize() - 210 - 372 + 213 + 362 4 @@ -1914,8 +1922,8 @@ onShadowControlsChanged() - 165 - 142 + 166 + 138 398 @@ -1930,8 +1938,8 @@ onShadowControlsChanged() - 165 - 179 + 166 + 174 294 @@ -1946,8 +1954,8 @@ onShadowControlsChanged() - 142 - 215 + 141 + 209 399 @@ -1962,8 +1970,8 @@ onShadowControlsChanged() - 159 - 252 + 162 + 245 399 @@ -1978,8 +1986,8 @@ onLineSizeControlsChanged() - 174 - 456 + 177 + 444 5 @@ -1994,8 +2002,8 @@ onLineSizeControlsChanged() - 174 - 493 + 177 + 480 1 @@ -2010,8 +2018,8 @@ onImageFileButtonClicked() - 365 - 175 + 367 + 168 394 @@ -2035,22 +2043,6 @@ - - textInsertFieldCombo - keySelected(QString) - ObjectEditor - onTextInsertFieldKeySelected(QString) - - - 239 - 599 - - - 395 - 645 - - - barcodeShowTextCheck toggled(bool) @@ -2058,8 +2050,8 @@ onBarcodeControlsChanged() - 178 - 172 + 195 + 167 4 @@ -2074,8 +2066,8 @@ onBarcodeControlsChanged() - 164 - 204 + 195 + 198 1 @@ -2091,7 +2083,7 @@ 126 - 239 + 232 1 @@ -2115,22 +2107,6 @@ - - barcodeInsertFieldCombo - keySelected(QString) - ObjectEditor - onBarcodeInsertFieldKeySelected(QString) - - - 239 - 400 - - - 403 - 625 - - - barcodeStyleButton selectionChanged() @@ -2138,8 +2114,8 @@ onBarcodeControlsChanged() - 178 - 140 + 195 + 136 5 @@ -2195,6 +2171,38 @@ + + textInsertFieldButton + keySelected(QString) + ObjectEditor + onTextInsertFieldKeySelected(QString) + + + 191 + 589 + + + 227 + 642 + + + + + barcodeInsertFieldButton + keySelected(QString) + ObjectEditor + onBarcodeInsertFieldKeySelected(QString) + + + 208 + 379 + + + 205 + 649 + + + onChanged() diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index f131f4f..933c810 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1146,6 +1146,17 @@
+ + glabels::FieldButton + + Merge fields + + + + Variables + + + glabels::File @@ -1892,6 +1903,14 @@ Selected File... + + Insert field + + + + Selected file... + + glabels::PrintView From 3cfda79b8200b8263b261d5865cf895ddc58a7c0 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 21 Jul 2019 00:59:14 -0400 Subject: [PATCH 16/32] Yet another redesign of image file selection in ObjectEditor. --- glabels/CMakeLists.txt | 2 - glabels/FieldButton.cpp | 2 +- glabels/FieldCombo.cpp | 149 -------------------------------- glabels/FieldCombo.h | 94 -------------------- glabels/ObjectEditor.cpp | 21 ++--- glabels/ObjectEditor.h | 2 +- glabels/ui/ObjectEditor.ui | 172 +++++++++++++++---------------------- translations/glabels_C.ts | 2 +- 8 files changed, 77 insertions(+), 367 deletions(-) delete mode 100644 glabels/FieldCombo.cpp delete mode 100644 glabels/FieldCombo.h diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index d03daa7..df14917 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -18,7 +18,6 @@ set (glabels_sources Cursors.cpp EditVariableDialog.cpp FieldButton.cpp - FieldCombo.cpp File.cpp Help.cpp Icons.cpp @@ -56,7 +55,6 @@ set (glabels_qobject_headers ColorPaletteButtonItem.h EditVariableDialog.h FieldButton.h - FieldCombo.h File.h LabelEditor.h MainWindow.h diff --git a/glabels/FieldButton.cpp b/glabels/FieldButton.cpp index 212a766..483e770 100644 --- a/glabels/FieldButton.cpp +++ b/glabels/FieldButton.cpp @@ -1,6 +1,6 @@ /* FieldButton.cpp * - * Copyright (C) 2014-2019 Jim Evins + * Copyright (C) 2019 Jim Evins * * This file is part of gLabels-qt. * diff --git a/glabels/FieldCombo.cpp b/glabels/FieldCombo.cpp deleted file mode 100644 index c2da4a7..0000000 --- a/glabels/FieldCombo.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* FieldCombo.cpp - * - * Copyright (C) 2014-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 "FieldCombo.h" - -#include -#include - - -namespace glabels -{ - - /// - /// Constructor - /// - FieldCombo::FieldCombo( QWidget* parent ) - : QComboBox(parent) - { - connect( this, SIGNAL(currentIndexChanged(int)), - this, SLOT(onIndexChanged(int)) ); - } - - - /// - /// Is current selection the alternative default selection? - /// - bool FieldCombo::isCurrentSelectionSpecial() const - { - return currentIndex() == 0; - } - - - /// - /// Return current selection - /// - QString FieldCombo::currentSelection() const - { - return mFieldNames[ currentIndex() ]; - } - - - /// - /// Set current selection to special - /// - void FieldCombo::setCurrentSelectionToSpecial() - { - setCurrentIndex( 0 ); - } - - - /// - /// Set current selection - /// - void FieldCombo::setCurrentSelection( const QString& key ) - { - setCurrentText( QString( "${%1}" ).arg( key ) ); - } - - - /// - /// Set alternative default selection - /// - void FieldCombo::setSpecialSelectionText( const QString& name ) - { - mName = name; - if ( count() == 0 ) - { - addItem( mName ); - } - else - { - setItemText( 0, mName ); - } - } - - - /// - /// Set field selections - /// - void FieldCombo::setFieldSelections( const merge::Merge* merge, - const model::Variables* variables ) - { - // Clear old keys - clear(); - mFieldNames.clear(); - - // Add default alt selection - addItem( mName ); - mFieldNames.append( mName ); - - // Add merge fields, if any - for ( auto& key : merge->keys() ) - { - addItem( QString( "${%1}" ).arg( key ) ); - mFieldNames.append( key ); - } - - // Add variables, if any - for ( auto& key : variables->keys() ) - { - addItem( QString( "${%1}" ).arg( key ) ); - mFieldNames.append( key ); - } - } - - - /// - /// Clear field selections - /// - void FieldCombo::clearFieldSelections() - { - clear(); - mFieldNames.clear(); - - addItem( mName ); - mFieldNames.append( mName ); - } - - - /// - /// onMenuKeySelected slot - /// - void FieldCombo::onIndexChanged( int index ) - { - if ( index >= 0 ) - { - emit selectionChanged(); - } - } - - -} // namespace glabels diff --git a/glabels/FieldCombo.h b/glabels/FieldCombo.h deleted file mode 100644 index a748628..0000000 --- a/glabels/FieldCombo.h +++ /dev/null @@ -1,94 +0,0 @@ -/* FieldCombo.h - * - * Copyright (C) 2014-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 FieldCombo_h -#define FieldCombo_h - - -#include "model/Variables.h" -#include "merge/Merge.h" - -#include -#include -#include - - -namespace glabels -{ - - /// - /// Field Combo - /// - class FieldCombo : public QComboBox - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - FieldCombo( QWidget* parent = nullptr ); - - - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void selectionChanged(); - - - ///////////////////////////////// - // Public Methods - ///////////////////////////////// - public: - bool isCurrentSelectionSpecial() const; - QString currentSelection() const; - - void setCurrentSelectionToSpecial(); - void setCurrentSelection( const QString& key ); - - void setSpecialSelectionText( const QString& name = "" ); - - void setFieldSelections( const merge::Merge* merge, - const model::Variables* variables ); - - void clearFieldSelections(); - - - ///////////////////////////////// - // Slots - ///////////////////////////////// - private slots: - void onIndexChanged( int index ); - - - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - QString mName; - QVector mFieldNames; - - }; - -} - - -#endif // FieldCombo_h diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index 8736ddd..dc480b5 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -69,7 +69,7 @@ namespace glabels textInsertFieldButton->setText( tr("Insert field") ); barcodeInsertFieldButton->setText( tr("Insert field") ); - imageFieldCombo->setSpecialSelectionText( tr("Selected file...") ); + imageFieldButton->setText( tr("Use field") ); setEnabled( false ); hidePages(); @@ -123,14 +123,12 @@ namespace glabels model::TextNode filenameNode = mObject->filenameNode(); - imageFileSelectionBox->setVisible( !filenameNode.isField() ); if ( filenameNode.isField() ) { - imageFieldCombo->setCurrentSelection( filenameNode.data() ); + imageFilenameLineEdit->setText( QString("${%1}").arg(filenameNode.data()) ); } else { - imageFieldCombo->setCurrentSelectionToSpecial(); imageFilenameLineEdit->setText( filenameNode.data() ); } @@ -510,7 +508,7 @@ namespace glabels fillColorButton->setKeys( keys ); textInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); barcodeInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); - imageFieldCombo->setFieldSelections( mModel->merge(), mModel->variables() ); + imageFieldButton->setKeys( mModel->merge(), mModel->variables() ); shadowColorButton->setKeys( keys ); } } @@ -620,21 +618,12 @@ namespace glabels } - void ObjectEditor::onImageComboChanged() + void ObjectEditor::onImageKeySelected( QString key ) { - imageFileSelectionBox->setVisible( imageFieldCombo->isCurrentSelectionSpecial() ); - if ( mObject ) { mUndoRedoModel->checkpoint( tr("Set image") ); - if ( imageFieldCombo->isCurrentSelectionSpecial() ) - { - mObject->setFilenameNode( model::TextNode( false, imageFilenameLineEdit->text() ) ); - } - else - { - mObject->setFilenameNode( model::TextNode( true, imageFieldCombo->currentSelection() ) ); - } + mObject->setFilenameNode( model::TextNode( true, key ) ); } } diff --git a/glabels/ObjectEditor.h b/glabels/ObjectEditor.h index 53cdf5b..57b380f 100644 --- a/glabels/ObjectEditor.h +++ b/glabels/ObjectEditor.h @@ -87,7 +87,7 @@ namespace glabels void onLineControlsChanged(); void onFillControlsChanged(); void onImageFileButtonClicked(); - void onImageComboChanged(); + void onImageKeySelected( QString key ); void onPositionControlsChanged(); void onRectSizeControlsChanged(); void onLineSizeControlsChanged(); diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index 1a9d51f..e46be75 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -70,7 +70,7 @@ - 1 + 2 @@ -766,83 +766,6 @@ Image - - - - File - - - - - - - 0 - 0 - - - - - Selected File... - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 231 - 0 - - - - true - - - None - - - - - - - - 0 - 0 - - - - Browse... - - - - - - - - - @@ -856,6 +779,57 @@ + + + + File + + + + + + + 0 + 0 + + + + + 231 + 0 + + + + true + + + None + + + + + + + + 0 + 0 + + + + Browse... + + + + + + + Use field + + + + + + @@ -1542,14 +1516,6 @@ selectionChanged() - - glabels::FieldCombo - QComboBox -
FieldCombo.h
- - selectionChanged() - -
glabels::FieldButton QPushButton @@ -2019,7 +1985,7 @@ 367 - 168 + 135 394 @@ -2155,22 +2121,6 @@ - - imageFieldCombo - selectionChanged() - ObjectEditor - onImageComboChanged() - - - 283 - 118 - - - 398 - 18 - - - textInsertFieldButton keySelected(QString) @@ -2203,6 +2153,22 @@ + + imageFieldButton + keySelected(QString) + ObjectEditor + onImageKeySelected(QString) + + + 317 + 160 + + + 331 + -12 + + + onChanged() diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 933c810..9a9f61b 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1908,7 +1908,7 @@ - Selected file... + Use field
From 5b9eba9af9e9f1a2e19f9e25f331d5bccdd9a2a8 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 21 Jul 2019 13:17:45 -0400 Subject: [PATCH 17/32] Tweaked look of image object placeholders. --- glabels/images/checkerboard.png | Bin 177 -> 2917 bytes model/ModelImageObject.cpp | 62 ++++++++++++++++++++++++++++++++ translations/glabels_C.ts | 7 ++++ 3 files changed, 69 insertions(+) diff --git a/glabels/images/checkerboard.png b/glabels/images/checkerboard.png index c97f40e2e67b6e4362b24b2936daa6e99d021dd1..575edc368640edeee32cfb7b4a385ee9ca4d8f4f 100644 GIT binary patch literal 2917 zcmZuzcQhMZA5K5D+o~1XQsdRwlvItNsFf;eH#BDLvrhQq{fn9X(rBnI zaKTIA2mqkV_c46#p>O5I?TU1FTnJ ztbpsl#)8=&miI(Hr)PPDt={Hip5P&)IgjF7Md!b>cNosm8+<;ma(22r&er|6Y!~iK zXa|l|te%|6`#*1C-Xf#?d8Uev%1aVJ{S(x6>$M@|9|wy#PET~V+pf|s8{zNrS=g_B zznpApeWVlHuKf|#VpW=uc`j%cfr6hMW9uKNk0K12Bn9*36f@%W-Kg*tUrY%0WuYRX z<#nqkh=W%V6Eh4X+`Ru}CB1u-k2Iwm*uqi~@t~d_=hEbqFFiUAY4uM^)0{hSv1vjV z5@fY2=yCbQ*S@QXYL#uF7L^Rjr~9|9j&*l&9~lNCNK6{H6`1;i5*XX*q0aWi7=hp( z-mwY2ShTfx3dS!DSv04WZD8ypYy9lw*G-sdJ99oq)vc&3>l(j)wb9cPpVp+JI5<3+UX}tb9n&zjI zT{mU;>$l1J}ZSWn#Mz2Ks0vsL#i>&G?6jyOQzNs zA&7?Nqb*BMhq~ZnS9T+m%RyCvxo|By>y{}^sB!pfQZxnQhn9)u1Tv>A3uagWGp=q% z#!R#cjNEw@TUFBW-ZG8+v98N>{X>15-~@ymTQeZL6`Wx%5$fpD9OgBDdJ{GBC7;5V z+MKbSn_6lw3J5-c{YEbyhCgaQ^dkj_2FKRUP$6 zZ_Pryd77IH`b`jcoz~)5ESbuC&x-r?3pVX^;kL>8?%63jandmC$24rZuQD304Ld|` zeVA<$MM?nUV~KBSWXmNS2F5sQq@EmFCsYap+e)D&R}h>F9ei8B#bj5@L<)D;Q0v6$ z{khv?>ikrTa>#<#Ye`4NZH6(E?|Uj7y>sqZ7qlhqKNFSYdo<+H{01I+$cL%J68!HA z7E4?!ggRZDUGAAyta#hm69?{))1~dQfyc>)cZAtmJc@b;3_(hyC`ZJv$NTIhxete> zwM^uC;*qYmyfvG598`w%B6uM7n9qB#aF5Nxs4JRw>H#YTdrr;6dz`Nwxa6 zr#>6IzN0HnXRqSr;}0cq*aVDTn+6`?oL%5MF8kfGJWWXazH%lf&t2;H1*yeI^edh6 zgS_z;IF>t2U#&fYCD~s7*|pkOW`Aj)*EX>Id9&`nADV)zKhd|jBpm~~`funXESmFn zLQ-jx=(ive#|Kj?RD|u(5zSt#CPB^y$9pcw1ik*iuD}^7y^La3z~X>Dbi-h( zU%>=h5zi2j=HWVC=WeCZ7wE{^&T5_3VAxv)tbOKK-&6A!SSWRXTS{A?Bp?Hvxc~y| zm0=V5J9?v%eEs~)C?66UI(wN!>4evutEQJb@m@LsU}UfxRTZ*IpOHClaO#L0^)2>g z?(giRQ`ZKQP@#t!f4-Cc@E&*{74Qt8o*%?1fPi<6#DE~+NC&=98WgbonQBe&2{QKf zy?u^*8kNY$c82z;F<>XL`Oz6J*T@ku;XWwcliF&Pxu!{2LZhlgW3|dUe&wrb5S>jV zYgd2(ivTb-?+ms|@k>K{5!bkQzsYKupQ)Ow{U+!`0i-B}Oi3Wy%P|tn1DYy@{fvoyB*OG@C?8COrOzr;=yuF|(xG?{>QD<&lQRXu{MIhc4DyV= zX2AuW+@e=I4|T5`(nPP!8!Y4U(ya?q?-m!M1_d`ui`lc6iCY*JXLFz2^enDwPU@fA z)rjtbnLNCwpV&$zqB~1hK85_;1jsXIFE^ybctasY>3>M0C%H zKVf(Y@l1D%NjVyYd)Y$5rJgcqr8cMJE?7t)l+6&uKkoCi(+hSBevtdDy?z15Kf4ndbw~5F(4l=hX9Y44G|L!pzuKrF za07D~2AL1gZWNy_rSXP;_va@z@b9*yILv-5^#>6f%ydr;y^rXlj82xs`HW#V|EO5A z#wR}Z{>a!MwDthr=~<$FQ3cHlaV z8R<*!hP-7(JH2Gr%uS=Wki$3(%eR#x-)c?><$zf==YRagWO=!C@{t(-TnhO}r2bpl zKe$b;g%wKLhEp~0&+Ncnw+hd=g~T;|S*V!}FsUPb?(^2GBh}2#3(Qy;4ct@i^mZ&$ zQ0`2yws#MX-W}HW4UW!R8R)vo`lGnmb1nXYX|im;$bmPKnlYndZ(Yqzoia8j#TzX$ zHXFWtHOLJ83O^|D=oSaoJ@MLLoBO2o|1qKX)IQA}TDbFc^P}T~++LhiTo)KyUqVEI z4vlLgS{Y$5l8b7()X|-!m4DqJpxFZBzWgrOh47+~jb2*1^0ITM=fPVg_^HIKr87PU zU#IBZly~GZ!2#Xiy3!JvN3_%CdhN&1p^H6-gYnwKoIm)LXNn=0VJ$Co-qlwbo0myq zb8Z1ln2W_Z0M4c$m|kf8~>=7dj_3umbrSJ%Ggcnv`EAst~c=Z6yq8qv(v482=FX2S}EY6U@6&j@IaXaPdrD zNyc6LtL&$wspEO6%&wYUT!qy3hToPGgZytULAJ6mUskEgKCsR?b(bo$D0%SXUl*E{ z%34c96|itQCIfX)7YwbdCd?fGpl80cD}XHYrNE{3fNHBzlc-r4DX9R=+?Q%s4XUba zsM$>>R$T|&r=e)$$G`6D5kPze72yF%D)wHRh#WOliUtTEvv;tCJ>JMjSESYdtS#46 ljN(?05|w0P(6wA7;OCpQgbEamTas2JY zjl2vBJj@6Ala{=(cPvv9l@{oHba&_GQbw7ERZI%Tl{du?-wZyTFJCVpm9e0a4M-dm aXX9O#bgPrkpxO>-5`(9!pUXO@geCw&H7yhX diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp index bc9eb18..9c30a42 100644 --- a/model/ModelImageObject.cpp +++ b/model/ModelImageObject.cpp @@ -40,6 +40,17 @@ namespace glabels QImage* ModelImageObject::smDefaultImage = nullptr; + // + // Private + // + namespace + { + const QColor fillColor = QColor( 224, 224, 224, 255 ); + const QColor labelColor = QColor( 102, 102, 102, 255 ); + const Distance pad = Distance::pt(2); + } + + /// /// Constructor /// @@ -436,10 +447,61 @@ namespace glabels if ( inEditor && (mFilenameNode.isField() || (!mImage && !mSvgRenderer) ) ) { + // + // Render default place holder image + // painter->save(); painter->setRenderHint( QPainter::SmoothPixmapTransform, false ); painter->drawImage( destRect, *smDefaultImage ); painter->restore(); + + // + // Print label on top of place holder image, if we have room + // + if ( (mW > 6*pad) && (mH > 4*pad) ) + { + QString labelText = tr("No image"); + if ( mFilenameNode.isField() ) + { + labelText = QString( "${%1}" ).arg( mFilenameNode.data() ); + } + + // Determine font size for labelText + QFont font( "Sans" ); + font.setPointSizeF( 6 ); + + QFontMetricsF fm( font ); + QRectF textRect = fm.boundingRect( labelText ); + + double wPts = (mW - 2*pad).pt(); + double hPts = (mH - 2*pad).pt(); + if ( (wPts < textRect.width()) || (hPts < textRect.height()) ) + { + double scaleX = wPts / textRect.width(); + double scaleY = hPts / textRect.height(); + font.setPointSizeF( 6 * std::min( scaleX, scaleY ) ); + } + + // Render hole for text (font size may have changed above) + fm = QFontMetricsF( font ); + textRect = fm.boundingRect( labelText ); + + QRectF holeRect( (mW.pt() - textRect.width())/2 - pad.pt(), + (mH.pt() - textRect.height())/2 - pad.pt(), + textRect.width() + 2*pad.pt(), + textRect.height() + 2*pad.pt() ); + + painter->setPen( Qt::NoPen ); + painter->setBrush( QBrush( fillColor ) ); + painter->drawRect( holeRect ); + + // Render text + painter->setFont( font ); + painter->setPen( QPen( labelColor ) ); + painter->drawText( QRectF( 0, 0, mW.pt(), mH.pt() ), + Qt::AlignCenter, + labelText ); + } } else if ( mImage ) { diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 9a9f61b..78a87d5 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -2550,6 +2550,13 @@ + + glabels::model::ModelImageObject + + No image + + + glabels::model::ModelTextObject From 8fa34325a5b15d9fabe322e5db88fdd2633f83c0 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 21 Jul 2019 13:44:39 -0400 Subject: [PATCH 18/32] Reconciled margin of VariablesView with other views. --- glabels/ui/VariablesView.ui | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/glabels/ui/VariablesView.ui b/glabels/ui/VariablesView.ui index a801498..c0953d6 100644 --- a/glabels/ui/VariablesView.ui +++ b/glabels/ui/VariablesView.ui @@ -14,6 +14,18 @@ Form + + 21 + + + 21 + + + 21 + + + 21 + From 1e1db1fc892196f307b0fe905fbe8bffa3753745 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 21 Jul 2019 17:08:24 -0400 Subject: [PATCH 19/32] Incorporated FieldButton into ColorPaletteDialog. Tweaked ColorPaletteDialog. --- glabels/CMakeLists.txt | 2 - glabels/ColorButton.cpp | 11 +- glabels/ColorButton.h | 5 +- glabels/ColorPaletteButtonItem.cpp | 124 ------------------- glabels/ColorPaletteButtonItem.h | 75 ------------ glabels/ColorPaletteDialog.cpp | 189 +++++++++++++---------------- glabels/ColorPaletteDialog.h | 22 ++-- glabels/ObjectEditor.cpp | 7 +- translations/glabels_C.ts | 16 ++- 9 files changed, 112 insertions(+), 339 deletions(-) delete mode 100644 glabels/ColorPaletteButtonItem.cpp delete mode 100644 glabels/ColorPaletteButtonItem.h diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index df14917..0ca4ff0 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -13,7 +13,6 @@ set (glabels_sources ColorHistory.cpp ColorPaletteDialog.cpp ColorPaletteItem.cpp - ColorPaletteButtonItem.cpp ColorSwatch.cpp Cursors.cpp EditVariableDialog.cpp @@ -52,7 +51,6 @@ set (glabels_qobject_headers ColorHistory.h ColorPaletteDialog.h ColorPaletteItem.h - ColorPaletteButtonItem.h EditVariableDialog.h FieldButton.h File.h diff --git a/glabels/ColorButton.cpp b/glabels/ColorButton.cpp index 1abb9a0..9789628 100644 --- a/glabels/ColorButton.cpp +++ b/glabels/ColorButton.cpp @@ -124,15 +124,10 @@ namespace glabels } - void ColorButton::setKeys( const QList keyList ) + void ColorButton::setKeys( const merge::Merge* merge, + const model::Variables* variables ) { - mDialog->setKeys( keyList ); - } - - - void ColorButton::clearKeys() - { - mDialog->clearKeys(); + mDialog->setKeys( merge, variables ); } diff --git a/glabels/ColorButton.h b/glabels/ColorButton.h index eb16611..a7155d8 100644 --- a/glabels/ColorButton.h +++ b/glabels/ColorButton.h @@ -63,8 +63,9 @@ namespace glabels void setColor( QColor color ); void setToDefault(); model::ColorNode colorNode(); - void setKeys( const QList keyList ); - void clearKeys(); + + void setKeys( const merge::Merge* merge, + const model::Variables* variables ); ///////////////////////////////// diff --git a/glabels/ColorPaletteButtonItem.cpp b/glabels/ColorPaletteButtonItem.cpp deleted file mode 100644 index ce8d5bf..0000000 --- a/glabels/ColorPaletteButtonItem.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* ColorPaletteButtonItem.cpp - * - * Copyright (C) 2014 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 "ColorPaletteButtonItem.h" - -#include -#include - - -namespace glabels -{ - - // - // Private - // - namespace - { - const int border = 4; - const int hBox = 25; - const int outlineWidthPixels = 1; - } - - - /// - /// Constructor From Data - /// - ColorPaletteButtonItem::ColorPaletteButtonItem( const QString& text, QWidget* parent ) - : QWidget(parent), mText(text), mHover(false) - { - setSizePolicy( QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed ) ); - setMinimumSize( hBox+2*border+1, hBox+2*border+1 ); - } - - - /// - /// Paint Event - /// - void ColorPaletteButtonItem::paintEvent( QPaintEvent* event ) - { - QPainter painter(this); - - // - // Draw background - // - if ( isEnabled() && mHover ) - { - QLinearGradient gradient( 0, 0, 0, height() ); - gradient.setColorAt( 0, palette().color( QPalette::Highlight ).lighter() ); - gradient.setColorAt( 1, palette().color( QPalette::Highlight ) ); - painter.setBrush( QBrush( gradient ) ); - - QPen pen( palette().color( QPalette::Text ) ); - pen.setWidth( outlineWidthPixels ); - painter.setPen( pen ); - - painter.drawRect( 0, 0, width()-1, height()-1 ); - } - - // - // Draw text - // - painter.setBrush( QBrush( Qt::NoBrush ) ); - - if ( isEnabled() && mHover ) - { - painter.setPen( QPen( palette().color( QPalette::HighlightedText ) ) ); - } - else - { - painter.setPen( QPen( palette().color( QPalette::Text ) ) ); - } - - QRect textRect( border, border, width()-2*border, hBox ); - - painter.drawText( textRect, Qt::AlignLeft|Qt::AlignVCenter, mText ); - } - - - /// - /// Enter Event - /// - void ColorPaletteButtonItem::enterEvent( QEvent* event ) - { - mHover = true; - update(); - } - - - /// - /// Leave Event - /// - void ColorPaletteButtonItem::leaveEvent( QEvent* event ) - { - mHover = false; - update(); - } - - - /// - /// Mouse Press Event - /// - void ColorPaletteButtonItem::mousePressEvent( QMouseEvent* event ) - { - emit activated(); - } - -} // namespace glabels diff --git a/glabels/ColorPaletteButtonItem.h b/glabels/ColorPaletteButtonItem.h deleted file mode 100644 index 0ffc627..0000000 --- a/glabels/ColorPaletteButtonItem.h +++ /dev/null @@ -1,75 +0,0 @@ -/* ColorPaletteButtonItem.h - * - * Copyright (C) 2014 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 ColorPaletteButtonItem_h -#define ColorPaletteButtonItem_h - - -#include -#include - - -namespace glabels -{ - - /// - /// Color Palette Item - /// - class ColorPaletteButtonItem : public QWidget - { - Q_OBJECT - - ///////////////////////////////// - // Life Cycle - ///////////////////////////////// - public: - ColorPaletteButtonItem( const QString& text, QWidget* parent = nullptr ); - - - ///////////////////////////////// - // Signals - ///////////////////////////////// - signals: - void activated(); - - - ///////////////////////////////// - // Event handlers - ///////////////////////////////// - protected: - void paintEvent( QPaintEvent* event ) override; - void enterEvent( QEvent* event ) override; - void leaveEvent( QEvent* event ) override; - void mousePressEvent( QMouseEvent* event ) override; - - - ///////////////////////////////// - // Private Data - ///////////////////////////////// - private: - QString mText; - - bool mHover; - }; - -} - - -#endif // ColorPaletteButtonItem_h diff --git a/glabels/ColorPaletteDialog.cpp b/glabels/ColorPaletteDialog.cpp index 71feb32..e11b4ad 100644 --- a/glabels/ColorPaletteDialog.cpp +++ b/glabels/ColorPaletteDialog.cpp @@ -18,14 +18,16 @@ * along with gLabels-qt. If not, see . */ + #include "ColorPaletteDialog.h" #include -#include -#include -#include #include +#include +#include +#include #include +#include #include @@ -99,14 +101,12 @@ namespace glabels vLayout->setContentsMargins( 0, 0, 0, 0 ); vLayout->setSpacing( 0 ); - auto* defaultButton = new ColorPaletteButtonItem( defaultLabel ); - connect( defaultButton, SIGNAL(activated()), this, SLOT(onDefaultItemActivated()) ); - vLayout->addWidget( defaultButton ); - - QFrame* hline1 = new QFrame; - hline1->setFrameStyle( QFrame::HLine | QFrame::Plain ); - hline1->setLineWidth( 1 ); - vLayout->addWidget( hline1 ); + // + // Construct Standard Colors Grid + // + auto* standardColorsGroup = new QGroupBox( tr("Standard Colors") ); + standardColorsGroup->setAlignment( Qt::AlignHCenter ); + vLayout->addWidget( standardColorsGroup ); auto* mainPaletteLayout = new QGridLayout(); mainPaletteLayout->setSpacing( 0 ); @@ -119,17 +119,20 @@ namespace glabels ColorPaletteItem* item = new ColorPaletteItem( i, QColor( mColorTable[i].colorSpec ), tr(mColorTable[i].trname) ); - connect( item, SIGNAL(activated(int)), this, SLOT(onPaletteItemActivated(int)) ); + connect( item, SIGNAL(activated(int)), + this, SLOT(onPaletteItemActivated(int)) ); mainPaletteLayout->addWidget( item, iRow, iCol ); } } - vLayout->addLayout( mainPaletteLayout ); + standardColorsGroup->setLayout( mainPaletteLayout ); - QFrame* hline2 = new QFrame; - hline2->setFrameStyle( QFrame::HLine | QFrame::Plain ); - hline2->setLineWidth( 1 ); - vLayout->addWidget( hline2 ); + // + // Construct Recent Colors Grid + // + auto* recentColorsGroup = new QGroupBox( tr("Recent Colors") ); + recentColorsGroup->setAlignment( Qt::AlignHCenter ); + vLayout->addWidget( recentColorsGroup ); auto* customPaletteLayout = new QHBoxLayout(); customPaletteLayout->setSpacing( 0 ); @@ -137,40 +140,42 @@ namespace glabels { mHistoryItem[iCol] = new ColorPaletteItem( iCol, QColor(0,0,0,0), "" ); mHistoryItem[iCol]->setEnabled( false ); - connect( mHistoryItem[iCol], SIGNAL(activated(int)), this, SLOT(onHistoryItemActivated(int)) ); + connect( mHistoryItem[iCol], SIGNAL(activated(int)), + this, SLOT(onHistoryItemActivated(int)) ); customPaletteLayout->addWidget( mHistoryItem[iCol] ); } - vLayout->addLayout( customPaletteLayout ); + recentColorsGroup->setLayout( customPaletteLayout ); - QFrame* hline3 = new QFrame; - hline3->setFrameStyle( QFrame::HLine | QFrame::Plain ); - hline3->setLineWidth( 1 ); - vLayout->addWidget( hline3 ); - - ColorPaletteButtonItem* customColorButton = new ColorPaletteButtonItem( tr("Custom color...") ); - connect( customColorButton, SIGNAL(activated()), this, SLOT(onCustomColorItemActivated()) ); + // + // Construct Default (e.g. "No Fill") Button + // + auto* defaultColorButton = new QPushButton( defaultLabel ); + defaultColorButton->setAutoDefault( false ); + defaultColorButton->setDefault( false ); + connect( defaultColorButton, SIGNAL(clicked()), this, SLOT(onDefaultButtonClicked()) ); + vLayout->addWidget( defaultColorButton ); + + // + // Construct Custom Color Button + // + auto* customColorButton = new QPushButton( tr("Custom color...") ); + customColorButton->setAutoDefault( false ); + customColorButton->setDefault( false ); + connect( customColorButton, SIGNAL(clicked()), this, SLOT(onCustomColorButtonClicked()) ); vLayout->addWidget( customColorButton ); - QFrame* hline4 = new QFrame; - hline4->setFrameStyle( QFrame::HLine | QFrame::Plain ); - hline4->setLineWidth( 1 ); - vLayout->addWidget( hline4 ); + // + // Construct "Use key" Button + // + mFieldButton = new FieldButton(); + mFieldButton->setText( tr("Use key") ); + mFieldButton->setAutoDefault( false ); + mFieldButton->setDefault( false ); + connect( mFieldButton, SIGNAL(keySelected(QString)), this, SLOT(onKeySelected(QString)) ); + vLayout->addWidget( mFieldButton ); - mMergeFieldCombo = new QComboBox(); - mMergeFieldCombo->addItem( tr("Merge key...") ); - mMergeFieldCombo->setMinimumSize( 34, 34 ); - mMergeFieldCombo->setFrame( false ); - mMergeFieldCombo->setEnabled( false ); - connect( mMergeFieldCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboIndexChanged(int)) ); - vLayout->addWidget( mMergeFieldCombo ); - - // Item 0 is the ComboBox title, not an item intended for selection. So disable it. - const auto* model = qobject_cast(mMergeFieldCombo->model()); - QStandardItem* item = model->item(0); - item->setFlags( item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) ); - setLayout( vLayout ); loadCustomColorHistory(); @@ -183,59 +188,29 @@ namespace glabels } - void ColorPaletteDialog::setKeys( const QStringList& keyList ) + void ColorPaletteDialog::setKeys( const merge::Merge* merge, + const model::Variables* variables ) { - mKeys = keyList; - - // Clear old keys, (all entries, except item 0) - for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- ) - { - mMergeFieldCombo->removeItem( index ); - } - - // Add new keys - if ( keyList.size() > 0 ) - { - mMergeFieldCombo->addItems( keyList ); - mMergeFieldCombo->setEnabled( true ); - } - else - { - mMergeFieldCombo->setEnabled( false ); - } - } - - - void ColorPaletteDialog::clearKeys() - { - - for ( int index = mMergeFieldCombo->count()-1; index > 0; index-- ) - { - mMergeFieldCombo->removeItem( index ); - } - mMergeFieldCombo->setEnabled( false ); - } - - - void ColorPaletteDialog::onDefaultItemActivated() - { - mColorNode.setField( false ); - mColorNode.setColor( mDefaultColor ); - mColorNode.setKey( "" ); - - emit colorChanged( mColorNode, true ); - accept(); + mFieldButton->setKeys( merge, variables ); } void ColorPaletteDialog::onPaletteItemActivated( int id ) { - mColorNode.setField( false ); - mColorNode.setColor( QColor( mColorTable[id].colorSpec ) ); - mColorNode.setKey( "" ); + model::ColorNode newColorNode; + newColorNode.setField( false ); + newColorNode.setColor( QColor( mColorTable[id].colorSpec ) ); + newColorNode.setKey( "" ); - emit colorChanged( mColorNode, false ); - accept(); + if ( newColorNode != mColorNode ) + { + mColorNode = newColorNode; + + mColorHistory->addColor( mColorNode.color() ); + + emit colorChanged( mColorNode, false ); + accept(); + } } @@ -250,7 +225,18 @@ namespace glabels } - void ColorPaletteDialog::onCustomColorItemActivated() + void ColorPaletteDialog::onDefaultButtonClicked() + { + mColorNode.setField( false ); + mColorNode.setColor( mDefaultColor ); + mColorNode.setKey( "" ); + + emit colorChanged( mColorNode, true ); + accept(); + } + + + void ColorPaletteDialog::onCustomColorButtonClicked() { QColorDialog dlg( mColorNode.color(), this ); dlg.setWindowTitle( tr("Custom Color") ); @@ -302,25 +288,14 @@ namespace glabels } - void ColorPaletteDialog::onComboIndexChanged( int index ) + void ColorPaletteDialog::onKeySelected( QString key ) { - if ( index != 0 ) - { - mColorNode.setField( true ); - mColorNode.setColor( QColor( 0xee, 0xee, 0xec ) ); - mColorNode.setKey( mKeys[index-1] ); + mColorNode.setField( true ); + mColorNode.setColor( QColor( 0xee, 0xee, 0xec ) ); + mColorNode.setKey( key ); - emit colorChanged( mColorNode, false ); - accept(); - } - } - - - void ColorPaletteDialog::showEvent( QShowEvent* event ) - { - mMergeFieldCombo->setCurrentIndex( 0 ); - - QDialog::showEvent( event ); + emit colorChanged( mColorNode, false ); + accept(); } } // namespace glabels diff --git a/glabels/ColorPaletteDialog.h b/glabels/ColorPaletteDialog.h index db5f7e1..518fd75 100644 --- a/glabels/ColorPaletteDialog.h +++ b/glabels/ColorPaletteDialog.h @@ -24,11 +24,10 @@ #include "ColorHistory.h" #include "ColorPaletteItem.h" -#include "ColorPaletteButtonItem.h" +#include "FieldButton.h" #include "model/ColorNode.h" -#include #include @@ -64,25 +63,23 @@ namespace glabels // Public Methods ///////////////////////////////// public: - void setColorNode( const model::ColorNode& colorNode ); - void setKeys( const QStringList& keyList ); - void clearKeys(); + void setColorNode( const model::ColorNode& colorNode ); + + void setKeys( const merge::Merge* merge, + const model::Variables* variables ); ///////////////////////////////// // Slots ///////////////////////////////// private slots: - void onDefaultItemActivated(); void onPaletteItemActivated( int id ); void onHistoryItemActivated( int id ); - void onCustomColorItemActivated(); + void onDefaultButtonClicked(); + void onCustomColorButtonClicked(); + void onKeySelected( QString key ); void onColorHistoryChanged(); - void onComboIndexChanged( int index ); - protected: - void showEvent( QShowEvent* event ) override; - ///////////////////////////////// // Private Methods @@ -111,8 +108,7 @@ namespace glabels ColorHistory* mColorHistory; ColorPaletteItem* mHistoryItem[PALETTE_COLS]; - QComboBox* mMergeFieldCombo; - QStringList mKeys; + FieldButton* mFieldButton; }; diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index dc480b5..f31415a 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -503,13 +503,12 @@ namespace glabels { if ( !mBlocked ) { - QStringList keys = mModel->merge()->keys(); - lineColorButton->setKeys( keys ); - fillColorButton->setKeys( keys ); + lineColorButton->setKeys( mModel->merge(), mModel->variables() ); + fillColorButton->setKeys( mModel->merge(), mModel->variables() ); textInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); barcodeInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); imageFieldButton->setKeys( mModel->merge(), mModel->variables() ); - shadowColorButton->setKeys( keys ); + shadowColorButton->setKeys( mModel->merge(), mModel->variables() ); } } diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 78a87d5..add9668 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1133,10 +1133,6 @@ Custom color... - - Merge key... - - Custom Color @@ -1145,6 +1141,18 @@ Custom color #%1 + + Use key + + + + Standard Colors + + + + Recent Colors + + glabels::FieldButton From cd0af020c66f86f397fceda9271abd14c2941804 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 21 Jul 2019 19:26:03 -0400 Subject: [PATCH 20/32] Added default cases to switch statements. --- model/Variable.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/model/Variable.cpp b/model/Variable.cpp index 1cdca5d..5156928 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -154,12 +154,14 @@ namespace glabels { switch (mType) { - case Type::STRING: - return mInitialValue; - case Type::INTEGER: - return QString::number( mIntegerValue ); - case Type::FLOATING_POINT: - return QString::number( mFloatingPointValue, 'g', 15 ); + case Type::STRING: + return mInitialValue; + case Type::INTEGER: + return QString::number( mIntegerValue ); + case Type::FLOATING_POINT: + return QString::number( mFloatingPointValue, 'g', 15 ); + default: + return mInitialValue; } } @@ -174,6 +176,8 @@ namespace glabels return tr("Integer"); case Type::FLOATING_POINT: return tr("Floating Point"); + default: + return tr("String"); } } @@ -188,6 +192,8 @@ namespace glabels return "integer"; case Type::FLOATING_POINT: return "float"; + default: + return "string"; } } @@ -225,6 +231,8 @@ namespace glabels return tr("Per copy"); case Increment::PER_PAGE: return tr("Per page"); + default: + return tr("Never"); } } @@ -241,6 +249,8 @@ namespace glabels return "per_copy"; case Increment::PER_PAGE: return "per_page"; + default: + return "never"; } } From f6ecdc64e0a21abbfae178df4b7530455d04aa46 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Wed, 24 Jul 2019 08:25:22 -0400 Subject: [PATCH 21/32] Redesigned ColorHistory to include color description. --- glabels/ColorHistory.cpp | 86 ++++++++++++++------------- glabels/ColorHistory.h | 8 +-- glabels/ColorPaletteDialog.cpp | 12 ++-- translations/glabels_C.ts | 105 +++++++++++++++------------------ 4 files changed, 106 insertions(+), 105 deletions(-) diff --git a/glabels/ColorHistory.cpp b/glabels/ColorHistory.cpp index 60ff08f..0175301 100644 --- a/glabels/ColorHistory.cpp +++ b/glabels/ColorHistory.cpp @@ -46,23 +46,25 @@ namespace glabels } - void ColorHistory::addColor( const QColor &color ) + void ColorHistory::addColor( const QColor &color, const QString& name ) { - QList colorList = readColorList(); + QString nameColor = name + ":" + color.name(); + + QStringList nameColorList = readNameColorList(); // Remove any occurrences of this color already in list - colorList.removeAll( color ); + nameColorList.removeAll( nameColor ); // Now add to list - colorList.append( color ); + nameColorList.append( nameColor ); // Remove oldest colors, if size exceeds current max - while ( colorList.size() > MAX_COLORS ) + while ( nameColorList.size() > MAX_COLORS ) { - colorList.removeFirst(); + nameColorList.removeFirst(); } - writeColorList( colorList ); + writeNameColorList( nameColorList ); emit changed(); } @@ -70,55 +72,57 @@ namespace glabels QList ColorHistory::getColors() { - return readColorList(); - } - - - QColor ColorHistory::getColor( int id ) - { - QList colors = readColorList(); - return colors[id]; - } - - - QList ColorHistory::readColorList() - { - QStringList defaultList; - QSettings settings; - - settings.beginGroup( "ColorHistory" ); - QStringList colorNameList = settings.value( "colors", defaultList ).toStringList(); - settings.endGroup(); - QList colorList; - foreach ( QString colorName, colorNameList ) + + for ( QString& nameColor : readNameColorList() ) { - colorList << QColor( colorName ); - } - - // Remove oldest colors, if size exceeds current max - while ( colorList.size() > MAX_COLORS ) - { - colorList.removeFirst(); + QStringList v = nameColor.split( ':' ); + colorList << QColor( v[1] ); } return colorList; } - void ColorHistory::writeColorList( const QList& colorList ) + QStringList ColorHistory::getNames() { - // Build name list - QStringList colorNameList; - foreach ( QColor color, colorList ) + QStringList nameList; + + for ( QString& nameColor : readNameColorList() ) { - colorNameList << color.name(); + QStringList v = nameColor.split( ':' ); + nameList << v[0]; } + return nameList; + } + + + QStringList ColorHistory::readNameColorList() + { + QStringList defaultList; + QSettings settings; + + settings.beginGroup( "ColorHistory" ); + QStringList nameColorList = settings.value( "colors", defaultList ).toStringList(); + settings.endGroup(); + + // Remove oldest colors, if size exceeds current max + while ( nameColorList.size() > MAX_COLORS ) + { + nameColorList.removeFirst(); + } + + return nameColorList; + } + + + void ColorHistory::writeNameColorList( const QStringList& nameColorList ) + { // Save QSettings settings; settings.beginGroup( "ColorHistory" ); - settings.setValue( "colors", colorNameList ); + settings.setValue( "colors", nameColorList ); settings.endGroup(); } diff --git a/glabels/ColorHistory.h b/glabels/ColorHistory.h index b74b3b4..eb14812 100644 --- a/glabels/ColorHistory.h +++ b/glabels/ColorHistory.h @@ -60,17 +60,17 @@ namespace glabels // Public Methods ///////////////////////////////// public: - void addColor( const QColor &color ); + void addColor( const QColor& color, const QString& name ); QList getColors(); - QColor getColor( int id ); + QStringList getNames(); ///////////////////////////////// // Private Methods ///////////////////////////////// private: - QList readColorList(); - void writeColorList( const QList& colorList ); + QStringList readNameColorList(); + void writeNameColorList( const QStringList& nameColorList ); ///////////////////////////////// diff --git a/glabels/ColorPaletteDialog.cpp b/glabels/ColorPaletteDialog.cpp index e11b4ad..3986fe4 100644 --- a/glabels/ColorPaletteDialog.cpp +++ b/glabels/ColorPaletteDialog.cpp @@ -206,7 +206,7 @@ namespace glabels { mColorNode = newColorNode; - mColorHistory->addColor( mColorNode.color() ); + mColorHistory->addColor( mColorNode.color(), mColorTable[id].trname ); emit colorChanged( mColorNode, false ); accept(); @@ -217,7 +217,7 @@ namespace glabels void ColorPaletteDialog::onHistoryItemActivated( int id ) { mColorNode.setField( false ); - mColorNode.setColor( mColorHistory->getColor(id) ); + mColorNode.setColor( mColorHistory->getColors()[id] ); mColorNode.setKey( "" ); emit colorChanged( mColorNode, false ); @@ -253,7 +253,10 @@ namespace glabels { mColorNode = newColorNode; - mColorHistory->addColor( mColorNode.color() ); + // TRANSLATORS + //: %1 = color specification in hex. String must not contain a colon (:). + mColorHistory->addColor( mColorNode.color(), + QString(tr("Custom Color %1")).arg(mColorNode.color().name()) ); emit colorChanged( mColorNode, false ); accept(); @@ -270,12 +273,13 @@ namespace glabels void ColorPaletteDialog::loadCustomColorHistory() { + QStringList nameList = mColorHistory->getNames(); QList colorList = mColorHistory->getColors(); int id = 0; foreach ( QColor color, colorList ) { - mHistoryItem[id]->setColor( id, color, QString(tr("Custom color #%1").arg(id+1) ) ); + mHistoryItem[id]->setColor( id, color, nameList[id] ); mHistoryItem[id]->setEnabled( true ); id++; } diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index add9668..666ef04 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -184,22 +184,22 @@ Dialog - - Name: - - - - Increment: - - Variable type: + + Name: + + Initial value: + + Increment: + + Step size: @@ -405,6 +405,10 @@ File + + Browse... + + Line/Fill @@ -481,10 +485,6 @@ Opacity: - - Browse... - - PreferencesDialog @@ -1056,18 +1056,6 @@ String - - Never - - - - Per copy - - - - Per page - - Integer @@ -1076,10 +1064,22 @@ Floating Point + + Never + + Per item + + Per copy + + + + Per page + + VariablesView @@ -1129,28 +1129,29 @@ glabels::ColorPaletteDialog + + Standard Colors + + + + Recent Colors + + Custom color... - - Custom Color - - - - Custom color #%1 - - Use key - Standard Colors + Custom Color - Recent Colors + Custom Color %1 + %1 = color specification in hex. String must not contain a colon (:). @@ -1768,7 +1769,11 @@ - Insert Field + Insert field + + + + Use field @@ -1907,18 +1912,6 @@ Shadow - - Selected File... - - - - Insert field - - - - Use field - - glabels::PrintView @@ -2148,14 +2141,6 @@ Variables - - Add Variable - - - - Edit Variable - - Name @@ -2164,6 +2149,10 @@ Type + + Initial Value + + Increment @@ -2173,7 +2162,11 @@ - Initial Value + Add Variable + + + + Edit Variable From 57cbf18039afcefc0ae4ba03767a38fbf3bf67fe Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 27 Jul 2019 22:00:05 -0400 Subject: [PATCH 22/32] Added variables expansion to TextNode and ColorNode. --- model/ColorNode.cpp | 40 ++++++++++++++------------ model/ColorNode.h | 4 ++- model/ModelBarcodeObject.cpp | 2 +- model/ModelBoxObject.cpp | 10 +++---- model/ModelEllipseObject.cpp | 10 +++---- model/ModelImageObject.cpp | 2 +- model/ModelLineObject.cpp | 6 ++-- model/ModelTextObject.cpp | 6 ++-- model/TextNode.cpp | 56 ++++++++++++++---------------------- model/TextNode.h | 5 ++-- model/XmlLabelParser.cpp | 24 ++++++++-------- 11 files changed, 78 insertions(+), 87 deletions(-) diff --git a/model/ColorNode.cpp b/model/ColorNode.cpp index f399a1a..ceee003 100644 --- a/model/ColorNode.cpp +++ b/model/ColorNode.cpp @@ -175,30 +175,32 @@ namespace glabels /// /// Get color, expand if necessary /// - QColor ColorNode::color( merge::Record* record ) const + QColor ColorNode::color( const merge::Record* record, + const Variables* variables ) const { - if ( mIsField ) + QColor value = QColor( 192, 192, 192, 128 ); + + bool haveRecordField = mIsField && record && + record->contains(mKey) && + !record->value(mKey).isEmpty(); + bool haveVariable = mIsField && variables && + variables->contains(mKey) && + !(*variables)[mKey].value().isEmpty(); + + if ( haveRecordField ) { - if ( record == nullptr ) - { - return mColor; - } - else - { - if ( record->contains( mKey ) ) - { - return QColor( (*record)[ mKey ] ); - } - else - { - return mColor; - } - } + value = QColor( record->value(mKey) ); } - else + else if ( haveVariable ) { - return mColor; + value = QColor( (*variables)[mKey].value() ); } + else if ( !mIsField ) + { + value = mColor; + } + + return value; } } diff --git a/model/ColorNode.h b/model/ColorNode.h index 89b0201..dab30af 100644 --- a/model/ColorNode.h +++ b/model/ColorNode.h @@ -22,6 +22,7 @@ #define model_ColorNode_h +#include "Variables.h" #include "merge/Record.h" #include @@ -95,7 +96,8 @@ namespace glabels ///////////////////////////////// public: uint32_t rgba() const; - QColor color( merge::Record* record ) const; + QColor color( const merge::Record* record, + const Variables* variables ) const; ///////////////////////////////// diff --git a/model/ModelBarcodeObject.cpp b/model/ModelBarcodeObject.cpp index 3b65e10..9a1daa4 100644 --- a/model/ModelBarcodeObject.cpp +++ b/model/ModelBarcodeObject.cpp @@ -326,7 +326,7 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor bcColor = mBcColorNode.color( record ); + QColor bcColor = mBcColorNode.color( record, variables ); if ( inEditor ) { diff --git a/model/ModelBoxObject.cpp b/model/ModelBoxObject.cpp index 24a61c6..701574a 100644 --- a/model/ModelBoxObject.cpp +++ b/model/ModelBoxObject.cpp @@ -108,9 +108,9 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor fillColor = mFillColorNode.color( record ); - QColor shadowColor = mShadowColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor fillColor = mFillColorNode.color( record, variables ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); @@ -156,8 +156,8 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor fillColor = mFillColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor fillColor = mFillColorNode.color( record, variables ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->setBrush( fillColor ); diff --git a/model/ModelEllipseObject.cpp b/model/ModelEllipseObject.cpp index e9e58fd..85591e9 100644 --- a/model/ModelEllipseObject.cpp +++ b/model/ModelEllipseObject.cpp @@ -108,9 +108,9 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor fillColor = mFillColorNode.color( record ); - QColor shadowColor = mShadowColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor fillColor = mFillColorNode.color( record, variables ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); @@ -156,8 +156,8 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor fillColor = mFillColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor fillColor = mFillColorNode.color( record, variables ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->setBrush( fillColor ); diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp index 9c30a42..9758a8d 100644 --- a/model/ModelImageObject.cpp +++ b/model/ModelImageObject.cpp @@ -413,7 +413,7 @@ namespace glabels { QRectF destRect( 0, 0, mW.pt(), mH.pt() ); - QColor shadowColor = mShadowColorNode.color( record ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) ) diff --git a/model/ModelLineObject.cpp b/model/ModelLineObject.cpp index 9223f91..44946a0 100644 --- a/model/ModelLineObject.cpp +++ b/model/ModelLineObject.cpp @@ -191,8 +191,8 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); - QColor shadowColor = mShadowColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); @@ -212,7 +212,7 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor lineColor = mLineColorNode.color( record ); + QColor lineColor = mLineColorNode.color( record, variables ); painter->setPen( QPen( lineColor, mLineWidth.pt() ) ); painter->drawLine( 0, 0, mW.pt(), mH.pt() ); diff --git a/model/ModelTextObject.cpp b/model/ModelTextObject.cpp index 45c259e..1d24f30 100644 --- a/model/ModelTextObject.cpp +++ b/model/ModelTextObject.cpp @@ -521,11 +521,11 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor textColor = mTextColorNode.color( record ); + QColor textColor = mTextColorNode.color( record, variables ); if ( textColor.alpha() ) { - QColor shadowColor = mShadowColorNode.color( record ); + QColor shadowColor = mShadowColorNode.color( record, variables ); shadowColor.setAlphaF( mShadowOpacity ); if ( inEditor ) @@ -548,7 +548,7 @@ namespace glabels merge::Record* record, Variables* variables ) const { - QColor textColor = mTextColorNode.color( record ); + QColor textColor = mTextColorNode.color( record, variables ); if ( inEditor ) { diff --git a/model/TextNode.cpp b/model/TextNode.cpp index 332367e..b0e2271 100644 --- a/model/TextNode.cpp +++ b/model/TextNode.cpp @@ -105,48 +105,34 @@ namespace glabels /// /// Get text, expand if necessary /// - QString TextNode::text( merge::Record* record ) const + QString TextNode::text( const merge::Record* record, + const Variables* variables ) const { - if ( mIsField ) + QString value(""); + + bool haveRecordField = mIsField && record && + record->contains(mData) && + !record->value(mData).isEmpty(); + bool haveVariable = mIsField && variables && + variables->contains(mData) && + !(*variables)[mData].value().isEmpty(); + + if ( haveRecordField ) { - if ( !record ) - { - return QString("${%1}").arg( mData ); - } - else - { - if ( record->contains( mData ) ) - { - return (*record)[ mData ]; - } - else - { - return ""; - } - } + value = record->value(mData); } - else + else if ( haveVariable ) { - return mData; + value = (*variables)[mData].value(); } + else if ( !mIsField ) + { + value = mData; + } + + return value; } - /// - /// Is it an empty field - /// - bool TextNode::isEmptyField( merge::Record* record ) const - { - if ( record && mIsField ) - { - if ( record->contains( mData ) ) - { - return (*record)[mData].isEmpty(); - } - } - - return false; - } - } } diff --git a/model/TextNode.h b/model/TextNode.h index 499f863..c7716d7 100644 --- a/model/TextNode.h +++ b/model/TextNode.h @@ -22,6 +22,7 @@ #define model_TextNode_h +#include "Variables.h" #include "merge/Record.h" #include @@ -76,8 +77,8 @@ namespace glabels ///////////////////////////////// // Misc. Methods ///////////////////////////////// - QString text( merge::Record* record ) const; - bool isEmptyField( merge::Record* record ) const; + QString text( const merge::Record* record, + const Variables* variables ) const; ///////////////////////////////// diff --git a/model/XmlLabelParser.cpp b/model/XmlLabelParser.cpp index 07fd543..ed9bdb9 100644 --- a/model/XmlLabelParser.cpp +++ b/model/XmlLabelParser.cpp @@ -364,13 +364,13 @@ namespace glabels QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0xFF ); ColorNode lineColorNode( field_flag, color, key ); /* fill attrs */ key = XmlUtil::getStringAttr( node, "fill_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "fill_color", 0 ); + color = XmlUtil::getUIntAttr( node, "fill_color", 0xFF ); ColorNode fillColorNode( field_flag, color, key ); /* affine attrs */ @@ -390,7 +390,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); return new ModelBoxObject( x0, y0, w, h, @@ -417,13 +417,13 @@ namespace glabels QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0xFF ); ColorNode lineColorNode( field_flag, color, key ); /* fill attrs */ key = XmlUtil::getStringAttr( node, "fill_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "fill_color", 0 ); + color = XmlUtil::getUIntAttr( node, "fill_color", 0xFF ); ColorNode fillColorNode( field_flag, color, key ); /* affine attrs */ @@ -443,7 +443,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); return new ModelEllipseObject( x0, y0, w, h, @@ -470,7 +470,7 @@ namespace glabels QString key = XmlUtil::getStringAttr( node, "line_color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "line_color", 0xFF ); ColorNode lineColorNode( field_flag, color, key ); /* affine attrs */ @@ -490,7 +490,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); return new ModelLineObject( x0, y0, dx, dy, @@ -534,7 +534,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); if ( filenameNode.isField() ) @@ -591,7 +591,7 @@ namespace glabels QString key = XmlUtil::getStringAttr( node, "color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "color", 0xFF ); ColorNode bcColorNode( field_flag, color, key ); QString bcData = XmlUtil::getStringAttr( node, "data", "" ); @@ -625,7 +625,7 @@ namespace glabels /* color attr */ QString key = XmlUtil::getStringAttr( node, "color_field", "" ); bool field_flag = !key.isEmpty(); - uint32_t color = XmlUtil::getUIntAttr( node, "color", 0 ); + uint32_t color = XmlUtil::getUIntAttr( node, "color", 0xFF ); ColorNode textColorNode( field_flag, color, key ); /* font attrs */ @@ -659,7 +659,7 @@ namespace glabels key = XmlUtil::getStringAttr( node, "shadow_color_field", "" ); field_flag = !key.isEmpty(); - color = XmlUtil::getUIntAttr( node, "shadow_color", 0 ); + color = XmlUtil::getUIntAttr( node, "shadow_color", 0xFF ); ColorNode shadowColorNode( field_flag, color, key ); /* deserialize contents. */ From 6fda0246a85928ac16c158e4f7b992fc9bd782f0 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Tue, 30 Jul 2019 21:26:16 -0400 Subject: [PATCH 23/32] Implement fields in ModelImageObject. --- model/ModelImageObject.cpp | 31 ++++++++++++++++++++++++++----- model/ModelImageObject.h | 4 +++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp index 9758a8d..5124995 100644 --- a/model/ModelImageObject.cpp +++ b/model/ModelImageObject.cpp @@ -418,19 +418,34 @@ namespace glabels if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) ) { - QImage* shadowImage = createShadowImage( shadowColor ); + QImage* shadowImage = createShadowImage( *mImage, shadowColor ); painter->drawImage( destRect, *shadowImage ); delete shadowImage; } + else if ( mImage || inEditor ) + { + painter->setBrush( shadowColor ); + painter->setPen( QPen( Qt::NoPen ) ); + + painter->drawRect( destRect ); + } else { - if ( mImage || inEditor ) + auto* image = new QImage( mFilenameNode.text( record, variables ) ); + if ( !image->isNull() && image->hasAlphaChannel() && (image->depth() == 32) ) + { + QImage* shadowImage = createShadowImage( *image, shadowColor ); + painter->drawImage( destRect, *shadowImage ); + delete shadowImage; + } + else if ( !image->isNull() ) { painter->setBrush( shadowColor ); painter->setPen( QPen( Qt::NoPen ) ); painter->drawRect( destRect ); } + delete image; } } @@ -513,7 +528,12 @@ namespace glabels } else if ( mFilenameNode.isField() ) { - // TODO + auto* image = new QImage( mFilenameNode.text( record, variables ) ); + if ( !image->isNull() ) + { + painter->drawImage( destRect, *image ); + } + delete image; } } @@ -612,14 +632,15 @@ namespace glabels /// /// Create shadow image /// - QImage* ModelImageObject::createShadowImage( const QColor& color ) const + QImage* ModelImageObject::createShadowImage( const QImage& image, + const QColor& color ) const { int r = color.red(); int g = color.green(); int b = color.blue(); int a = color.alpha(); - auto* shadow = new QImage( *mImage ); + auto* shadow = new QImage( image ); for ( int iy = 0; iy < shadow->height(); iy++ ) { auto* scanLine = (QRgb*)shadow->scanLine( iy ); diff --git a/model/ModelImageObject.h b/model/ModelImageObject.h index d1c62a0..70a605f 100644 --- a/model/ModelImageObject.h +++ b/model/ModelImageObject.h @@ -149,7 +149,9 @@ namespace glabels // Private /////////////////////////////////////////////////////////////// void loadImage(); - QImage* createShadowImage( const QColor& color ) const; + + QImage* createShadowImage( const QImage& image, + const QColor& color ) const; /////////////////////////////////////////////////////////////// From 2c1c865f539698a176da40d6c71e85e4c07139ae Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 3 Aug 2019 13:44:05 -0400 Subject: [PATCH 24/32] Update .gitignore. --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index cfadfca..c73579d 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,6 @@ core *.sav* .directory TEST-DATA +SAV* +OLD* + From 48bfb68837b643fc346667d602868e6116e38201 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 3 Aug 2019 14:10:01 -0400 Subject: [PATCH 25/32] Make ColorHistory more robust to change in format. --- glabels/ColorHistory.cpp | 30 ++++++++++++++++++++++++++++-- translations/glabels_C.ts | 19 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/glabels/ColorHistory.cpp b/glabels/ColorHistory.cpp index 0175301..ba564de 100644 --- a/glabels/ColorHistory.cpp +++ b/glabels/ColorHistory.cpp @@ -77,7 +77,20 @@ namespace glabels for ( QString& nameColor : readNameColorList() ) { QStringList v = nameColor.split( ':' ); - colorList << QColor( v[1] ); + if ( v.size() == 2 ) + { + colorList << QColor( v[1] ); + } + else if ( v.size() == 1 ) + { + // Old-style, no name + colorList << QColor( v[0] ); + } + else + { + // Should not happen + qWarning() << "Invalid color history."; + } } return colorList; @@ -91,7 +104,20 @@ namespace glabels for ( QString& nameColor : readNameColorList() ) { QStringList v = nameColor.split( ':' ); - nameList << v[0]; + if ( v.size() == 2 ) + { + nameList << v[0]; + } + else if ( v.size() == 1 ) + { + // Old-style, no name + nameList << QString(tr("color %1")).arg( v[0] ); + } + else + { + // Should not happen + qWarning() << "Invalid color history."; + } } return nameList; diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 666ef04..10ece40 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1127,6 +1127,13 @@ + + glabels::ColorHistory + + color %1 + + + glabels::ColorPaletteDialog @@ -1154,6 +1161,10 @@ %1 = color specification in hex. String must not contain a colon (:). + + Custom color #%1 + + glabels::FieldButton @@ -1912,6 +1923,14 @@ Shadow + + Insert Field + + + + Selected File... + + glabels::PrintView From dd41aa3dd75c062636b4da380b6b4b174ff26d3b Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 3 Aug 2019 15:31:57 -0400 Subject: [PATCH 26/32] Minor tweaking of EditVariablesDialog. --- glabels/EditVariableDialog.cpp | 17 +--- glabels/VariablesView.cpp | 2 +- glabels/ui/EditVariableDialog.ui | 136 +++++++++++++++++-------------- translations/glabels_C.ts | 28 ++++--- 4 files changed, 95 insertions(+), 88 deletions(-) diff --git a/glabels/EditVariableDialog.cpp b/glabels/EditVariableDialog.cpp index 4a1135e..9893da4 100644 --- a/glabels/EditVariableDialog.cpp +++ b/glabels/EditVariableDialog.cpp @@ -67,6 +67,8 @@ namespace glabels { incrementCombo->addItem( model::Variable::incrementToI18nString( type ) ); } + + stepSizeEdit->setText( "1" ); } @@ -157,28 +159,16 @@ namespace glabels case model::Variable::Type::INTEGER: valueEdit->setValidator( new QIntValidator() ); stepSizeEdit->setValidator( new QIntValidator() ); - - if ( increment == model::Variable::Increment::NEVER ) - { - stepSizeEdit->setText( "0" ); - } break; case model::Variable::Type::FLOATING_POINT: valueEdit->setValidator( new QDoubleValidator() ); stepSizeEdit->setValidator( new QDoubleValidator() ); - - if ( increment == model::Variable::Increment::NEVER ) - { - stepSizeEdit->setText( "0" ); - } break; default: valueEdit->setValidator( nullptr ); stepSizeEdit->setValidator( nullptr ); - incrementCombo->setCurrentIndex( static_cast(model::Variable::Increment::NEVER) ); - stepSizeEdit->setText( "" ); break; } @@ -186,8 +176,7 @@ namespace glabels bool isNumeric = ( type == model::Variable::Type::INTEGER ) || ( type == model::Variable::Type::FLOATING_POINT ); - incrementLabel->setEnabled( isNumeric ); - incrementCombo->setEnabled( isNumeric ); + incrementGroup->setVisible( isNumeric ); stepSizeLabel->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) ); stepSizeEdit->setEnabled( isNumeric && (increment != model::Variable::Increment::NEVER) ); diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index 9487085..339d901 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -126,7 +126,7 @@ namespace glabels "x", "0", model::Variable::Increment::NEVER, - "0" ); + "1" ); dialog.setVariable( v ); dialog.setWindowTitle( tr("Add Variable") ); diff --git a/glabels/ui/EditVariableDialog.ui b/glabels/ui/EditVariableDialog.ui index af81a20..77b5e93 100644 --- a/glabels/ui/EditVariableDialog.ui +++ b/glabels/ui/EditVariableDialog.ui @@ -6,73 +6,44 @@ 0 0 - 471 - 237 + 469 + 297 Dialog - - - - - - Variable type: - - - - - - - - - - Name: - - - - - - - - - - Initial value: - - - - - - - - - - Increment: - - - - - - - - - - - - Step size: - - - - - - - - - + + 12 + + + + + Increment + + + + + + + + + + + Step size: + + + + + + + + + + - + Qt::Vertical @@ -85,7 +56,50 @@ - + + + + Variable + + + + + + + + + + + Type: + + + + + + + + + + Value: + + + + + + + Name: + + + + + + + + + + + + Qt::Horizontal diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 10ece40..a81f287 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -184,26 +184,30 @@ Dialog - - Variable type: - - Name: - - Initial value: - - - - Increment: - - Step size: + + Increment + + + + Variable + + + + Type: + + + + Value: + + Factory From f41461ef261d964e378d6d9a9d3cbb42496a371a Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 3 Aug 2019 17:16:14 -0400 Subject: [PATCH 27/32] Added color variable type. --- glabels/ColorButton.cpp | 10 ++- glabels/ColorButton.h | 6 +- glabels/ColorPaletteDialog.cpp | 27 +++++--- glabels/ColorPaletteDialog.h | 1 + glabels/EditVariableDialog.cpp | 21 +++++- glabels/EditVariableDialog.h | 1 + glabels/ObjectEditor.cpp | 6 +- glabels/VariablesView.cpp | 2 +- glabels/ui/EditVariableDialog.ui | 114 ++++++++++++++++++++----------- glabels/ui/ObjectEditor.ui | 99 ++++++++++++++++----------- model/Variable.cpp | 22 ++++++ model/Variable.h | 3 +- translations/glabels_C.ts | 43 ++++++++---- 13 files changed, 248 insertions(+), 107 deletions(-) diff --git a/glabels/ColorButton.cpp b/glabels/ColorButton.cpp index 9789628..28ea4c8 100644 --- a/glabels/ColorButton.cpp +++ b/glabels/ColorButton.cpp @@ -48,8 +48,9 @@ namespace glabels void ColorButton::init( const QString& defaultLabel, - const QColor& defaultColor, - const QColor& color ) + const QColor& defaultColor, + const QColor& color, + bool showUseFieldButton ) { mDefaultColor = defaultColor; mColorNode = model::ColorNode( color ); @@ -61,7 +62,10 @@ namespace glabels setText( "" ); setCheckable( true ); - mDialog = new ColorPaletteDialog( defaultLabel, defaultColor, color ); + mDialog = new ColorPaletteDialog( defaultLabel, + defaultColor, + color, + showUseFieldButton ); connect( this, SIGNAL(toggled(bool)), this, SLOT(onButtonToggled(bool)) ); connect( mDialog, SIGNAL(colorChanged(model::ColorNode,bool)), diff --git a/glabels/ColorButton.h b/glabels/ColorButton.h index a7155d8..81ba63d 100644 --- a/glabels/ColorButton.h +++ b/glabels/ColorButton.h @@ -58,7 +58,11 @@ namespace glabels // Public Methods ///////////////////////////////// public: - void init( const QString& defaultLabel, const QColor& defaultColor, const QColor& color ); + void init( const QString& defaultLabel, + const QColor& defaultColor, + const QColor& color, + bool showUseFieldButton = true ); + void setColorNode( model::ColorNode colorNode ); void setColor( QColor color ); void setToDefault(); diff --git a/glabels/ColorPaletteDialog.cpp b/glabels/ColorPaletteDialog.cpp index 3986fe4..9ad496a 100644 --- a/glabels/ColorPaletteDialog.cpp +++ b/glabels/ColorPaletteDialog.cpp @@ -85,6 +85,7 @@ namespace glabels ColorPaletteDialog::ColorPaletteDialog( const QString& defaultLabel, const QColor& defaultColor, const QColor& color, + bool showUseFieldButton, QWidget* parent ) : QDialog( parent ) { @@ -167,14 +168,21 @@ namespace glabels vLayout->addWidget( customColorButton ); // - // Construct "Use key" Button + // Construct "Use field" Button // - mFieldButton = new FieldButton(); - mFieldButton->setText( tr("Use key") ); - mFieldButton->setAutoDefault( false ); - mFieldButton->setDefault( false ); - connect( mFieldButton, SIGNAL(keySelected(QString)), this, SLOT(onKeySelected(QString)) ); - vLayout->addWidget( mFieldButton ); + if ( showUseFieldButton ) + { + mFieldButton = new FieldButton(); + mFieldButton->setText( tr("Use substitution field") ); + mFieldButton->setAutoDefault( false ); + mFieldButton->setDefault( false ); + connect( mFieldButton, SIGNAL(keySelected(QString)), this, SLOT(onKeySelected(QString)) ); + vLayout->addWidget( mFieldButton ); + } + else + { + mFieldButton = nullptr; + } setLayout( vLayout ); @@ -191,7 +199,10 @@ namespace glabels void ColorPaletteDialog::setKeys( const merge::Merge* merge, const model::Variables* variables ) { - mFieldButton->setKeys( merge, variables ); + if (mFieldButton) + { + mFieldButton->setKeys( merge, variables ); + } } diff --git a/glabels/ColorPaletteDialog.h b/glabels/ColorPaletteDialog.h index 518fd75..6e1a22c 100644 --- a/glabels/ColorPaletteDialog.h +++ b/glabels/ColorPaletteDialog.h @@ -49,6 +49,7 @@ namespace glabels ColorPaletteDialog( const QString& defaultLabel, const QColor& defaultColor, const QColor& color, + bool showUseFieldButton = true, QWidget* parent = nullptr ); diff --git a/glabels/EditVariableDialog.cpp b/glabels/EditVariableDialog.cpp index 9893da4..a685e73 100644 --- a/glabels/EditVariableDialog.cpp +++ b/glabels/EditVariableDialog.cpp @@ -31,7 +31,8 @@ namespace const QVector allTypes = { glabels::model::Variable::Type::STRING, glabels::model::Variable::Type::INTEGER, - glabels::model::Variable::Type::FLOATING_POINT + glabels::model::Variable::Type::FLOATING_POINT, + glabels::model::Variable::Type::COLOR }; // All variable increments. (must be in sorted order) @@ -58,6 +59,11 @@ namespace glabels QRegularExpression reIdentifier( "[a-zA-Z_][a-zA-Z_0-9]*" ); nameEdit->setValidator( new QRegularExpressionValidator( reIdentifier ) ); + colorValueButton->init( tr("Default"), + QColor(0,0,0,255), + QColor(0,0,0,255), + false ); + for ( auto type : allTypes ) { typeCombo->addItem( model::Variable::typeToI18nString( type ) ); @@ -80,6 +86,7 @@ namespace glabels typeCombo->setCurrentIndex( static_cast(variable.type()) ); nameEdit->setText( variable.name() ); valueEdit->setText( variable.initialValue() ); + colorValueButton->setColor( QColor( variable.initialValue() ) ); incrementCombo->setCurrentIndex( static_cast(variable.increment()) ); stepSizeEdit->setText( variable.stepSize() ); @@ -127,6 +134,16 @@ namespace glabels } + /// + /// colorValueButton Changed + /// + void EditVariableDialog::onColorValueButtonChanged() + { + valueEdit->setText( colorValueButton->colorNode().color().name() ); + validateCurrentInputs(); + } + + /// /// incrementCombo Changed /// @@ -173,6 +190,8 @@ namespace glabels } + colorValueButton->setVisible( type == model::Variable::Type::COLOR ); + bool isNumeric = ( type == model::Variable::Type::INTEGER ) || ( type == model::Variable::Type::FLOATING_POINT ); diff --git a/glabels/EditVariableDialog.h b/glabels/EditVariableDialog.h index 8c57a20..6c71d61 100644 --- a/glabels/EditVariableDialog.h +++ b/glabels/EditVariableDialog.h @@ -57,6 +57,7 @@ namespace glabels void onNameEditChanged(); void onTypeComboChanged(); void onValueEditChanged(); + void onColorValueButtonChanged(); void onIncrementComboChanged(); void onStepSizeEditChanged(); diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index f31415a..5f9b42d 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -67,9 +67,9 @@ namespace glabels barcodeColorButton->init( tr("Default"), QColor(0,0,0,255), QColor(0,0,0,255) ); shadowColorButton->init( tr("Default"), QColor(0,0,0,255), QColor(0,0,0,255) ); - textInsertFieldButton->setText( tr("Insert field") ); - barcodeInsertFieldButton->setText( tr("Insert field") ); - imageFieldButton->setText( tr("Use field") ); + textInsertFieldButton->setText( tr("Insert substitution field") ); + barcodeInsertFieldButton->setText( tr("Insert subsitution field") ); + imageFieldButton->setText( tr("Use substitution field") ); setEnabled( false ); hidePages(); diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp index 339d901..ea13f33 100644 --- a/glabels/VariablesView.cpp +++ b/glabels/VariablesView.cpp @@ -63,7 +63,7 @@ namespace glabels typeHeaderItem->setFlags( typeHeaderItem->flags() ^ Qt::ItemIsEditable ); table->setHorizontalHeaderItem( I_COL_TYPE, typeHeaderItem ); - auto* valueHeaderItem = new QTableWidgetItem( tr("Initial Value") ); + auto* valueHeaderItem = new QTableWidgetItem( tr("Value") ); valueHeaderItem->setFlags( valueHeaderItem->flags() ^ Qt::ItemIsEditable ); table->setHorizontalHeaderItem( I_COL_VALUE, valueHeaderItem ); diff --git a/glabels/ui/EditVariableDialog.ui b/glabels/ui/EditVariableDialog.ui index 77b5e93..72f8575 100644 --- a/glabels/ui/EditVariableDialog.ui +++ b/glabels/ui/EditVariableDialog.ui @@ -67,16 +67,6 @@ - - - - Type: - - - - - - @@ -94,6 +84,27 @@ + + + + Type: + + + + + + + + + + + + + + + + +
@@ -111,6 +122,16 @@
+ + + glabels::ColorButton + QPushButton +
ColorButton.h
+ + colorChanged() + +
+
@@ -120,8 +141,8 @@ accept() - 227 - 214 + 236 + 287 157 @@ -136,8 +157,8 @@ reject() - 295 - 220 + 304 + 287 286 @@ -152,8 +173,8 @@ onTypeComboChanged() - 179 - 30 + 252 + 70 33 @@ -161,22 +182,6 @@ - - valueEdit - textChanged(QString) - EditVariableDialog - onValueEditChanged() - - - 212 - 86 - - - 63 - 166 - - - incrementCombo currentIndexChanged(int) @@ -184,8 +189,8 @@ onIncrementComboChanged() - 170 - 123 + 100 + 223 97 @@ -200,8 +205,8 @@ onStepSizeEditChanged() - 344 - 125 + 440 + 223 333 @@ -216,8 +221,8 @@ onNameEditChanged() - 371 - 62 + 440 + 103 393 @@ -225,6 +230,38 @@ + + valueEdit + textChanged(QString) + EditVariableDialog + onValueEditChanged() + + + 318 + 129 + + + 459 + 157 + + + + + colorValueButton + colorChanged() + EditVariableDialog + onColorValueButtonChanged() + + + 406 + 114 + + + 458 + 122 + + + onTypeComboChanged() @@ -232,5 +269,6 @@ onIncrementComboChanged() onStepSizeEditChanged() onNameEditChanged() + onColorValueButtonChanged() diff --git a/glabels/ui/ObjectEditor.ui b/glabels/ui/ObjectEditor.ui index e46be75..bcfa051 100644 --- a/glabels/ui/ObjectEditor.ui +++ b/glabels/ui/ObjectEditor.ui @@ -786,46 +786,67 @@ - - - - 0 - 0 - - - - - 231 - 0 - - - - true - - - None - - + + + + + + 0 + 0 + + + + + 231 + 0 + + + + true + + + None + + + + + + + + 0 + 0 + + + + Browse... + + + + - - - - - 0 - 0 - - - - Browse... - - - - - - - Use field - - + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Use field + + + + diff --git a/model/Variable.cpp b/model/Variable.cpp index 5156928..fc52e14 100644 --- a/model/Variable.cpp +++ b/model/Variable.cpp @@ -86,6 +86,9 @@ namespace glabels mFloatingPointValue = mInitialValue.toDouble(); mFloatingPointStep = mStepSize.toDouble(); break; + case Type::COLOR: + // do nothing + break; } } @@ -105,6 +108,9 @@ namespace glabels case Type::FLOATING_POINT: mFloatingPointValue += mFloatingPointStep; break; + case Type::COLOR: + // do nothing + break; } } } @@ -125,6 +131,9 @@ namespace glabels case Type::FLOATING_POINT: mFloatingPointValue += mFloatingPointStep; break; + case Type::COLOR: + // do nothing + break; } } } @@ -145,6 +154,9 @@ namespace glabels case Type::FLOATING_POINT: mFloatingPointValue += mFloatingPointStep; break; + case Type::COLOR: + // do nothing + break; } } } @@ -160,6 +172,8 @@ namespace glabels return QString::number( mIntegerValue ); case Type::FLOATING_POINT: return QString::number( mFloatingPointValue, 'g', 15 ); + case Type::COLOR: + return mInitialValue; default: return mInitialValue; } @@ -176,6 +190,8 @@ namespace glabels return tr("Integer"); case Type::FLOATING_POINT: return tr("Floating Point"); + case Type::COLOR: + return tr("Color"); default: return tr("String"); } @@ -192,6 +208,8 @@ namespace glabels return "integer"; case Type::FLOATING_POINT: return "float"; + case Type::COLOR: + return "color"; default: return "string"; } @@ -212,6 +230,10 @@ namespace glabels { return Type::FLOATING_POINT; } + if ( id == "color" ) + { + return Type::COLOR; + } else { return Type::STRING; // Default diff --git a/model/Variable.h b/model/Variable.h index 95f3dec..3dfad13 100644 --- a/model/Variable.h +++ b/model/Variable.h @@ -40,7 +40,8 @@ namespace glabels { STRING, INTEGER, - FLOATING_POINT + FLOATING_POINT, + COLOR }; enum class Increment diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index a81f287..426a73d 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1084,6 +1084,10 @@ Per page + + Color + + VariablesView @@ -1169,6 +1173,17 @@ Custom color #%1 + + Use substitution field + + + + + glabels::EditVariableDialog + + Default + + glabels::FieldButton @@ -1783,14 +1798,6 @@ Default - - Insert field - - - - Use field - - Original size @@ -1935,6 +1942,18 @@ Selected File... + + Insert substitution field + + + + Insert subsitution field + + + + Use substitution field + + glabels::PrintView @@ -2172,10 +2191,6 @@ Type - - Initial Value - - Increment @@ -2192,6 +2207,10 @@ Edit Variable + + Value + + glabels::barcode::Backends From 3fedb16c2cec2174a9f48dad2ff448adfd2cc79e Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 4 Aug 2019 23:32:50 -0400 Subject: [PATCH 28/32] Look for image files from substitution fields relative to project file. --- model/Model.cpp | 17 +++++++++++++++++ model/Model.h | 1 + model/ModelImageObject.cpp | 16 ++++++++++++++-- model/ModelObject.h | 2 +- model/XmlLabelCreator.cpp | 14 ++++++++++++-- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/model/Model.cpp b/model/Model.cpp index 4fe8b34..07801b2 100644 --- a/model/Model.cpp +++ b/model/Model.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -280,6 +281,22 @@ namespace glabels } + /// + /// Get directory. + /// + QString Model::dir() const + { + if ( mFileName.isEmpty() ) + { + return QDir::currentPath(); + } + else + { + return QFileInfo( mFileName ).absolutePath(); + } + } + + /// /// Get short name. /// diff --git a/model/Model.h b/model/Model.h index cfd74c8..b1c5b33 100644 --- a/model/Model.h +++ b/model/Model.h @@ -91,6 +91,7 @@ namespace glabels void setModified(); void clearModified(); + QString dir() const; QString shortName(); const QString& fileName() const; void setFileName( const QString &fileName ); diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp index 5124995..550de8c 100644 --- a/model/ModelImageObject.cpp +++ b/model/ModelImageObject.cpp @@ -20,9 +20,11 @@ #include "ModelImageObject.h" +#include "Model.h" #include "Size.h" #include +#include #include #include #include @@ -431,7 +433,12 @@ namespace glabels } else { - auto* image = new QImage( mFilenameNode.text( record, variables ) ); + // Look for image file relative to project file 1st then CWD 2nd + auto* model = dynamic_cast( parent() ); + QDir::setSearchPaths( "images", {model->dir(), QDir::currentPath()} ); + QString filename = QString("images:") + mFilenameNode.text( record, variables ); + + auto* image = new QImage( filename ); if ( !image->isNull() && image->hasAlphaChannel() && (image->depth() == 32) ) { QImage* shadowImage = createShadowImage( *image, shadowColor ); @@ -528,7 +535,12 @@ namespace glabels } else if ( mFilenameNode.isField() ) { - auto* image = new QImage( mFilenameNode.text( record, variables ) ); + // Look for image file relative to project file 1st then CWD 2nd + auto* model = dynamic_cast( parent() ); + QDir::setSearchPaths( "images", {model->dir(), QDir::currentPath()} ); + QString filename = QString("images:") + mFilenameNode.text( record, variables ); + + auto* image = new QImage( filename ); if ( !image->isNull() ) { painter->drawImage( destRect, *image ); diff --git a/model/ModelObject.h b/model/ModelObject.h index e7a6c2f..6acb538 100644 --- a/model/ModelObject.h +++ b/model/ModelObject.h @@ -407,7 +407,7 @@ namespace glabels void draw( QPainter* painter, bool inEditor, merge::Record* record, - Variables* variables ) const; + Variables* variables ) const; void drawSelectionHighlight( QPainter* painter, double scale ) const; diff --git a/model/XmlLabelCreator.cpp b/model/XmlLabelCreator.cpp index a546d14..90a1ced 100644 --- a/model/XmlLabelCreator.cpp +++ b/model/XmlLabelCreator.cpp @@ -496,8 +496,18 @@ namespace glabels XmlUtil::setStringAttr( node, "type", Variable::typeToIdString( v.type() ) ); XmlUtil::setStringAttr( node, "name", v.name() ); XmlUtil::setStringAttr( node, "initialValue", v.initialValue() ); - XmlUtil::setStringAttr( node, "increment", Variable::incrementToIdString( v.increment() ) ); - XmlUtil::setStringAttr( node, "stepSize", v.stepSize() ); + + if ( (v.type() == Variable::Type::INTEGER) || + (v.type() == Variable::Type::FLOATING_POINT) ) + { + XmlUtil::setStringAttr( node, "increment", + Variable::incrementToIdString( v.increment() ) ); + + if ( v.increment() != Variable::Increment::NEVER ) + { + XmlUtil::setStringAttr( node, "stepSize", v.stepSize() ); + } + } } From c2d9a4c0754694b4bfd3219b29a426c9c7db8f10 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Mon, 5 Aug 2019 20:26:07 -0400 Subject: [PATCH 29/32] Make sure keys are set for all apropos controls in ObjectEditor. --- glabels/ObjectEditor.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index 5f9b42d..c69bd75 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -505,10 +505,13 @@ namespace glabels { lineColorButton->setKeys( mModel->merge(), mModel->variables() ); fillColorButton->setKeys( mModel->merge(), mModel->variables() ); + textColorButton->setKeys( mModel->merge(), mModel->variables() ); + barcodeColorButton->setKeys( mModel->merge(), mModel->variables() ); + shadowColorButton->setKeys( mModel->merge(), mModel->variables() ); + textInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); barcodeInsertFieldButton->setKeys( mModel->merge(), mModel->variables() ); imageFieldButton->setKeys( mModel->merge(), mModel->variables() ); - shadowColorButton->setKeys( mModel->merge(), mModel->variables() ); } } From d4f742e7e6558b42b86d3599fe0fa10badb962ed Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Thu, 8 Aug 2019 07:57:12 -0400 Subject: [PATCH 30/32] Display image filenames as relative paths. --- glabels/ObjectEditor.cpp | 4 +++- translations/glabels_C.ts | 16 ---------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index c69bd75..206eff6 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -36,6 +36,7 @@ #include "merge/Merge.h" #include +#include #include #include @@ -129,7 +130,8 @@ namespace glabels } else { - imageFilenameLineEdit->setText( filenameNode.data() ); + QString fn = QDir(mModel->dir()).relativeFilePath( filenameNode.data() ); + imageFilenameLineEdit->setText( fn ); } mBlocked = false; diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 426a73d..575f40d 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1156,10 +1156,6 @@ Custom color... - - Use key - - Custom Color @@ -1169,10 +1165,6 @@ %1 = color specification in hex. String must not contain a colon (:). - - Custom color #%1 - - Use substitution field @@ -1934,14 +1926,6 @@ Shadow - - Insert Field - - - - Selected File... - - Insert substitution field From ec3d900e874d096615e2fcb6dc25e09dbfe87144 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Mon, 12 Aug 2019 23:03:38 -0400 Subject: [PATCH 31/32] Display merge file locations as relative paths. --- glabels/MergeView.cpp | 32 +++++--------- glabels/MergeView.h | 2 +- glabels/ui/MergeView.ui | 90 +++++++++++++++++++-------------------- translations/glabels_C.ts | 8 ++-- 4 files changed, 60 insertions(+), 72 deletions(-) diff --git a/glabels/MergeView.cpp b/glabels/MergeView.cpp index 0a1eea6..bf0f306 100644 --- a/glabels/MergeView.cpp +++ b/glabels/MergeView.cpp @@ -63,14 +63,7 @@ namespace glabels mUndoRedoModel = undoRedoModel; // Initialize CWD - if ( model->fileName().isEmpty() ) - { - mCwd = "."; - } - else - { - mCwd = QFileInfo( model->fileName() ).absolutePath(); - } + mCwd = mModel->dir(); onMergeChanged(); connect( mModel, SIGNAL(mergeChanged()), this, SLOT(onMergeChanged()) ); @@ -87,26 +80,22 @@ namespace glabels mOldFormatComboIndex = index; formatCombo->setCurrentIndex( index ); + QString fn; + switch ( merge::Factory::idToType( mModel->merge()->id() ) ) { case merge::Factory::NONE: case merge::Factory::FIXED: locationLabel->setEnabled( false ); - locationButton->setEnabled( false ); - locationButton->setText( "" ); + locationLineEdit->setText( "" ); + locationBrowseButton->setVisible( false ); break; case merge::Factory::FILE: locationLabel->setEnabled( true ); - locationButton->setEnabled( true ); - if ( mModel->merge()->source().isEmpty() ) - { - locationButton->setText( "Select file..." ); - } - else - { - locationButton->setText( mModel->merge()->source() ); - } + fn = QDir(mModel->dir()).relativeFilePath( mModel->merge()->source() ); + locationLineEdit->setText( fn ); + locationBrowseButton->setVisible( true ); break; default: @@ -135,7 +124,8 @@ namespace glabels /// void MergeView::onMergeSourceChanged() { - locationButton->setText( mModel->merge()->source() ); + QString fn = QDir(mModel->dir()).relativeFilePath( mModel->merge()->source() ); + locationLineEdit->setText( fn ); recordsTable->clear(); recordsTable->setColumnCount( 0 ); @@ -185,7 +175,7 @@ namespace glabels /// /// Location button clicked handler /// - void MergeView::onLocationButtonClicked() + void MergeView::onLocationBrowseButtonClicked() { QString fileName = QFileDialog::getOpenFileName( this, diff --git a/glabels/MergeView.h b/glabels/MergeView.h index 8734994..e0ddead 100644 --- a/glabels/MergeView.h +++ b/glabels/MergeView.h @@ -67,7 +67,7 @@ namespace glabels void onMergeSelectionChanged(); void onFormatComboActivated(); - void onLocationButtonClicked(); + void onLocationBrowseButtonClicked(); void onSelectAllButtonClicked(); void onUnselectAllButtonClicked(); void onCellChanged( int iRow, int iCol ); diff --git a/glabels/ui/MergeView.ui b/glabels/ui/MergeView.ui index 89517fd..c7f682a 100644 --- a/glabels/ui/MergeView.ui +++ b/glabels/ui/MergeView.ui @@ -46,16 +46,9 @@ Source - - + + - - - - Location - - - @@ -63,6 +56,27 @@ + + + + + + + + + true + + + + + + + Browse... + + + + + @@ -70,24 +84,8 @@ - - - - - - - Qt::Horizontal - - - - 360 - 20 - - - - @@ -151,8 +149,8 @@ onSelectAllButtonClicked() - 63 - 571 + 97 + 570 69 @@ -176,22 +174,6 @@ - - locationButton - clicked() - MergeView - onLocationButtonClicked() - - - 174 - 93 - - - 570 - 75 - - - formatCombo activated(int) @@ -199,8 +181,8 @@ onFormatComboActivated() - 162 - 48 + 257 + 109 563 @@ -208,11 +190,27 @@ + + locationBrowseButton + clicked() + MergeView + onLocationBrowseButtonClicked() + + + 296 + 130 + + + 565 + 149 + + + onSelectAllButtonClicked() onUnselectAllButtonClicked() - onLocationButtonClicked() onFormatComboActivated() + onLocationBrowseButtonClicked() diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index 575f40d..d300fce 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -286,10 +286,6 @@ Source - - Location - - Format: @@ -310,6 +306,10 @@ Unselect all + + Browse... + + ObjectEditor From 6a789c96328af1a3b82a9af3ff22d856adbd3376 Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sun, 18 Aug 2019 21:56:37 -0400 Subject: [PATCH 32/32] Save/restore file paths as relative to project file. --- glabels/File.cpp | 8 +-- glabels/MergeView.cpp | 6 +- glabels/ObjectEditor.cpp | 2 +- model/Model.cpp | 25 +++++++-- model/Model.h | 4 +- model/ModelImageObject.cpp | 4 +- model/XmlLabelCreator.cpp | 98 +++++++++++++++++++++----------- model/XmlLabelCreator.h | 104 +++++++++++++++++++++++++--------- model/XmlLabelParser.cpp | 112 ++++++++++++++++++++++++------------- model/XmlLabelParser.h | 65 +++++++++++++++------ translations/glabels_C.ts | 16 ++++++ 11 files changed, 312 insertions(+), 132 deletions(-) diff --git a/glabels/File.cpp b/glabels/File.cpp index 1e65f59..8af7562 100644 --- a/glabels/File.cpp +++ b/glabels/File.cpp @@ -111,8 +111,6 @@ namespace glabels model::Model *model = model::XmlLabelParser::readFile( fileName ); if ( model ) { - model->setFileName( fileName ); - // Either apply to current window or open a new one if ( window->isEmpty() ) { @@ -156,7 +154,6 @@ namespace glabels } model::XmlLabelCreator::writeFile( window->model(), window->model()->fileName() ); - window->model()->clearModified(); // Save CWD mCwd = QFileInfo( window->model()->fileName() ).absolutePath(); @@ -170,7 +167,8 @@ namespace glabels /// bool File::saveAs( MainWindow *window ) { - // Either use the saved CWD from a previous open/save or grab it from the path of the current file + // Either use the saved CWD from a previous open/save or grab it from the path + // of the current file. QString cwd = mCwd; if ( window->model() && !window->model()->fileName().isEmpty() ) { @@ -210,8 +208,6 @@ namespace glabels } model::XmlLabelCreator::writeFile( window->model(), fileName ); - window->model()->setFileName( fileName ); - window->model()->clearModified(); // Save CWD mCwd = QFileInfo( fileName ).absolutePath(); diff --git a/glabels/MergeView.cpp b/glabels/MergeView.cpp index bf0f306..f534209 100644 --- a/glabels/MergeView.cpp +++ b/glabels/MergeView.cpp @@ -63,7 +63,7 @@ namespace glabels mUndoRedoModel = undoRedoModel; // Initialize CWD - mCwd = mModel->dir(); + mCwd = mModel->dirPath(); onMergeChanged(); connect( mModel, SIGNAL(mergeChanged()), this, SLOT(onMergeChanged()) ); @@ -93,7 +93,7 @@ namespace glabels case merge::Factory::FILE: locationLabel->setEnabled( true ); - fn = QDir(mModel->dir()).relativeFilePath( mModel->merge()->source() ); + fn = mModel->dir().relativeFilePath( mModel->merge()->source() ); locationLineEdit->setText( fn ); locationBrowseButton->setVisible( true ); break; @@ -124,7 +124,7 @@ namespace glabels /// void MergeView::onMergeSourceChanged() { - QString fn = QDir(mModel->dir()).relativeFilePath( mModel->merge()->source() ); + QString fn = mModel->dir().relativeFilePath( mModel->merge()->source() ); locationLineEdit->setText( fn ); recordsTable->clear(); diff --git a/glabels/ObjectEditor.cpp b/glabels/ObjectEditor.cpp index 206eff6..83ee153 100644 --- a/glabels/ObjectEditor.cpp +++ b/glabels/ObjectEditor.cpp @@ -130,7 +130,7 @@ namespace glabels } else { - QString fn = QDir(mModel->dir()).relativeFilePath( filenameNode.data() ); + QString fn = mModel->dir().relativeFilePath( filenameNode.data() ); imageFilenameLineEdit->setText( fn ); } diff --git a/model/Model.cpp b/model/Model.cpp index 07801b2..e9c76e8 100644 --- a/model/Model.cpp +++ b/model/Model.cpp @@ -32,7 +32,6 @@ #include #include -#include #include #include #include @@ -282,9 +281,25 @@ namespace glabels /// - /// Get directory. + /// Get directory as a QDir. /// - QString Model::dir() const + QDir Model::dir() const + { + if ( mFileName.isEmpty() ) + { + return QDir::current(); + } + else + { + return QFileInfo( mFileName ).absoluteDir(); + } + } + + + /// + /// Get directory as a path. + /// + QString Model::dirPath() const { if ( mFileName.isEmpty() ) { @@ -1400,7 +1415,7 @@ namespace glabels QClipboard *clipboard = QApplication::clipboard(); QByteArray buffer; - XmlLabelCreator::serializeObjects( getSelection(), buffer ); + XmlLabelCreator::serializeObjects( getSelection(), this, buffer ); auto *mimeData = new QMimeData; mimeData->setData( MIME_TYPE, buffer ); @@ -1456,7 +1471,7 @@ namespace glabels { // Native objects QByteArray buffer = mimeData->data( MIME_TYPE ); - QList objects = XmlLabelParser::deserializeObjects( buffer ); + QList objects = XmlLabelParser::deserializeObjects( buffer, this ); unselectAll(); foreach ( ModelObject* object, objects ) diff --git a/model/Model.h b/model/Model.h index b1c5b33..ef6e69d 100644 --- a/model/Model.h +++ b/model/Model.h @@ -29,6 +29,7 @@ #include "merge/Merge.h" #include "merge/Record.h" +#include #include #include #include @@ -91,7 +92,8 @@ namespace glabels void setModified(); void clearModified(); - QString dir() const; + QDir dir() const; + QString dirPath() const; QString shortName(); const QString& fileName() const; void setFileName( const QString &fileName ); diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp index 550de8c..7d94728 100644 --- a/model/ModelImageObject.cpp +++ b/model/ModelImageObject.cpp @@ -435,7 +435,7 @@ namespace glabels { // Look for image file relative to project file 1st then CWD 2nd auto* model = dynamic_cast( parent() ); - QDir::setSearchPaths( "images", {model->dir(), QDir::currentPath()} ); + QDir::setSearchPaths( "images", {model->dirPath(), QDir::currentPath()} ); QString filename = QString("images:") + mFilenameNode.text( record, variables ); auto* image = new QImage( filename ); @@ -537,7 +537,7 @@ namespace glabels { // Look for image file relative to project file 1st then CWD 2nd auto* model = dynamic_cast( parent() ); - QDir::setSearchPaths( "images", {model->dir(), QDir::currentPath()} ); + QDir::setSearchPaths( "images", {model->dirPath(), QDir::currentPath()} ); QString filename = QString("images:") + mFilenameNode.text( record, variables ); auto* image = new QImage( filename ); diff --git a/model/XmlLabelCreator.cpp b/model/XmlLabelCreator.cpp index 90a1ced..7504d3f 100644 --- a/model/XmlLabelCreator.cpp +++ b/model/XmlLabelCreator.cpp @@ -33,6 +33,7 @@ #include "XmlTemplateCreator.h" #include "XmlUtil.h" +#include "merge/Factory.h" #include "merge/None.h" #include @@ -49,38 +50,41 @@ namespace glabels { void - XmlLabelCreator::writeFile( const Model* label, const QString& fileName ) + XmlLabelCreator::writeFile( Model* model, const QString& fileName ) { - QDomDocument doc; - - createDoc( doc, label ); - QByteArray buffer = doc.toByteArray( 2 ); - QFile file( fileName ); - if ( !file.open( QFile::WriteOnly | QFile::Text) ) { qWarning() << "Error: Cannot write file " << fileName << ": " << file.errorString(); + return; } + model->setFileName( fileName ); + model->clearModified(); + + QDomDocument doc; + createDoc( doc, model ); + + QByteArray buffer = doc.toByteArray( 2 ); file.write( buffer.data(), buffer.size() ); } void - XmlLabelCreator::writeBuffer( const Model* label, QByteArray& buffer ) + XmlLabelCreator::writeBuffer( const Model* model, QByteArray& buffer ) { QDomDocument doc; - createDoc( doc, label ); + createDoc( doc, model ); buffer = doc.toByteArray( 2 ); } void XmlLabelCreator::serializeObjects( const QList& objects, - QByteArray& buffer ) + const Model* model, + QByteArray& buffer ) { QDomDocument doc; @@ -91,15 +95,15 @@ namespace glabels doc.appendChild( root ); XmlUtil::setStringAttr( root, "version", "4.0" ); - createDataNode( root, objects ); - createObjectsNode( root, objects, false ); + createDataNode( root, model, objects ); + createObjectsNode( root, model, objects, false ); buffer = doc.toByteArray( 2 ); } void - XmlLabelCreator::createDoc( QDomDocument& doc, const Model* label ) + XmlLabelCreator::createDoc( QDomDocument& doc, const Model* model ) { QDomNode xmlNode( doc.createProcessingInstruction( "xml", "version=\"1.0\"" ) ); doc.appendChild( xmlNode ); @@ -108,26 +112,29 @@ namespace glabels doc.appendChild( root ); XmlUtil::setStringAttr( root, "version", "4.0" ); - XmlTemplateCreator().createTemplateNode( root, label->tmplate() ); + XmlTemplateCreator().createTemplateNode( root, model->tmplate() ); - createObjectsNode( root, label->objectList(), label->rotate() ); + createObjectsNode( root, model, model->objectList(), model->rotate() ); - if ( label->merge() && !dynamic_cast(label->merge()) ) + if ( model->merge() && !dynamic_cast(model->merge()) ) { - createMergeNode( root, label ); + createMergeNode( root, model ); } - if ( label->variables()->size() != 0 ) + if ( model->variables()->size() != 0 ) { - createVariablesNode( root, label ); + createVariablesNode( root, model ); } - createDataNode( root, label->objectList() ); + createDataNode( root, model, model->objectList() ); } void - XmlLabelCreator::createObjectsNode( QDomElement &parent, const QList& objects, bool rotate ) + XmlLabelCreator::createObjectsNode( QDomElement& parent, + const Model* model, + const QList& objects, + bool rotate ) { QDomDocument doc = parent.ownerDocument(); QDomElement node = doc.createElement( "Objects" ); @@ -152,7 +159,7 @@ namespace glabels } else if ( auto* imageObject = dynamic_cast(object) ) { - createObjectImageNode( node, imageObject ); + createObjectImageNode( node, model, imageObject ); } else if ( auto* barcodeObject = dynamic_cast(object) ) { @@ -250,7 +257,9 @@ namespace glabels void - XmlLabelCreator::createObjectImageNode( QDomElement &parent, const ModelImageObject* object ) + XmlLabelCreator::createObjectImageNode( QDomElement& parent, + const Model* model, + const ModelImageObject* object ) { QDomDocument doc = parent.ownerDocument(); QDomElement node = doc.createElement( "Object-image" ); @@ -269,7 +278,8 @@ namespace glabels } else { - XmlUtil::setStringAttr( node, "src", object->filenameNode().data() ); + QString fn = model->dir().relativeFilePath( object->filenameNode().data() ); + XmlUtil::setStringAttr( node, "src", fn ); } /* affine attrs */ @@ -461,25 +471,45 @@ namespace glabels void - XmlLabelCreator::createMergeNode( QDomElement &parent, const Model* label ) + XmlLabelCreator::createMergeNode( QDomElement &parent, const Model* model ) { QDomDocument doc = parent.ownerDocument(); QDomElement node = doc.createElement( "Merge" ); parent.appendChild( node ); - XmlUtil::setStringAttr( node, "type", label->merge()->id() ); - XmlUtil::setStringAttr( node, "src", label->merge()->source() ); + QString id = model->merge()->id(); + QString src = model->merge()->source(); + + XmlUtil::setStringAttr( node, "type", id ); + + switch ( merge::Factory::idToType( id ) ) + { + case merge::Factory::NONE: + case merge::Factory::FIXED: + break; + + case merge::Factory::FILE: + { + QString fn = model->dir().relativeFilePath( src ); + XmlUtil::setStringAttr( node, "src", fn ); + } + break; + + default: + qWarning() << "XmlLabelCreator::createMergeNode(): Should not be reached!"; + break; + } } void - XmlLabelCreator::createVariablesNode( QDomElement &parent, const Model* label ) + XmlLabelCreator::createVariablesNode( QDomElement &parent, const Model* model ) { QDomDocument doc = parent.ownerDocument(); QDomElement node = doc.createElement( "Variables" ); parent.appendChild( node ); - for ( const auto& v : *label->variables() ) + for ( const auto& v : *model->variables() ) { createVariableNode( node, v ); } @@ -512,7 +542,9 @@ namespace glabels void - XmlLabelCreator::createDataNode( QDomElement &parent, const QList& objects ) + XmlLabelCreator::createDataNode( QDomElement& parent, + const Model* model, + const QList& objects ) { QDomDocument doc = parent.ownerDocument(); QDomElement node = doc.createElement( "Data" ); @@ -522,12 +554,14 @@ namespace glabels foreach ( QString name, data.imageNames() ) { - createPngFileNode( node, name, data.getImage( name ) ); + QString fn = model->dir().relativeFilePath( name ); + createPngFileNode( node, fn, data.getImage( name ) ); } foreach ( QString name, data.svgNames() ) { - createSvgFileNode( node, name, data.getSvg( name ) ); + QString fn = model->dir().relativeFilePath( name ); + createSvgFileNode( node, fn, data.getSvg( name ) ); } } diff --git a/model/XmlLabelCreator.h b/model/XmlLabelCreator.h index 2e3d87a..9c765ac 100644 --- a/model/XmlLabelCreator.h +++ b/model/XmlLabelCreator.h @@ -51,33 +51,87 @@ namespace glabels Q_OBJECT public: - static void writeFile( const Model* label, const QString& fileName ); - static void writeBuffer( const Model* label, QByteArray& buffer ); - static void serializeObjects( const QList& objects, QByteArray& buffer ); + static void writeFile( Model* model, + const QString& fileName ); + + static void writeBuffer( const Model* model, + QByteArray& buffer ); + + static void serializeObjects( const QList& objects, + const Model* model, + QByteArray& buffer ); private: - static void createDoc( QDomDocument& doc, const Model* label ); - static void createRootNode( const Model* label ); - static void createObjectsNode( QDomElement &parent, const QList& objects, bool rotate ); - static void createObjectBoxNode( QDomElement &parent, const ModelBoxObject* object ); - static void createObjectEllipseNode( QDomElement &parent, const ModelEllipseObject* object ); - static void createObjectLineNode( QDomElement &parent, const ModelLineObject* object ); - static void createObjectImageNode( QDomElement &parent, const ModelImageObject* object ); - static void createObjectBarcodeNode( QDomElement &parent, const ModelBarcodeObject* object ); - static void createObjectTextNode( QDomElement &parent, const ModelTextObject* object ); - static void createPNode( QDomElement &parent, const QString& blockText ); - static void createPositionAttrs( QDomElement &node, const ModelObject* object ); - static void createSizeAttrs( QDomElement &node, const ModelObject* object ); - static void createLineAttrs( QDomElement &node, const ModelObject* object ); - static void createFillAttrs( QDomElement &node, const ModelObject* object ); - static void createAffineAttrs( QDomElement &node, const ModelObject* object ); - static void createShadowAttrs( QDomElement &node, const ModelObject* object ); - static void createMergeNode( QDomElement &parent, const Model* label ); - static void createVariablesNode( QDomElement &parent, const Model* label ); - static void createVariableNode( QDomElement &parent, const Variable& v ); - static void createDataNode( QDomElement &parent, const QList& objects ); - static void createPngFileNode( QDomElement &parent, const QString& name, const QImage& image ); - static void createSvgFileNode( QDomElement &parent, const QString& name, const QByteArray& svg ); + static void createDoc( QDomDocument& doc, + const Model* model ); + + static void createRootNode( const Model* model ); + + static void createObjectsNode( QDomElement& parent, + const Model* model, + const QList& objects, + bool rotate ); + + static void createObjectBoxNode( QDomElement& parent, + const ModelBoxObject* object ); + + static void createObjectEllipseNode( QDomElement& parent, + const ModelEllipseObject* object ); + + static void createObjectLineNode( QDomElement& parent, + const ModelLineObject* object ); + + static void createObjectImageNode( QDomElement& parent, + const Model* model, + const ModelImageObject* object ); + + static void createObjectBarcodeNode( QDomElement& parent, + const ModelBarcodeObject* object ); + + static void createObjectTextNode( QDomElement& parent, + const ModelTextObject* object ); + + static void createPNode( QDomElement& parent, + const QString& blockText ); + + static void createPositionAttrs( QDomElement& node, + const ModelObject* object ); + + static void createSizeAttrs( QDomElement& node, + const ModelObject* object ); + + static void createLineAttrs( QDomElement& node, + const ModelObject* object ); + + static void createFillAttrs( QDomElement& node, + const ModelObject* object ); + + static void createAffineAttrs( QDomElement& node, + const ModelObject* object ); + + static void createShadowAttrs( QDomElement& node, + const ModelObject* object ); + + static void createMergeNode( QDomElement& parent, + const Model* model ); + + static void createVariablesNode( QDomElement& parent, + const Model* model ); + + static void createVariableNode( QDomElement& parent, + const Variable& v ); + + static void createDataNode( QDomElement& parent, + const Model* model, + const QList& objects ); + + static void createPngFileNode( QDomElement& parent, + const QString& name, + const QImage& image ); + + static void createSvgFileNode( QDomElement& parent, + const QString& name, + const QByteArray& svg ); }; diff --git a/model/XmlLabelParser.cpp b/model/XmlLabelParser.cpp index ed9bdb9..601f488 100644 --- a/model/XmlLabelParser.cpp +++ b/model/XmlLabelParser.cpp @@ -105,7 +105,7 @@ namespace glabels return nullptr; } - return parseRootNode( root ); + return parseRootNode( root, fileName ); } @@ -132,12 +132,12 @@ namespace glabels return nullptr; } - return parseRootNode( root ); + return parseRootNode( root, QString() ); } QList - XmlLabelParser::deserializeObjects( const QByteArray& buffer ) + XmlLabelParser::deserializeObjects( const QByteArray& buffer, const Model* model ) { QList list; @@ -167,7 +167,7 @@ namespace glabels { if ( child.toElement().tagName() == "Data" ) { - parseDataNode( child.toElement(), data ); + parseDataNode( child.toElement(), model, data ); } } @@ -176,9 +176,10 @@ namespace glabels { if ( child.toElement().tagName() == "Objects" ) { - list = parseObjectsNode( child.toElement(), data ); + list = parseObjectsNode( child.toElement(), model, data ); } } + return list; } @@ -236,7 +237,7 @@ namespace glabels Model* - XmlLabelParser::parseRootNode( const QDomElement &node ) + XmlLabelParser::parseRootNode( const QDomElement &node, const QString& fileName ) { QString version = XmlUtil::getStringAttr( node, "version", "" ); if ( version != "4.0" ) @@ -245,7 +246,8 @@ namespace glabels return XmlLabelParser_3::parseRootNode(node); } - auto* label = new Model(); + auto* model = new Model(); + model->setFileName( fileName ); /* Pass 1, extract data nodes to pre-load cache. */ DataCache data; @@ -253,7 +255,7 @@ namespace glabels { if ( child.toElement().tagName() == "Data" ) { - parseDataNode( child.toElement(), data ); + parseDataNode( child.toElement(), model, data ); } } @@ -268,27 +270,27 @@ namespace glabels if ( tmplate == nullptr ) { qWarning() << "Unable to parse template"; - delete label; + delete model; return nullptr; } - label->setTmplate( tmplate ); + model->setTmplate( tmplate ); } else if ( tagName == "Objects" ) { - label->setRotate( parseRotateAttr( child.toElement() ) ); - QList list = parseObjectsNode( child.toElement(), data ); + model->setRotate( parseRotateAttr( child.toElement() ) ); + auto list = parseObjectsNode( child.toElement(), model, data ); foreach ( ModelObject* object, list ) { - label->addObject( object ); + model->addObject( object ); } } else if ( tagName == "Merge" ) { - parseMergeNode( child.toElement(), label ); + parseMergeNode( child.toElement(), model ); } else if ( tagName == "Variables" ) { - parseVariablesNode( child.toElement(), label ); + parseVariablesNode( child.toElement(), model ); } else if ( tagName == "Data" ) { @@ -300,13 +302,15 @@ namespace glabels } } - label->clearModified(); - return label; + model->clearModified(); + return model; } QList - XmlLabelParser::parseObjectsNode( const QDomElement &node, const DataCache& data ) + XmlLabelParser::parseObjectsNode( const QDomElement& node, + const Model* model, + const DataCache& data ) { QList list; @@ -332,7 +336,7 @@ namespace glabels } else if ( tagName == "Object-image" ) { - list.append( parseObjectImageNode( child.toElement(), data ) ); + list.append( parseObjectImageNode( child.toElement(), model, data ) ); } else if ( tagName == "Object-barcode" ) { @@ -501,7 +505,9 @@ namespace glabels ModelImageObject* - XmlLabelParser::parseObjectImageNode( const QDomElement &node, const DataCache& data ) + XmlLabelParser::parseObjectImageNode( const QDomElement& node, + const Model* model, + const DataCache& data ) { /* position attrs */ Distance x0 = XmlUtil::getLengthAttr( node, "x", 0.0 ); @@ -546,23 +552,25 @@ namespace glabels } else { - if ( data.hasImage( filename ) ) + QString fn = QDir::cleanPath( model->dir().absoluteFilePath( filename ) ); + + if ( data.hasImage( fn ) ) { return new ModelImageObject( x0, y0, w, h, - filename, data.getImage( filename ), + fn, data.getImage( fn ), QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ), shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode ); } - else if ( data.hasSvg( filename ) ) + else if ( data.hasSvg( fn ) ) { return new ModelImageObject( x0, y0, w, h, - filename, data.getSvg( filename ), + fn, data.getSvg( fn ), QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ), shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode ); } else { - qWarning() << "Embedded file" << filename << "missing. Trying actual file."; + qWarning() << "Embedded file" << fn << "missing. Trying actual file."; return new ModelImageObject( x0, y0, w, h, filenameNode, QMatrix( a[0], a[1], a[2], a[3], a[4], a[5] ), @@ -711,20 +719,37 @@ namespace glabels void - XmlLabelParser::parseMergeNode( const QDomElement &node, Model* label ) + XmlLabelParser::parseMergeNode( const QDomElement &node, Model* model ) { - QString type = XmlUtil::getStringAttr( node, "type", "None" ); - QString src = XmlUtil::getStringAttr( node, "src", "" ); + QString id = XmlUtil::getStringAttr( node, "type", "None" ); + QString src = XmlUtil::getStringAttr( node, "src", "" ); - merge::Merge* merge = merge::Factory::createMerge( type ); - merge->setSource( src ); + merge::Merge* merge = merge::Factory::createMerge( id ); - label->setMerge( merge ); + switch ( merge::Factory::idToType( id ) ) + { + case merge::Factory::NONE: + case merge::Factory::FIXED: + break; + + case merge::Factory::FILE: + { + QString fn = QDir::cleanPath( model->dir().absoluteFilePath( src ) ); + merge->setSource( fn ); + } + break; + + default: + qWarning() << "XmlLabelCreator::createMergeNode(): Should not be reached!"; + break; + } + + model->setMerge( merge ); } void - XmlLabelParser::parseVariablesNode( const QDomElement &node, Model* label ) + XmlLabelParser::parseVariablesNode( const QDomElement &node, Model* model ) { for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() ) { @@ -732,7 +757,7 @@ namespace glabels if ( tagName == "Variable" ) { - parseVariableNode( child.toElement(), label ); + parseVariableNode( child.toElement(), model ); } else if ( !child.isComment() ) { @@ -743,7 +768,7 @@ namespace glabels void - XmlLabelParser::parseVariableNode( const QDomElement &node, Model* label ) + XmlLabelParser::parseVariableNode( const QDomElement &node, Model* model ) { QString typeString = XmlUtil::getStringAttr( node, "type", "string" ); QString name = XmlUtil::getStringAttr( node, "name", "unknown" ); @@ -755,12 +780,14 @@ namespace glabels auto increment = Variable::idStringToIncrement( incrementString ); Variable v( type, name, initialValue, increment, stepSize ); - label->variables()->addVariable( v ); + model->variables()->addVariable( v ); } void - XmlLabelParser::parseDataNode( const QDomElement &node, DataCache& data ) + XmlLabelParser::parseDataNode( const QDomElement &node, + const Model* model, + DataCache& data ) { for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() ) { @@ -768,7 +795,7 @@ namespace glabels if ( tagName == "File" ) { - parseFileNode( child.toElement(), data ); + parseFileNode( child.toElement(), model, data ); } else if ( !child.isComment() ) { @@ -779,12 +806,17 @@ namespace glabels void - XmlLabelParser::parseFileNode( const QDomElement& node, DataCache& data ) + XmlLabelParser::parseFileNode( const QDomElement& node, + const Model* model, + DataCache& data ) { QString name = XmlUtil::getStringAttr( node, "name", "" ); QString mimetype = XmlUtil::getStringAttr( node, "mimetype", "image/png" ); QString encoding = XmlUtil::getStringAttr( node, "encoding", "base64" ); + // Rewrite name as absolute file path + QString fn = QDir::cleanPath( model->dir().absoluteFilePath( name ) ); + if ( mimetype == "image/png" ) { if ( encoding == "base64" ) @@ -794,7 +826,7 @@ namespace glabels QImage image; image.loadFromData( ba, "PNG" ); - data.addImage( name, image ); + data.addImage( fn, image ); } else { @@ -803,7 +835,7 @@ namespace glabels } else if ( mimetype == "image/svg+xml" ) { - data.addSvg( name, node.text().toUtf8() ); + data.addSvg( fn, node.text().toUtf8() ); } } diff --git a/model/XmlLabelParser.h b/model/XmlLabelParser.h index c13edf4..93e90e8 100644 --- a/model/XmlLabelParser.h +++ b/model/XmlLabelParser.h @@ -52,26 +52,57 @@ namespace glabels public: static Model* readFile( const QString& fileName ); + static Model* readBuffer( const QByteArray& buffer ); - static QList deserializeObjects( const QByteArray& buffer ); + + static QList deserializeObjects( const QByteArray& buffer, + const Model* model ); private: - static void gunzip( const QByteArray& gzippedData, QByteArray& data ); - static Model* parseRootNode( const QDomElement &node ); - static QList parseObjectsNode( const QDomElement &node, const DataCache& data ); - static ModelBoxObject* parseObjectBoxNode( const QDomElement &node ); - static ModelEllipseObject* parseObjectEllipseNode( const QDomElement &node ); - static ModelLineObject* parseObjectLineNode( const QDomElement &node ); - static ModelImageObject* parseObjectImageNode( const QDomElement &node, const DataCache& data ); - static ModelBarcodeObject* parseObjectBarcodeNode( const QDomElement &node ); - static ModelTextObject* parseObjectTextNode( const QDomElement &node ); - static QString parsePNode( const QDomElement &node ); - static bool parseRotateAttr( const QDomElement &node ); - static void parseMergeNode( const QDomElement &node, Model* label ); - static void parseVariablesNode( const QDomElement &node, Model* label ); - static void parseVariableNode( const QDomElement &node, Model* label ); - static void parseDataNode( const QDomElement &node, DataCache& data ); - static void parseFileNode( const QDomElement &node, DataCache& data ); + static void gunzip( const QByteArray& gzippedData, + QByteArray& data ); + + static Model* parseRootNode( const QDomElement& node, + const QString& fileName ); + + static QList parseObjectsNode( const QDomElement& node, + const Model* model, + const DataCache& data ); + + static ModelBoxObject* parseObjectBoxNode( const QDomElement& node ); + + static ModelEllipseObject* parseObjectEllipseNode( const QDomElement& node ); + + static ModelLineObject* parseObjectLineNode( const QDomElement& node ); + + static ModelImageObject* parseObjectImageNode( const QDomElement& node, + const Model* model, + const DataCache& data ); + + static ModelBarcodeObject* parseObjectBarcodeNode( const QDomElement& node ); + + static ModelTextObject* parseObjectTextNode( const QDomElement& node ); + + static QString parsePNode( const QDomElement& node ); + + static bool parseRotateAttr( const QDomElement& node ); + + static void parseMergeNode( const QDomElement& node, + Model* model ); + + static void parseVariablesNode( const QDomElement& node, + Model* model ); + + static void parseVariableNode( const QDomElement& node, + Model* model ); + + static void parseDataNode( const QDomElement& node, + const Model* model, + DataCache& data ); + + static void parseFileNode( const QDomElement& node, + const Model* model, + DataCache& data ); }; diff --git a/translations/glabels_C.ts b/translations/glabels_C.ts index d300fce..645d124 100644 --- a/translations/glabels_C.ts +++ b/translations/glabels_C.ts @@ -1169,6 +1169,14 @@ Use substitution field + + Use key + + + + Custom color #%1 + + glabels::EditVariableDialog @@ -1938,6 +1946,14 @@ Use substitution field + + Insert Field + + + + Selected File... + + glabels::PrintView