Closed MVC loop for VariablesView.

This commit is contained in:
Jim Evins
2019-03-16 18:12:17 -04:00
parent c9e26c45fb
commit 6255939f39
11 changed files with 448 additions and 45 deletions
+2
View File
@@ -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})
+24
View File
@@ -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
///
+6
View File
@@ -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<ModelObject*>& 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<ModelObject*> mObjectList;
Variables* mVariables;
merge::Merge* mMerge;
};
+65 -8
View File
@@ -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";
}
}
}
}
+29 -20
View File
@@ -22,6 +22,7 @@
#define model_Variable_h
#include <QCoreApplication>
#include <QString>
@@ -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;
};
+90
View File
@@ -0,0 +1,90 @@
/* Variables.cpp
*
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "Variables.h"
#include <QtDebug>
namespace glabels
{
namespace model
{
///
/// Copy constructor
///
Variables::Variables( const Variables* variables )
: QMap<QString,Variable>(*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
+85
View File
@@ -0,0 +1,85 @@
/* Variables.h
*
* Copyright (C) 2013-2016 Jim Evins <evins@snaught.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef model_Variables_h
#define model_Variables_h
#include "Variable.h"
#include <QMap>
#include <QObject>
#include <QString>
namespace glabels
{
namespace model
{
///
/// Variables Collection
///
class Variables : public QObject, public QMap<QString,Variable>
{
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