diff --git a/.github/workflows/build-tests.yml b/.github/workflows/build-tests.yml
index 1594cf1..65f83cb 100644
--- a/.github/workflows/build-tests.yml
+++ b/.github/workflows/build-tests.yml
@@ -139,3 +139,8 @@ jobs:
if: startsWith( matrix.os, 'macos-' )
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }}
+
+# - name: Tmate
+# uses: mxschmitt/action-tmate@v3
+# if: failure()
+
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3bdba30..3b28b70 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,10 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/"
#=======================================
# Version Information
#=======================================
+set (ORGANIZATION_NAME "glabels.org")
+set (ORGANIZATION_DOMAIN "glabels.org")
+set (APPLICATION_NAME "glabels-qt")
+
set (WEBSITE "glabels.org")
set (BUG_WEBSITE "https://github.com/j-evins/glabels-qt/issues")
diff --git a/backends/merge/Merge.cpp b/backends/merge/Merge.cpp
index 8279996..bf37995 100644
--- a/backends/merge/Merge.cpp
+++ b/backends/merge/Merge.cpp
@@ -18,9 +18,8 @@
* along with gLabels-qt. If not, see .
*/
-#include "Merge.h"
-#include "Record.h"
+#include "Merge.h"
namespace glabels
@@ -31,25 +30,11 @@ namespace glabels
///
/// Constructor
///
- Merge::Merge( const Merge* merge ) : mId(merge->mId), mSource(merge->mSource)
+ Merge::Merge( const Merge* merge )
+ : mId(merge->mId),
+ mSource(merge->mSource),
+ mRecordList(merge->mRecordList)
{
- foreach ( Record* record, merge->mRecordList )
- {
- mRecordList << record->clone();
- }
- }
-
-
- ///
- /// Destructor
- ///
- Merge::~Merge()
- {
- foreach ( Record* record, mRecordList )
- {
- delete record;
- }
- mRecordList.clear();
}
@@ -79,16 +64,12 @@ namespace glabels
mSource = source;
// Clear out any old records
- foreach ( Record* record, mRecordList )
- {
- delete record;
- }
mRecordList.clear();
open();
- for ( Record* record = readNextRecord(); record != nullptr; record = readNextRecord() )
+ for ( Record record = readNextRecord(); !record.isEmpty(); record = readNextRecord() )
{
- mRecordList.append( record );
+ mRecordList.push_back( record );
}
close();
@@ -99,32 +80,12 @@ namespace glabels
///
/// Get record list
///
- const QList& Merge::recordList( ) const
+ const QList& Merge::recordList( ) const
{
return mRecordList;
}
- ///
- /// Select matching record
- ///
- void Merge::select( Record* record )
- {
- record->setSelected( true );
- emit selectionChanged();
- }
-
-
- ///
- /// Unselect matching record
- ///
- void Merge::unselect( Record* record )
- {
- record->setSelected( false );
- emit selectionChanged();
- }
-
-
///
/// Select/unselect i'th record
///
@@ -132,7 +93,7 @@ namespace glabels
{
if ( (i >= 0) && (i < mRecordList.size()) )
{
- mRecordList[i]->setSelected( state );
+ mRecordList[i].setSelected( state );
emit selectionChanged();
}
}
@@ -143,9 +104,9 @@ namespace glabels
///
void Merge::selectAll()
{
- foreach ( Record* record, mRecordList )
+ for ( auto& record : mRecordList )
{
- record->setSelected( true );
+ record.setSelected( true );
}
emit selectionChanged();
}
@@ -156,9 +117,9 @@ namespace glabels
///
void Merge::unselectAll()
{
- foreach ( Record* record, mRecordList )
+ for ( auto& record : mRecordList )
{
- record->setSelected( false );
+ record.setSelected( false );
}
emit selectionChanged();
}
@@ -171,9 +132,9 @@ namespace glabels
{
int count = 0;
- foreach ( Record* record, mRecordList )
+ for ( const auto& record : mRecordList )
{
- if ( record->isSelected() )
+ if ( record.isSelected() )
{
count++;
}
@@ -186,13 +147,13 @@ namespace glabels
///
/// Return list of selected records
///
- const QList Merge::selectedRecords() const
+ const QList Merge::selectedRecords() const
{
- QList list;
+ QList list;
- foreach ( Record* record, mRecordList )
+ for ( const auto& record : mRecordList )
{
- if ( record->isSelected() )
+ if ( record.isSelected() )
{
list.append( record );
}
diff --git a/backends/merge/Merge.h b/backends/merge/Merge.h
index 5c1d96c..a8cecbb 100644
--- a/backends/merge/Merge.h
+++ b/backends/merge/Merge.h
@@ -22,6 +22,8 @@
#define merge_Merge_h
+#include "Record.h"
+
#include
#include
#include
@@ -52,7 +54,7 @@ namespace glabels
Merge() = default;
Merge( const Merge* merge );
public:
- ~Merge() override;
+ virtual ~Merge() = default;
/////////////////////////////////
@@ -69,21 +71,19 @@ namespace glabels
QString source() const;
void setSource( const QString& source );
- const QList& recordList( ) const;
+ const QList& recordList( ) const;
/////////////////////////////////
// Selection methods
/////////////////////////////////
public:
- void select( Record* record );
- void unselect( Record* record );
void setSelected( int i, bool state = true );
void selectAll();
void unselectAll();
int nSelectedRecords() const;
- const QList selectedRecords() const;
+ const QList selectedRecords() const;
/////////////////////////////////
@@ -95,7 +95,7 @@ namespace glabels
protected:
virtual void open() = 0;
virtual void close() = 0;
- virtual Record* readNextRecord() = 0;
+ virtual Record readNextRecord() = 0;
/////////////////////////////////
@@ -110,10 +110,10 @@ namespace glabels
// Private data
/////////////////////////////////
protected:
- QString mId;
+ QString mId;
private:
- QString mSource;
- QList mRecordList;
+ QString mSource;
+ QList mRecordList;
};
}
diff --git a/backends/merge/None.cpp b/backends/merge/None.cpp
index 16ac7d4..f528eec 100644
--- a/backends/merge/None.cpp
+++ b/backends/merge/None.cpp
@@ -108,9 +108,9 @@ namespace glabels
///
/// Read next record
///
- Record* None::readNextRecord()
+ Record None::readNextRecord()
{
- return nullptr;
+ return NullRecord();
}
} // namespace merge
diff --git a/backends/merge/None.h b/backends/merge/None.h
index bbe17db..8a1480a 100644
--- a/backends/merge/None.h
+++ b/backends/merge/None.h
@@ -41,7 +41,7 @@ namespace glabels
public:
None();
None( const None* merge );
- ~None() override = default;
+ virtual ~None() = default;
/////////////////////////////////
@@ -67,7 +67,7 @@ namespace glabels
protected:
void open() override;
void close() override;
- Record* readNextRecord() override;
+ Record readNextRecord() override;
};
diff --git a/backends/merge/Record.cpp b/backends/merge/Record.cpp
index facab81..88aede0 100644
--- a/backends/merge/Record.cpp
+++ b/backends/merge/Record.cpp
@@ -26,32 +26,6 @@ namespace glabels
namespace merge
{
- ///
- /// Constructor
- ///
- Record::Record() : mSelected( true )
- {
- }
-
-
- ///
- /// Constructor
- ///
- Record::Record( const Record* record )
- : QMap(*record), mSelected(record->mSelected)
- {
- }
-
-
- ///
- /// Clone
- ///
- Record* Record::clone() const
- {
- return new Record( this );
- }
-
-
///
/// Is record selected?
///
diff --git a/backends/merge/Record.h b/backends/merge/Record.h
index 7b43ce8..248aa34 100644
--- a/backends/merge/Record.h
+++ b/backends/merge/Record.h
@@ -37,20 +37,6 @@ namespace glabels
class Record : public QMap
{
- /////////////////////////////////
- // Life Cycle
- /////////////////////////////////
- public:
- Record();
- Record( const Record* record );
-
-
- /////////////////////////////////
- // Object duplication
- /////////////////////////////////
- Record* clone() const;
-
-
/////////////////////////////////
// Properties
/////////////////////////////////
@@ -63,10 +49,12 @@ namespace glabels
// Private data
/////////////////////////////////
private:
- bool mSelected;
+ bool mSelected{ true };
};
+
+ using NullRecord = const Record;
}
}
diff --git a/backends/merge/Text.cpp b/backends/merge/Text.cpp
index 8c8eaf7..93406c5 100644
--- a/backends/merge/Text.cpp
+++ b/backends/merge/Text.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "Text.h"
#include "Record.h"
@@ -34,7 +35,10 @@ namespace glabels
/// Constructor
///
Text::Text( QChar delimiter, bool line1HasKeys )
- : mDelimeter(delimiter), mLine1HasKeys(line1HasKeys), mNFieldsMax(0)
+ : Merge(),
+ mDelimeter(delimiter),
+ mLine1HasKeys(line1HasKeys),
+ mNFieldsMax(0)
{
}
@@ -44,8 +48,10 @@ namespace glabels
///
Text::Text( const Text* merge )
: Merge( merge ),
- mDelimeter(merge->mDelimeter), mLine1HasKeys(merge->mLine1HasKeys),
- mKeys(merge->mKeys), mNFieldsMax(merge->mNFieldsMax)
+ mDelimeter(merge->mDelimeter),
+ mLine1HasKeys(merge->mLine1HasKeys),
+ mKeys(merge->mKeys),
+ mNFieldsMax(merge->mNFieldsMax)
{
}
@@ -115,24 +121,25 @@ namespace glabels
///
/// Read next record
///
- Record* Text::readNextRecord()
+ Record Text::readNextRecord()
{
QStringList values = parseLine();
if ( !values.isEmpty() )
{
- auto* record = new Record();
+ Record record;
int iField = 0;
- foreach ( QString value, values )
+ for ( const auto& value : values )
{
- (*record)[ keyFromIndex(iField) ] = value;
+ record[ keyFromIndex(iField) ] = value;
iField++;
}
mNFieldsMax = std::max( mNFieldsMax, iField );
return record;
}
- return nullptr;
+
+ return NullRecord();
}
diff --git a/backends/merge/Text.h b/backends/merge/Text.h
index b75030d..d9ee820 100644
--- a/backends/merge/Text.h
+++ b/backends/merge/Text.h
@@ -21,6 +21,7 @@
#ifndef merge_Text_h
#define merge_Text_h
+
#include "Merge.h"
#include
@@ -43,7 +44,7 @@ namespace glabels
protected:
Text( QChar delimiter, bool line1HasKeys );
Text( const Text* merge );
- ~Text() override = default;
+ virtual ~Text() = default;
/////////////////////////////////
@@ -55,7 +56,7 @@ namespace glabels
protected:
void open() override;
void close() override;
- Record* readNextRecord() override;
+ Record readNextRecord() override;
/////////////////////////////////
diff --git a/backends/merge/TextColon.h b/backends/merge/TextColon.h
index 5ea12d5..ba481f0 100644
--- a/backends/merge/TextColon.h
+++ b/backends/merge/TextColon.h
@@ -42,7 +42,7 @@ namespace glabels
private:
TextColon();
TextColon( const TextColon* merge );
- ~TextColon() override = default;
+ virtual ~TextColon() = default;
/////////////////////////////////
diff --git a/backends/merge/TextColonKeys.h b/backends/merge/TextColonKeys.h
index c5fce60..2abd194 100644
--- a/backends/merge/TextColonKeys.h
+++ b/backends/merge/TextColonKeys.h
@@ -42,7 +42,7 @@ namespace glabels
private:
TextColonKeys();
TextColonKeys( const TextColonKeys* merge );
- ~TextColonKeys() override = default;
+ virtual ~TextColonKeys() = default;
/////////////////////////////////
diff --git a/backends/merge/TextCsv.h b/backends/merge/TextCsv.h
index 3ac95e8..cc9df33 100644
--- a/backends/merge/TextCsv.h
+++ b/backends/merge/TextCsv.h
@@ -42,7 +42,7 @@ namespace glabels
private:
TextCsv();
TextCsv( const TextCsv* merge );
- ~TextCsv() override = default;
+ virtual ~TextCsv() = default;
/////////////////////////////////
diff --git a/backends/merge/TextCsvKeys.h b/backends/merge/TextCsvKeys.h
index 2f71219..7d68878 100644
--- a/backends/merge/TextCsvKeys.h
+++ b/backends/merge/TextCsvKeys.h
@@ -42,7 +42,7 @@ namespace glabels
private:
TextCsvKeys();
TextCsvKeys( const TextCsvKeys* merge );
- ~TextCsvKeys() override = default;
+ virtual ~TextCsvKeys() = default;
/////////////////////////////////
diff --git a/backends/merge/TextSemicolon.h b/backends/merge/TextSemicolon.h
index 9bf8b51..dba0e60 100644
--- a/backends/merge/TextSemicolon.h
+++ b/backends/merge/TextSemicolon.h
@@ -42,7 +42,7 @@ namespace glabels
private:
TextSemicolon();
TextSemicolon( const TextSemicolon* merge );
- ~TextSemicolon() override = default;
+ virtual ~TextSemicolon() = default;
/////////////////////////////////
diff --git a/backends/merge/TextSemicolonKeys.h b/backends/merge/TextSemicolonKeys.h
index 39d2079..e263094 100644
--- a/backends/merge/TextSemicolonKeys.h
+++ b/backends/merge/TextSemicolonKeys.h
@@ -42,7 +42,7 @@ namespace glabels
private:
TextSemicolonKeys();
TextSemicolonKeys( const TextSemicolonKeys* merge );
- ~TextSemicolonKeys() override = default;
+ virtual ~TextSemicolonKeys() = default;
/////////////////////////////////
diff --git a/backends/merge/TextTsv.h b/backends/merge/TextTsv.h
index 555ca6d..4cba8dd 100644
--- a/backends/merge/TextTsv.h
+++ b/backends/merge/TextTsv.h
@@ -42,7 +42,7 @@ namespace glabels
private:
TextTsv();
TextTsv( const TextTsv* merge );
- ~TextTsv() override = default;
+ virtual ~TextTsv() = default;
/////////////////////////////////
diff --git a/backends/merge/TextTsvKeys.h b/backends/merge/TextTsvKeys.h
index 7be33aa..86500cc 100644
--- a/backends/merge/TextTsvKeys.h
+++ b/backends/merge/TextTsvKeys.h
@@ -42,7 +42,7 @@ namespace glabels
private:
TextTsvKeys();
TextTsvKeys( const TextTsvKeys* merge );
- ~TextTsvKeys() override = default;
+ virtual ~TextTsvKeys() = default;
/////////////////////////////////
diff --git a/glabels-batch/main.cpp b/glabels-batch/main.cpp
index cc0ccbd..1b38679 100644
--- a/glabels-batch/main.cpp
+++ b/glabels-batch/main.cpp
@@ -22,7 +22,6 @@
#include "model/Db.h"
#include "model/Model.h"
#include "model/PageRenderer.h"
-#include "model/Settings.h"
#include "model/Version.h"
#include "model/XmlLabelParser.h"
@@ -188,7 +187,7 @@ int main( int argc, char **argv )
glabels::model::Model *model = glabels::model::XmlLabelParser::readFile( filename );
if ( model )
{
- model->variables()->setVariables( variableDefinitions );
+ model->variables().setVariables( variableDefinitions );
QPrinter printer( QPrinter::HighResolution );
printer.setColorMode( QPrinter::Color );
diff --git a/glabels/ColorButton.cpp b/glabels/ColorButton.cpp
index 0c6b1e5..bb71709 100644
--- a/glabels/ColorButton.cpp
+++ b/glabels/ColorButton.cpp
@@ -129,7 +129,7 @@ namespace glabels
void ColorButton::setKeys( const merge::Merge* merge,
- const model::Variables* variables )
+ const model::Variables& variables )
{
mDialog->setKeys( merge, variables );
}
diff --git a/glabels/ColorButton.h b/glabels/ColorButton.h
index bb634a0..c2af588 100644
--- a/glabels/ColorButton.h
+++ b/glabels/ColorButton.h
@@ -69,7 +69,7 @@ namespace glabels
model::ColorNode colorNode();
void setKeys( const merge::Merge* merge,
- const model::Variables* variables );
+ const model::Variables& variables );
/////////////////////////////////
diff --git a/glabels/ColorPaletteDialog.cpp b/glabels/ColorPaletteDialog.cpp
index 9b9cade..eabf386 100644
--- a/glabels/ColorPaletteDialog.cpp
+++ b/glabels/ColorPaletteDialog.cpp
@@ -197,7 +197,7 @@ namespace glabels
void ColorPaletteDialog::setKeys( const merge::Merge* merge,
- const model::Variables* variables )
+ const model::Variables& variables )
{
if (mFieldButton)
{
diff --git a/glabels/ColorPaletteDialog.h b/glabels/ColorPaletteDialog.h
index 6a04dd4..205982d 100644
--- a/glabels/ColorPaletteDialog.h
+++ b/glabels/ColorPaletteDialog.h
@@ -67,7 +67,7 @@ namespace glabels
void setColorNode( const model::ColorNode& colorNode );
void setKeys( const merge::Merge* merge,
- const model::Variables* variables );
+ const model::Variables& variables );
/////////////////////////////////
diff --git a/glabels/FieldButton.cpp b/glabels/FieldButton.cpp
index 8d50ae1..44adf07 100644
--- a/glabels/FieldButton.cpp
+++ b/glabels/FieldButton.cpp
@@ -44,7 +44,7 @@ namespace glabels
/// Set Keys
///
void FieldButton::setKeys( const merge::Merge* merge,
- const model::Variables* variables )
+ const model::Variables& variables )
{
// Clear old keys
mMenu.clear();
@@ -64,18 +64,18 @@ namespace glabels
// Add variable keys, if any
mMenu.addSection( tr("Variables") );
- for ( auto& key : variables->keys() )
+ for ( auto& key : variables.keys() )
{
auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) );
action->setData( key );
}
- if ( variables->keys().empty() )
+ if ( variables.keys().empty() )
{
auto* action = mMenu.addAction( "None" );
action->setEnabled( false );
}
- setEnabled( !merge->keys().empty() || !variables->keys().empty() );
+ setEnabled( !merge->keys().empty() || !variables.keys().empty() );
}
diff --git a/glabels/FieldButton.h b/glabels/FieldButton.h
index 251705d..3b08071 100644
--- a/glabels/FieldButton.h
+++ b/glabels/FieldButton.h
@@ -60,7 +60,7 @@ namespace glabels
/////////////////////////////////
public:
void setKeys( const merge::Merge* merge,
- const model::Variables* variables );
+ const model::Variables& variables );
/////////////////////////////////
diff --git a/glabels/File.cpp b/glabels/File.cpp
index 9f6e3a8..77c5a36 100644
--- a/glabels/File.cpp
+++ b/glabels/File.cpp
@@ -52,14 +52,14 @@ namespace glabels
SelectProductDialog dialog;
dialog.exec();
- const model::Template* tmplate = dialog.tmplate();
- if ( tmplate )
+ auto tmplate = dialog.tmplate();
+ if ( !tmplate.isNull() )
{
auto* model = new model::Model();
model->setTmplate( tmplate );
// Intelligently decide to rotate label by default
- const model::Frame* frame = tmplate->frames().first();
+ auto frame = tmplate.frame();
model->setRotate( frame->h() > frame->w() );
model->clearModified();
diff --git a/glabels/LabelEditor.cpp b/glabels/LabelEditor.cpp
index d489d75..f5b29fd 100644
--- a/glabels/LabelEditor.cpp
+++ b/glabels/LabelEditor.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "LabelEditor.h"
#include "Cursors.h"
@@ -38,10 +39,10 @@
#include "model/Markup.h"
#include "model/Settings.h"
+#include
#include
#include
#include
-#include
namespace glabels
@@ -95,12 +96,12 @@ namespace glabels
mState = IdleState;
- mSelectRegionVisible = false;
- mResizeObject = nullptr;
- mResizeHandle = nullptr;
- mResizeHonorAspect = false;
- mCreateObjectType = Box;
- mCreateObject = nullptr;
+ mSelectRegionVisible = false;
+ mResizeObject = nullptr;
+ mResizeHandleLocation = model::Handle::NULL_HANDLE;
+ mResizeHonorAspect = false;
+ mCreateObjectType = Box;
+ mCreateObject = nullptr;
setMouseTracking( true );
setFocusPolicy(Qt::StrongFocus);
@@ -459,15 +460,15 @@ namespace glabels
case IdleState:
{
model::ModelObject* object = nullptr;
- model::Handle* handle = nullptr;
- if ( mModel->isSelectionAtomic() &&
- (handle = mModel->handleAt( mScale, xWorld, yWorld )) != nullptr )
+ auto& handle = mModel->handleAt( mScale, xWorld, yWorld );
+
+ if ( mModel->isSelectionAtomic() && !handle.isNull() )
{
//
// Start an object resize
//
- mResizeObject = handle->owner();
- mResizeHandle = handle;
+ mResizeObject = handle.owner();
+ mResizeHandleLocation = handle.location();
mResizeHonorAspect = event->modifiers() & Qt::ControlModifier;
if ( mResizeObject->lockAspectRatio() )
{
@@ -632,7 +633,7 @@ namespace glabels
case IdleState:
if ( mModel->isSelectionAtomic() &&
- mModel->handleAt( mScale, xWorld, yWorld ) )
+ !mModel->handleAt( mScale, xWorld, yWorld ).isNull() )
{
setCursor( Qt::CrossCursor );
}
@@ -796,11 +797,10 @@ namespace glabels
/// Handle resize motion
///
void
- LabelEditor::handleResizeMotion( const model::Distance& xWorld,
- const model::Distance& yWorld )
+ LabelEditor::handleResizeMotion( model::Distance xWorld,
+ model::Distance yWorld )
{
QPointF p( xWorld.pt(), yWorld.pt() );
- model::Handle::Location location = mResizeHandle->location();
/*
* Change point to object relative coordinates
@@ -824,7 +824,7 @@ namespace glabels
* Calculate new size
*/
double w, h;
- switch ( location )
+ switch ( mResizeHandleLocation )
{
case model::Handle::NW:
w = std::max( x2 - p.x(), 0.0 );
@@ -879,11 +879,11 @@ namespace glabels
/*
* Set size
*/
- if ( !(location == model::Handle::P1) && !(location == model::Handle::P2) )
+ if ( !(mResizeHandleLocation == model::Handle::P1) && !(mResizeHandleLocation == model::Handle::P2) )
{
if ( mResizeHonorAspect )
{
- switch ( location )
+ switch ( mResizeHandleLocation )
{
case model::Handle::E:
case model::Handle::W:
@@ -908,7 +908,7 @@ namespace glabels
/*
* Adjust origin, if needed.
*/
- switch ( location )
+ switch ( mResizeHandleLocation )
{
case model::Handle::NW:
x0 += x2 - mResizeObject->w().pt();
@@ -1227,9 +1227,9 @@ namespace glabels
painter->translate( -mModel->frame()->w().pt(), 0 );
}
- foreach( model::Markup* markup, mModel->frame()->markups() )
+ for( auto& markup : mModel->frame()->markups() )
{
- painter->drawPath( markup->path( mModel->frame() ) );
+ painter->drawPath( markup->path( *mModel->frame() ) );
}
painter->restore();
@@ -1243,7 +1243,7 @@ namespace glabels
void
LabelEditor::drawObjectsLayer( QPainter* painter )
{
- mModel->draw( painter, true, nullptr, nullptr );
+ mModel->draw( painter, true, merge::NullRecord(), model::Variables() );
}
diff --git a/glabels/LabelEditor.h b/glabels/LabelEditor.h
index 0e31d1b..1f3bfb9 100644
--- a/glabels/LabelEditor.h
+++ b/glabels/LabelEditor.h
@@ -22,7 +22,7 @@
#define LabelEditor_h
-#include "model/Handles.h"
+#include "model/Handle.h"
#include "model/Model.h"
#include "model/ModelObject.h"
#include "model/Region.h"
@@ -135,8 +135,8 @@ namespace glabels
// Private methods
/////////////////////////////////////
private:
- void handleResizeMotion( const model::Distance& xWorld,
- const model::Distance& yWorld );
+ void handleResizeMotion( model::Distance xWorld,
+ model::Distance yWorld );
void drawBgLayer( QPainter* painter );
void drawGridLayer( QPainter* painter );
@@ -205,9 +205,9 @@ namespace glabels
model::Distance mMoveLastY;
/* ArrowResize state */
- model::ModelObject* mResizeObject;
- model::Handle* mResizeHandle;
- bool mResizeHonorAspect;
+ model::ModelObject* mResizeObject;
+ model::Handle::Location mResizeHandleLocation;
+ bool mResizeHonorAspect;
/* CreateDrag state */
CreateType mCreateObjectType;
diff --git a/glabels/MainWindow.cpp b/glabels/MainWindow.cpp
index ec2b9f6..e40e4ab 100644
--- a/glabels/MainWindow.cpp
+++ b/glabels/MainWindow.cpp
@@ -29,7 +29,6 @@
#include "PrintView.h"
#include "PropertiesView.h"
#include "StartupView.h"
-#include "UndoRedoModel.h"
#include "VariablesView.h"
#include "model/Db.h"
@@ -63,7 +62,7 @@ namespace glabels
///
/// Constructor
///
- MainWindow::MainWindow() : mModel(nullptr), mUndoRedoModel(nullptr)
+ MainWindow::MainWindow()
{
setWindowIcon( QIcon::fromTheme( "glabels" ) );
@@ -204,30 +203,12 @@ namespace glabels
}
- ///
- /// Destructor
- ///
- MainWindow::~MainWindow()
- {
- if ( mUndoRedoModel )
- {
- delete mUndoRedoModel;
- }
- if ( mModel )
- {
- delete mModel->merge(); // Ownership of final Merge instance is ours
- delete mModel->variables(); // Ownership of Variables instance is ours
- delete mModel;
- }
- }
-
-
///
/// Get model accessor
///
model::Model* MainWindow::model() const
{
- return mModel;
+ return mModel.get();
}
@@ -236,15 +217,15 @@ namespace glabels
///
void MainWindow::setModel( model::Model* model )
{
- mModel = model; // Ownership passes to us
- mUndoRedoModel = new UndoRedoModel( mModel );
+ mModel.reset( model );
+ mUndoRedoModel = std::make_unique( mModel.get() );
- mPropertiesView->setModel( mModel, mUndoRedoModel );
- mLabelEditor->setModel( mModel, mUndoRedoModel );
- mObjectEditor->setModel( mModel, mUndoRedoModel );
- mMergeView->setModel( mModel, mUndoRedoModel );
- mVariablesView->setModel( mModel, mUndoRedoModel );
- mPrintView->setModel( mModel );
+ mPropertiesView->setModel( mModel.get(), mUndoRedoModel.get() );
+ mLabelEditor->setModel( mModel.get(), mUndoRedoModel.get() );
+ mObjectEditor->setModel( mModel.get(), mUndoRedoModel.get() );
+ mMergeView->setModel( mModel.get(), mUndoRedoModel.get() );
+ mVariablesView->setModel( mModel.get(), mUndoRedoModel.get() );
+ mPrintView->setModel( mModel.get() );
mEditorButton->setChecked( true );
mPages->setCurrentIndex( EDITOR_PAGE_INDEX );
@@ -253,11 +234,11 @@ namespace glabels
setTitle();
connect( mLabelEditor, SIGNAL(contextMenuActivate(model::Point)), this, SLOT(onContextMenuActivate(model::Point)) );
- connect( mModel, SIGNAL(nameChanged()), this, SLOT(onNameChanged()) );
- connect( mModel, SIGNAL(modifiedChanged()), this, SLOT(onModifiedChanged()) );
- connect( mModel, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()) );
- connect( mModel, SIGNAL(changed()), this, SLOT(onLabelChanged()) );
- connect( mUndoRedoModel, SIGNAL(changed()), this, SLOT(onUndoRedoChanged()) );
+ connect( mModel.get(), SIGNAL(nameChanged()), this, SLOT(onNameChanged()) );
+ connect( mModel.get(), SIGNAL(modifiedChanged()), this, SLOT(onModifiedChanged()) );
+ connect( mModel.get(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()) );
+ connect( mModel.get(), SIGNAL(changed()), this, SLOT(onLabelChanged()) );
+ connect( mUndoRedoModel.get(), SIGNAL(changed()), this, SLOT(onUndoRedoChanged()) );
}
@@ -266,7 +247,7 @@ namespace glabels
///
bool MainWindow::isEmpty() const
{
- return mModel == nullptr;
+ return !mModel;
}
@@ -1032,7 +1013,7 @@ namespace glabels
///
void MainWindow::setTitle()
{
- if ( mModel == nullptr )
+ if ( !mModel )
{
setWindowTitle( "gLabels" );
}
diff --git a/glabels/MainWindow.h b/glabels/MainWindow.h
index d2a2807..9c84f85 100644
--- a/glabels/MainWindow.h
+++ b/glabels/MainWindow.h
@@ -21,6 +21,9 @@
#ifndef MainWindow_h
#define MainWindow_h
+
+#include "UndoRedoModel.h"
+
#include
#include
@@ -35,6 +38,8 @@
#include
#include
+#include
+
namespace glabels
{
@@ -46,7 +51,6 @@ namespace glabels
class PrintView;
class PropertiesView;
class StartupView;
- class UndoRedoModel;
class VariablesView;
@@ -63,7 +67,7 @@ namespace glabels
/////////////////////////////////////
public:
MainWindow();
- ~MainWindow() override;
+ virtual ~MainWindow() = default;
/////////////////////////////////////
@@ -194,8 +198,17 @@ namespace glabels
/////////////////////////////////////
// Private Data
+ // owned and managed by us
/////////////////////////////////////
private:
+ std::unique_ptr mModel;
+ std::unique_ptr mUndoRedoModel;
+
+
+ /////////////////////////////////////
+ // Private Data
+ // owned by QMainWindow
+ /////////////////////////////////////
QMenu* fileMenu;
QMenu* fileRecentMenu;
QMenu* editMenu;
@@ -219,9 +232,6 @@ namespace glabels
QToolBar* fileToolBar;
QToolBar* editorToolBar;
- model::Model* mModel;
- UndoRedoModel* mUndoRedoModel;
-
QToolBar* mContents;
QToolButton* mWelcomeButton;
QToolButton* mEditorButton;
diff --git a/glabels/MergeView.cpp b/glabels/MergeView.cpp
index 3edb3e1..6bf6d56 100644
--- a/glabels/MergeView.cpp
+++ b/glabels/MergeView.cpp
@@ -18,15 +18,16 @@
* along with gLabels-qt. If not, see .
*/
+
#include "MergeView.h"
#include "merge/Factory.h"
#include "model/FileUtil.h"
+#include
#include
#include
-#include
namespace glabels
@@ -48,15 +49,6 @@ namespace glabels
}
- ///
- /// Destructor
- ///
- MergeView::~MergeView()
- {
- // empty
- }
-
-
///
/// Set Model
///
@@ -144,13 +136,13 @@ namespace glabels
{
mBlock = true; // Don't recurse
- const QList& records = mModel->merge()->recordList();
+ auto& records = mModel->merge()->recordList();
int iRow = 0;
- foreach ( merge::Record* record, records )
+ for ( auto& record : records )
{
QTableWidgetItem* item = recordsTable->item( iRow, 0 );
- item->setCheckState( record->isSelected() ? Qt::Checked : Qt::Unchecked );
+ item->setCheckState( record.isSelected() ? Qt::Checked : Qt::Unchecked );
iRow++;
}
@@ -274,33 +266,33 @@ namespace glabels
{
mBlock = true;
- const QList& records = merge->recordList();
+ auto& records = merge->recordList();
recordsTable->setRowCount( records.size() );
int iRow = 0;
- foreach ( merge::Record* record, records )
+ for ( auto record : records )
{
// First column for primary field
auto* item = new QTableWidgetItem();
- if ( record->contains( mPrimaryKey ) )
+ if ( record.contains( mPrimaryKey ) )
{
- auto text = printableTextForView( (*record)[mPrimaryKey] );
+ auto text = printableTextForView( record[mPrimaryKey] );
item->setText( text );
}
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable );
- item->setCheckState( record->isSelected() ? Qt::Checked : Qt::Unchecked );
+ item->setCheckState( record.isSelected() ? Qt::Checked : Qt::Unchecked );
recordsTable->setItem( iRow, 0, item );
recordsTable->resizeColumnToContents( 0 );
// Starting on 2nd column, 1 column per field, skip primary field
int iCol = 1;
- foreach ( QString key, mKeys )
+ for ( auto& key : mKeys )
{
if ( key != mPrimaryKey )
{
- if ( record->contains( key ) )
+ if ( record.contains( key ) )
{
- auto text = printableTextForView( (*record)[key] );
+ auto text = printableTextForView( record[key] );
auto* item = new QTableWidgetItem( text );
item->setFlags( Qt::ItemIsEnabled );
recordsTable->setItem( iRow, iCol, item );
diff --git a/glabels/MergeView.h b/glabels/MergeView.h
index 3a259f6..32e3395 100644
--- a/glabels/MergeView.h
+++ b/glabels/MergeView.h
@@ -49,7 +49,7 @@ namespace glabels
/////////////////////////////////
public:
MergeView( QWidget *parent = nullptr );
- ~MergeView() override;
+ virtual ~MergeView() = default;
/////////////////////////////////
diff --git a/glabels/MiniPreviewPixmap.cpp b/glabels/MiniPreviewPixmap.cpp
index 49ca63a..2c74e58 100644
--- a/glabels/MiniPreviewPixmap.cpp
+++ b/glabels/MiniPreviewPixmap.cpp
@@ -49,14 +49,14 @@ namespace glabels
}
- MiniPreviewPixmap::MiniPreviewPixmap( const model::Template* tmplate, int width, int height )
+ MiniPreviewPixmap::MiniPreviewPixmap( const model::Template& tmplate, int width, int height )
: QPixmap( width, height )
{
draw( tmplate, width, height );
}
- void MiniPreviewPixmap::draw( const model::Template* tmplate, int width, int height )
+ void MiniPreviewPixmap::draw( const model::Template& tmplate, int width, int height )
{
fill( Qt::transparent );
@@ -66,11 +66,11 @@ namespace glabels
painter.setRenderHint( QPainter::Antialiasing, true );
// For "Roll" templates, allow extra room for tape width and continuation break lines
- model::Distance drawWidth = tmplate->pageWidth();
- model::Distance drawHeight = tmplate->pageHeight();
- if ( tmplate->isRoll() )
+ model::Distance drawWidth = tmplate.pageWidth();
+ model::Distance drawHeight = tmplate.pageHeight();
+ if ( tmplate.isRoll() )
{
- drawWidth = tmplate->rollWidth();
+ drawWidth = tmplate.rollWidth();
drawHeight *= 1.2;
}
@@ -87,8 +87,8 @@ namespace glabels
}
painter.scale( scale, scale );
- model::Distance xOffset = ( model::Distance::pt(width/scale) - tmplate->pageWidth() ) / 2;
- model::Distance yOffset = ( model::Distance::pt(height/scale) - tmplate->pageHeight() ) / 2;
+ model::Distance xOffset = ( model::Distance::pt(width/scale) - tmplate.pageWidth() ) / 2;
+ model::Distance yOffset = ( model::Distance::pt(height/scale) - tmplate.pageHeight() ) / 2;
painter.translate( xOffset.pt(), yOffset.pt() );
drawPaper( painter, tmplate, scale );
@@ -96,7 +96,7 @@ namespace glabels
}
- void MiniPreviewPixmap::drawPaper( QPainter& painter, const model::Template* tmplate, double scale )
+ void MiniPreviewPixmap::drawPaper( QPainter& painter, const model::Template& tmplate, double scale )
{
QBrush brush( paperColor );
QPen pen( paperOutlineColor );
@@ -107,9 +107,9 @@ namespace glabels
painter.setBrush( brush );
painter.setPen( pen );
- if ( !tmplate->isRoll() )
+ if ( !tmplate.isRoll() )
{
- painter.drawRect( 0, 0, tmplate->pageWidth().pt(), tmplate->pageHeight().pt() );
+ painter.drawRect( 0, 0, tmplate.pageWidth().pt(), tmplate.pageHeight().pt() );
}
else
{
@@ -120,7 +120,7 @@ namespace glabels
}
- void MiniPreviewPixmap::drawLabelOutlines( QPainter& painter, const model::Template* tmplate, double scale )
+ void MiniPreviewPixmap::drawLabelOutlines( QPainter& painter, const model::Template& tmplate, double scale )
{
QBrush brush( labelColor );
QPen pen( labelOutlineColor );
@@ -131,10 +131,8 @@ namespace glabels
painter.setBrush( brush );
painter.setPen( pen );
- model::Frame *frame = tmplate->frames().first();
- QVector origins = frame->getOrigins();
-
- foreach ( model::Point p0, origins )
+ auto frame = tmplate.frame();
+ for ( model::Point p0 : frame->getOrigins() )
{
drawLabelOutline( painter, frame, p0 );
}
diff --git a/glabels/MiniPreviewPixmap.h b/glabels/MiniPreviewPixmap.h
index 18566e8..27bc052 100644
--- a/glabels/MiniPreviewPixmap.h
+++ b/glabels/MiniPreviewPixmap.h
@@ -39,13 +39,13 @@ namespace glabels
public:
MiniPreviewPixmap();
- MiniPreviewPixmap( const model::Template* tmplate, int width, int height );
+ MiniPreviewPixmap( const model::Template& tmplate, int width, int height );
private:
- void draw( const model::Template* tmplate, int width, int height );
- void drawPaper( QPainter& painter, const model::Template* tmplate, double scale );
- void drawLabelOutlines( QPainter& painter, const model::Template* tmplate, double scale );
+ void draw( const model::Template& tmplate, int width, int height );
+ void drawPaper( QPainter& painter, const model::Template& tmplate, double scale );
+ void drawLabelOutlines( QPainter& painter, const model::Template& tmplate, double scale );
void drawLabelOutline( QPainter& painter, const model::Frame *frame, const model::Point& point0 );
};
diff --git a/glabels/Preview.cpp b/glabels/Preview.cpp
index 8528ffa..909507c 100644
--- a/glabels/Preview.cpp
+++ b/glabels/Preview.cpp
@@ -97,18 +97,18 @@ namespace glabels
auto tmplate = mModel->tmplate();
// For "Roll" templates, allow extra room to draw continuation break lines.
- model::Distance drawHeight = mModel->tmplate()->pageHeight();
+ model::Distance drawHeight = mModel->tmplate().pageHeight();
model::Distance drawOffset = 0;
- if ( tmplate->isRoll() )
+ if ( tmplate.isRoll() )
{
- drawHeight = 1.2 * tmplate->pageHeight();
- drawOffset = 0.1 * tmplate->pageHeight();
+ drawHeight = 1.2 * tmplate.pageHeight();
+ drawOffset = 0.1 * tmplate.pageHeight();
}
// Set scene up with a 5% margin around paper
- model::Distance x = -0.05 * tmplate->pageWidth();
+ model::Distance x = -0.05 * tmplate.pageWidth();
model::Distance y = -0.05 * drawHeight - drawOffset;
- model::Distance w = 1.10 * tmplate->pageWidth();
+ model::Distance w = 1.10 * tmplate.pageWidth();
model::Distance h = 1.10 * drawHeight;
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
@@ -121,11 +121,15 @@ namespace glabels
}
}
- void Preview::drawLabelNumberOverlaySingle(const model::Distance& x, const model::Distance& y, const QPainterPath& path, uint32_t labelInstance)
+
+ void Preview::drawLabelNumberOverlaySingle( model::Distance x,
+ model::Distance y,
+ const QPainterPath& path,
+ uint32_t labelInstance)
{
QBrush brush( labelNumberColor );
- model::Frame *frame = mModel->tmplate()->frames().first();
+ auto frame = mModel->tmplate().frame();
model::Distance w = frame->w();
model::Distance h = frame->h();
@@ -143,18 +147,20 @@ namespace glabels
mScene->addItem( labelNumberItem );
}
+
void Preview::drawLabelNumberOverlay()
{
- model::Frame *frame = mModel->tmplate()->frames().first();
+ auto frame = mModel->tmplate().frame();
auto i = 0;
- foreach (model::Point origin, frame->getOrigins() )
+ for ( model::Point origin : frame->getOrigins() )
{
i++;
drawLabelNumberOverlaySingle( origin.x(), origin.y(), frame->path(), i);
}
}
+
///
/// Resize Event Handler
///
@@ -181,9 +187,9 @@ namespace glabels
QAbstractGraphicsShapeItem* pageItem;
auto tmplate = mModel->tmplate();
- if ( !tmplate->isRoll() )
+ if ( !tmplate.isRoll() )
{
- pageItem = new QGraphicsRectItem( 0, 0, tmplate->pageWidth().pt(), tmplate->pageHeight().pt() );
+ pageItem = new QGraphicsRectItem( 0, 0, tmplate.pageWidth().pt(), tmplate.pageHeight().pt() );
}
else
{
@@ -202,9 +208,9 @@ namespace glabels
///
void Preview::drawLabels()
{
- model::Frame *frame = mModel->tmplate()->frames().first();
+ auto frame = mModel->tmplate().frame();
- foreach (model::Point origin, frame->getOrigins() )
+ for ( model::Point origin : frame->getOrigins() )
{
drawLabel( origin.x(), origin.y(), frame->path() );
}
@@ -214,7 +220,9 @@ namespace glabels
///
/// Draw a Single Label at x,y
///
- void Preview::drawLabel( const model::Distance& x, const model::Distance& y, const QPainterPath& path )
+ void Preview::drawLabel( model::Distance x,
+ model::Distance y,
+ const QPainterPath& path )
{
QBrush brush( labelColor );
QPen pen( labelOutlineColor );
diff --git a/glabels/Preview.h b/glabels/Preview.h
index 8e95deb..a9cab1d 100644
--- a/glabels/Preview.h
+++ b/glabels/Preview.h
@@ -70,11 +70,16 @@ namespace glabels
private:
void drawPaper();
void drawLabels();
- void drawLabel( const model::Distance& x, const model::Distance& y, const QPainterPath& path );
+ void drawLabel( model::Distance x,
+ model::Distance y,
+ const QPainterPath& path );
void drawPreviewOverlay();
- void drawLabelNumberOverlaySingle(const model::Distance& x, const model::Distance& y, const QPainterPath& path, uint32_t labelInstance);
+ void drawLabelNumberOverlaySingle( model::Distance x,
+ model::Distance y,
+ const QPainterPath& path,
+ uint32_t labelInstance);
void drawLabelNumberOverlay();
diff --git a/glabels/PropertiesView.cpp b/glabels/PropertiesView.cpp
index 3203ccb..798cc25 100644
--- a/glabels/PropertiesView.cpp
+++ b/glabels/PropertiesView.cpp
@@ -60,15 +60,6 @@ namespace glabels
}
- ///
- /// Destructor
- ///
- PropertiesView::~PropertiesView()
- {
- // empty
- }
-
-
///
/// Set Model
///
@@ -101,41 +92,41 @@ namespace glabels
///
void PropertiesView::onLabelSizeChanged()
{
- auto* tmplate = mModel->tmplate();
- auto* frame = tmplate->frames().first();
- bool isRotated = mModel->rotate();
+ auto tmplate = mModel->tmplate();
+ auto frame = tmplate.frame();
+ bool isRotated = mModel->rotate();
preview->setTemplate( tmplate );
preview->setShowArrow( true );
preview->setRotate( isRotated );
- const model::Vendor* vendor = model::Db::lookupVendorFromName( tmplate->brand() );
- if ( (vendor != nullptr) && (vendor->url() != nullptr) )
+ vendorLabel->setText( tmplate.brand() );
+ if ( model::Db::isVendorNameKnown( tmplate.brand() ) )
{
- QString markup = QString( "%2" ).arg( vendor->url(), vendor->name() );
- vendorLabel->setText( markup );
- }
- else
- {
- vendorLabel->setText( tmplate->brand() );
+ auto vendor = model::Db::lookupVendorFromName( tmplate.brand() );
+ if ( !vendor.url().isEmpty() )
+ {
+ QString markup = QString( "%2" ).arg( vendor.url(), vendor.name() );
+ vendorLabel->setText( markup );
+ }
}
- if ( tmplate->productUrl() != nullptr )
+ if ( !tmplate.productUrl().isEmpty() )
{
- QString markup = QString( "%2" ).arg( tmplate->productUrl(), tmplate->part() );
+ QString markup = QString( "%2" ).arg( tmplate.productUrl(), tmplate.part() );
partLabel->setText( markup );
}
else
{
- partLabel->setText( tmplate->part() );
+ partLabel->setText( tmplate.part() );
}
- descriptionLabel->setText( tmplate->description() );
- pageSizeLabel->setText( tmplate->paperDescription( mUnits ) );
+ descriptionLabel->setText( tmplate.description() );
+ pageSizeLabel->setText( tmplate.paperDescription( mUnits ) );
labelSizeLabel->setText( frame->sizeDescription( mUnits ) );
layoutLabel->setText( frame->layoutDescription() );
- QStringList list = model::Db::getNameListOfSimilarTemplates( tmplate->name() );
+ QStringList list = model::Db::getNameListOfSimilarTemplates( tmplate.name() );
if ( list.isEmpty() )
{
similarProductsGroupBox->hide();
@@ -208,8 +199,8 @@ namespace glabels
///
void PropertiesView::onOrientationActivated()
{
- const model::Template* tmplate = mModel->tmplate();
- const model::Frame* frame = tmplate->frames().first();
+ auto tmplate = mModel->tmplate();
+ auto frame = tmplate.frame();
// Make sure index actually changed.
int index = orientationCombo->currentIndex();
@@ -243,15 +234,15 @@ namespace glabels
SelectProductDialog selectProductDialog( this );
selectProductDialog.exec();
- const model::Template* tmplate = selectProductDialog.tmplate();
- if ( tmplate )
+ auto tmplate = selectProductDialog.tmplate();
+ if ( !tmplate.isNull() )
{
mUndoRedoModel->checkpoint( tr("Change Product") );
mModel->setTmplate( tmplate );
// Don't rotate circular or round labels
- const model::Frame *frame = tmplate->frames().first();
+ auto frame = tmplate.frame();
if ( frame->w() == frame->h() )
{
mModel->setRotate( false );
diff --git a/glabels/PropertiesView.h b/glabels/PropertiesView.h
index 8d375d1..e7dbaae 100644
--- a/glabels/PropertiesView.h
+++ b/glabels/PropertiesView.h
@@ -48,7 +48,7 @@ namespace glabels
/////////////////////////////////
public:
PropertiesView( QWidget *parent = nullptr );
- ~PropertiesView() override;
+ virtual ~PropertiesView() = default;
/////////////////////////////////
diff --git a/glabels/RollTemplatePath.cpp b/glabels/RollTemplatePath.cpp
index e1fcc17..9eed2b8 100644
--- a/glabels/RollTemplatePath.cpp
+++ b/glabels/RollTemplatePath.cpp
@@ -29,16 +29,16 @@ namespace glabels
///
/// Constructor
///
- RollTemplatePath::RollTemplatePath( const model::Template* tmplate )
+ RollTemplatePath::RollTemplatePath( const model::Template& tmplate )
{
- if ( !tmplate->isRoll() )
+ if ( !tmplate.isRoll() )
{
qWarning() << "Not a \"Roll\" template type.";
}
- model::Distance x0 = (tmplate->pageWidth() - tmplate->rollWidth()) / 2.0;
- model::Distance w = tmplate->rollWidth();
- model::Distance h = tmplate->pageHeight();
+ model::Distance x0 = (tmplate.pageWidth() - tmplate.rollWidth()) / 2.0;
+ model::Distance w = tmplate.rollWidth();
+ model::Distance h = tmplate.pageHeight();
model::Distance c = 0.07*h;
model::Distance b = 0.03*h;
diff --git a/glabels/RollTemplatePath.h b/glabels/RollTemplatePath.h
index e637469..3a76c6b 100644
--- a/glabels/RollTemplatePath.h
+++ b/glabels/RollTemplatePath.h
@@ -39,7 +39,7 @@ namespace glabels
// Life Cycle
/////////////////////////////////
public:
- RollTemplatePath( const model::Template* tmplate );
+ RollTemplatePath( const model::Template& tmplate );
};
diff --git a/glabels/SelectProductDialog.cpp b/glabels/SelectProductDialog.cpp
index f33df5e..200676c 100644
--- a/glabels/SelectProductDialog.cpp
+++ b/glabels/SelectProductDialog.cpp
@@ -52,15 +52,15 @@ namespace glabels
categoriesCheckContainer->setEnabled( !model::Settings::searchAllCategories() );
mCategoryIdList = model::Settings::searchCategoryList();
- QList categories = model::Db::categories();
- foreach ( model::Category *category, categories )
+ auto categories = model::Db::categories();
+ for ( auto& category : categories )
{
- QCheckBox* check = new QCheckBox( category->name() );
- check->setChecked( mCategoryIdList.contains( category->id() ) );
+ QCheckBox* check = new QCheckBox( category.name() );
+ check->setChecked( mCategoryIdList.contains( category.id() ) );
categoriesLayout->addWidget( check );
mCheckList.append( check );
- mCheckToCategoryMap[check] = category->id();
+ mCheckToCategoryMap[check] = category.id();
connect( check, SIGNAL(clicked()), this, SLOT(onCategoryCheckClicked()) );
}
@@ -78,7 +78,7 @@ namespace glabels
viewModeButton->setToolTip( tr( "Grid View" ) );
}
- QList tmplates = model::Db::templates();
+ auto tmplates = model::Db::templates();
templatePicker->setTemplates( tmplates );
if ( model::Settings::recentTemplateList().count() > 0 )
@@ -93,7 +93,7 @@ namespace glabels
///
/// Get selected template
///
- const model::Template* SelectProductDialog::tmplate() const
+ model::Template SelectProductDialog::tmplate() const
{
if ( mHasSelection )
{
@@ -101,7 +101,7 @@ namespace glabels
}
else
{
- return nullptr;
+ return model::Template();
}
}
@@ -229,41 +229,41 @@ namespace glabels
///
void SelectProductDialog::onTemplatePickerSelectionChanged()
{
- auto* tmplate = templatePicker->selectedTemplate();
- if ( !tmplate )
+ auto tmplate = templatePicker->selectedTemplate();
+ if ( tmplate.isNull() )
{
productInfoWidget->setVisible( false );
selectButton->setEnabled( false );
return;
}
- auto* frame = tmplate->frames().first();
+ auto frame = tmplate.frame();
preview->setTemplate( tmplate );
- const model::Vendor* vendor = model::Db::lookupVendorFromName( tmplate->brand() );
- if ( (vendor != nullptr) && (vendor->url() != nullptr) )
+ vendorLabel->setText( tmplate.brand() );
+ if ( model::Db::isVendorNameKnown( tmplate.brand() ) )
{
- QString markup = QString( "%2" ).arg( vendor->url(), vendor->name() );
- vendorLabel->setText( markup );
- }
- else
- {
- vendorLabel->setText( tmplate->brand() );
+ auto vendor = model::Db::lookupVendorFromName( tmplate.brand() );
+ if ( !vendor.url().isEmpty() )
+ {
+ QString markup = QString( "%2" ).arg( vendor.url(), vendor.name() );
+ vendorLabel->setText( markup );
+ }
}
- if ( tmplate->productUrl() != nullptr )
+ if ( !tmplate.productUrl().isEmpty() )
{
- QString markup = QString( "%2" ).arg( tmplate->productUrl(), tmplate->part() );
+ QString markup = QString( "%2" ).arg( tmplate.productUrl(), tmplate.part() );
partLabel->setText( markup );
}
else
{
- partLabel->setText( tmplate->part() );
+ partLabel->setText( tmplate.part() );
}
- descriptionLabel->setText( tmplate->description() );
- pageSizeLabel->setText( tmplate->paperDescription( model::Settings::units() ) );
+ descriptionLabel->setText( tmplate.description() );
+ pageSizeLabel->setText( tmplate.paperDescription( model::Settings::units() ) );
labelSizeLabel->setText( frame->sizeDescription( model::Settings::units() ) );
layoutLabel->setText( frame->layoutDescription() );
diff --git a/glabels/SelectProductDialog.h b/glabels/SelectProductDialog.h
index dbcf89e..173db91 100644
--- a/glabels/SelectProductDialog.h
+++ b/glabels/SelectProductDialog.h
@@ -46,7 +46,7 @@ namespace glabels
/////////////////////////////////
// Accessors
/////////////////////////////////
- const model::Template* tmplate() const;
+ model::Template tmplate() const;
/////////////////////////////////
diff --git a/glabels/SimplePreview.cpp b/glabels/SimplePreview.cpp
index b108e1d..a16a7ac 100644
--- a/glabels/SimplePreview.cpp
+++ b/glabels/SimplePreview.cpp
@@ -78,7 +78,7 @@ namespace glabels
///
/// Template Property Setter
///
- void SimplePreview::setTemplate( const model::Template *tmplate )
+ void SimplePreview::setTemplate( const model::Template& tmplate )
{
mTmplate = tmplate;
update();
@@ -121,21 +121,21 @@ namespace glabels
{
mScene->clear();
- if ( mTmplate != nullptr )
+ if ( !mTmplate.isNull() )
{
// For "Roll" templates, allow extra room to draw continuation break lines.
- model::Distance drawHeight = mTmplate->pageHeight();
+ model::Distance drawHeight = mTmplate.pageHeight();
model::Distance drawOffset = 0;
- if ( mTmplate->isRoll() )
+ if ( mTmplate.isRoll() )
{
- drawHeight = 1.2 * mTmplate->pageHeight();
- drawOffset = 0.1 * mTmplate->pageHeight();
+ drawHeight = 1.2 * mTmplate.pageHeight();
+ drawOffset = 0.1 * mTmplate.pageHeight();
}
// Set scene up with a 5% margin around paper
- model::Distance x = -0.05 * mTmplate->pageWidth();
+ model::Distance x = -0.05 * mTmplate.pageWidth();
model::Distance y = -0.05 * drawHeight - drawOffset;
- model::Distance w = 1.10 * mTmplate->pageWidth();
+ model::Distance w = 1.10 * mTmplate.pageWidth();
model::Distance h = 1.10 * drawHeight;
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
@@ -167,9 +167,9 @@ namespace glabels
pen.setWidthF( paperOutlineWidthPixels );
QAbstractGraphicsShapeItem* pageItem;
- if ( !mTmplate->isRoll() )
+ if ( !mTmplate.isRoll() )
{
- pageItem = new QGraphicsRectItem( 0, 0, mTmplate->pageWidth().pt(), mTmplate->pageHeight().pt() );
+ pageItem = new QGraphicsRectItem( 0, 0, mTmplate.pageWidth().pt(), mTmplate.pageHeight().pt() );
}
else
{
@@ -188,9 +188,9 @@ namespace glabels
///
void SimplePreview::drawLabels()
{
- model::Frame *frame = mTmplate->frames().first();
+ auto frame = mTmplate.frame();
- foreach (model::Point origin, frame->getOrigins() )
+ for ( model::Point origin : frame->getOrigins() )
{
drawLabel( origin.x(), origin.y(), frame->path() );
}
@@ -200,9 +200,9 @@ namespace glabels
///
/// Draw a Single Label at x,y
///
- void SimplePreview::drawLabel( const model::Distance& x,
- const model::Distance& y,
- const QPainterPath& path )
+ void SimplePreview::drawLabel( model::Distance x,
+ model::Distance y,
+ const QPainterPath& path )
{
QBrush brush( labelColor );
QPen pen( labelOutlineColor );
@@ -223,7 +223,7 @@ namespace glabels
///
void SimplePreview::drawArrow()
{
- model::Frame *frame = mTmplate->frames().first();
+ auto frame = mTmplate.frame();
model::Distance w = frame->w();
model::Distance h = frame->h();
diff --git a/glabels/SimplePreview.h b/glabels/SimplePreview.h
index 9d29924..4100836 100644
--- a/glabels/SimplePreview.h
+++ b/glabels/SimplePreview.h
@@ -51,7 +51,7 @@ namespace glabels
// Properties
/////////////////////////////////
public:
- void setTemplate( const model::Template *tmplate );
+ void setTemplate( const model::Template& tmplate );
void setShowArrow( bool showArrow );
void setRotate( bool rotateFlag );
@@ -70,7 +70,9 @@ namespace glabels
void update();
void drawPaper();
void drawLabels();
- void drawLabel( const model::Distance& x, const model::Distance& y, const QPainterPath& path );
+ void drawLabel( model::Distance x,
+ model::Distance y,
+ const QPainterPath& path );
void drawArrow();
@@ -78,11 +80,11 @@ namespace glabels
// Private Data
/////////////////////////////////
private:
- const model::Template* mTmplate { nullptr };
- bool mShowArrow { false };
- bool mRotateFlag { false };
+ model::Template mTmplate;
+ bool mShowArrow { false };
+ bool mRotateFlag { false };
- QGraphicsScene* mScene { nullptr };
+ QGraphicsScene* mScene { nullptr };
};
diff --git a/glabels/TemplateDesigner.cpp b/glabels/TemplateDesigner.cpp
index 2f6ca80..7944445 100644
--- a/glabels/TemplateDesigner.cpp
+++ b/glabels/TemplateDesigner.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "TemplateDesigner.h"
#include "SelectProductDialog.h"
@@ -34,14 +35,16 @@
#include "model/PageRenderer.h"
#include "model/Settings.h"
+#include
#include
#include
#include
#include
-#include
#include
#include
+#include
+
namespace glabels
{
@@ -367,7 +370,7 @@ namespace glabels
///
/// Build template from wizard pages
///
- model::Template* TemplateDesigner::buildTemplate()
+ model::Template TemplateDesigner::buildTemplate()
{
model::Units units = model::Settings::units();
@@ -379,9 +382,8 @@ namespace glabels
model::Distance pageH( field( "pageSize.h" ).toDouble(), units );
model::Distance pageRollW( field( "pageSize.rollW" ).toDouble(), units );
- auto t = new model::Template( brand, part, description, paperId, pageW, pageH, pageRollW, true );
+ auto t = model::Template( brand, part, description, paperId, pageW, pageH, pageRollW, "", true );
- model::Frame* frame;
if ( field( "shape.rect" ).toBool() )
{
model::Distance w( field( "rect.w" ).toDouble(), units );
@@ -392,8 +394,10 @@ namespace glabels
model::Distance xMargin( field( "rect.xMargin" ).toDouble(), units );
model::Distance yMargin( field( "rect.yMargin" ).toDouble(), units );
- frame = new model::FrameRect( w, h, r, xWaste, yWaste );
- frame->addMarkup( new model::MarkupMargin( xMargin, yMargin ) );
+ model::FrameRect frame( w, h, r, xWaste, yWaste );
+ frame.addMarkup( model::MarkupMargin( xMargin, yMargin ) );
+ addLayouts( frame );
+ t.addFrame( frame );
}
else if ( field( "shape.round" ).toBool() )
{
@@ -401,8 +405,10 @@ namespace glabels
model::Distance waste( field( "round.waste" ).toDouble(), units );
model::Distance margin( field( "round.margin" ).toDouble(), units );
- frame = new model::FrameRound( r, waste );
- frame->addMarkup( new model::MarkupMargin( margin ) );
+ model::FrameRound frame( r, waste );
+ frame.addMarkup( model::MarkupMargin( margin ) );
+ addLayouts( frame );
+ t.addFrame( frame );
}
else if ( field( "shape.ellipse" ).toBool() )
{
@@ -411,8 +417,10 @@ namespace glabels
model::Distance waste( field( "ellipse.waste" ).toDouble(), units );
model::Distance margin( field( "ellipse.margin" ).toDouble(), units );
- frame = new model::FrameEllipse( w, h, waste );
- frame->addMarkup( new model::MarkupMargin( margin ) );
+ model::FrameEllipse frame( w, h, waste );
+ frame.addMarkup( model::MarkupMargin( margin ) );
+ addLayouts( frame );
+ t.addFrame( frame );
}
else
{
@@ -423,10 +431,22 @@ namespace glabels
model::Distance waste( field( "cd.waste" ).toDouble(), units );
model::Distance margin( field( "cd.margin" ).toDouble(), units );
- frame = new model::FrameCd( r1, r2, xClip, yClip, waste );
- frame->addMarkup( new model::MarkupMargin( margin ) );
+ model::FrameCd frame( r1, r2, xClip, yClip, waste );
+ frame.addMarkup( model::MarkupMargin( margin ) );
+ addLayouts( frame );
+ t.addFrame( frame );
}
- t->addFrame( frame );
+
+ return t;
+ }
+
+
+ ///
+ /// Add layouts to frame
+ ///
+ void TemplateDesigner::addLayouts( model::Frame& frame )
+ {
+ model::Units units = model::Settings::units();
if ( field( "nLayouts.one" ).toBool() )
{
@@ -437,7 +457,7 @@ namespace glabels
model::Distance dx( field( "oneLayout.dx" ).toDouble(), units );
model::Distance dy( field( "oneLayout.dy" ).toDouble(), units );
- frame->addLayout( model::Layout( nx, ny, x0, y0, dx, dy ) );
+ frame.addLayout( model::Layout( nx, ny, x0, y0, dx, dy ) );
}
else
{
@@ -455,14 +475,12 @@ namespace glabels
model::Distance dx2( field( "twoLayout.dx2" ).toDouble(), units );
model::Distance dy2( field( "twoLayout.dy2" ).toDouble(), units );
- frame->addLayout( model::Layout( nx1, ny1, x01, y01, dx1, dy1 ) );
- frame->addLayout( model::Layout( nx2, ny2, x02, y02, dx2, dy2 ) );
+ frame.addLayout( model::Layout( nx1, ny1, x01, y01, dx1, dy1 ) );
+ frame.addLayout( model::Layout( nx2, ny2, x02, y02, dx2, dy2 ) );
}
-
- return t;
}
-
+
///
/// Print test sheet
///
@@ -498,22 +516,22 @@ namespace glabels
///
/// Load wizard from template
///
- void TemplateDesigner::loadFromTemplate( const model::Template* tmplate )
+ void TemplateDesigner::loadFromTemplate( const model::Template& tmplate )
{
mIsBasedOnCopy = true;
model::Units units = model::Settings::units();
- setField( "name.brand", tmplate->brand() );
- setField( "name.part", tmplate->part() + QString(" (%1)").arg( tr("Copy") ) );
- setField( "name.description", tmplate->description() );
+ setField( "name.brand", tmplate.brand() );
+ setField( "name.part", tmplate.part() + QString(" (%1)").arg( tr("Copy") ) );
+ setField( "name.description", tmplate.description() );
- setField( "pageSize.pageSize", model::Db::lookupPaperNameFromId( tmplate->paperId() ) );
- setField( "pageSize.w", tmplate->pageWidth().inUnits( units ) );
- setField( "pageSize.h", tmplate->pageHeight().inUnits( units ) );
- setField( "pageSize.rollW", tmplate->rollWidth().inUnits( units ) );
+ setField( "pageSize.pageSize", model::Db::lookupPaperNameFromId( tmplate.paperId() ) );
+ setField( "pageSize.w", tmplate.pageWidth().inUnits( units ) );
+ setField( "pageSize.h", tmplate.pageHeight().inUnits( units ) );
+ setField( "pageSize.rollW", tmplate.rollWidth().inUnits( units ) );
- const model::Frame* frame = tmplate->frames().first();
+ auto frame = tmplate.frame();
if ( auto frameRect = dynamic_cast( frame ) )
{
setField( "shape.rect", true );
@@ -550,9 +568,9 @@ namespace glabels
setField( "cd.waste", frameCd->waste().inUnits( units ) );
}
- foreach( auto markup, frame->markups() )
+ for( auto& markup : frame->markups() )
{
- if ( auto markupMargin = dynamic_cast( markup ) )
+ if ( auto markupMargin = dynamic_cast( markup.get() ) )
{
setField( "rect.xMargin", markupMargin->xSize().inUnits( units ) );
setField( "rect.yMargin", markupMargin->ySize().inUnits( units ) );
@@ -565,28 +583,30 @@ namespace glabels
auto layouts = frame->layouts();
if ( layouts.size() == 1 )
{
- setField( "oneLayout.nx", layouts[0].nx() );
- setField( "oneLayout.ny", layouts[0].ny() );
- setField( "oneLayout.x0", layouts[0].x0().inUnits( units ) );
- setField( "oneLayout.y0", layouts[0].y0().inUnits( units ) );
- setField( "oneLayout.dx", layouts[0].dx().inUnits( units ) );
- setField( "oneLayout.dy", layouts[0].dy().inUnits( units ) );
+ setField( "oneLayout.nx", layouts.front().nx() );
+ setField( "oneLayout.ny", layouts.front().ny() );
+ setField( "oneLayout.x0", layouts.front().x0().inUnits( units ) );
+ setField( "oneLayout.y0", layouts.front().y0().inUnits( units ) );
+ setField( "oneLayout.dx", layouts.front().dx().inUnits( units ) );
+ setField( "oneLayout.dy", layouts.front().dy().inUnits( units ) );
}
else if ( layouts.size() > 1 )
{
- setField( "twoLayout.nx1", layouts[0].nx() );
- setField( "twoLayout.ny1", layouts[0].ny() );
- setField( "twoLayout.x01", layouts[0].x0().inUnits( units ) );
- setField( "twoLayout.y01", layouts[0].y0().inUnits( units ) );
- setField( "twoLayout.dx1", layouts[0].dx().inUnits( units ) );
- setField( "twoLayout.dy1", layouts[0].dy().inUnits( units ) );
+ auto it = layouts.begin();
+ setField( "twoLayout.nx1", it->nx() );
+ setField( "twoLayout.ny1", it->ny() );
+ setField( "twoLayout.x01", it->x0().inUnits( units ) );
+ setField( "twoLayout.y01", it->y0().inUnits( units ) );
+ setField( "twoLayout.dx1", it->dx().inUnits( units ) );
+ setField( "twoLayout.dy1", it->dy().inUnits( units ) );
- setField( "twoLayout.nx2", layouts[1].nx() );
- setField( "twoLayout.ny2", layouts[1].ny() );
- setField( "twoLayout.x02", layouts[1].x0().inUnits( units ) );
- setField( "twoLayout.y02", layouts[1].y0().inUnits( units ) );
- setField( "twoLayout.dx2", layouts[1].dx().inUnits( units ) );
- setField( "twoLayout.dy2", layouts[1].dy().inUnits( units ) );
+ std::advance( it, 1 );
+ setField( "twoLayout.nx2", it->nx() );
+ setField( "twoLayout.ny2", it->ny() );
+ setField( "twoLayout.x02", it->x0().inUnits( units ) );
+ setField( "twoLayout.y02", it->y0().inUnits( units ) );
+ setField( "twoLayout.dx2", it->dx().inUnits( units ) );
+ setField( "twoLayout.dy2", it->dy().inUnits( units ) );
}
}
@@ -633,16 +653,16 @@ namespace glabels
SelectProductDialog dialog;
dialog.exec();
- const model::Template* tmplate = dialog.tmplate();
- if ( tmplate )
+ auto tmplate = dialog.tmplate();
+ if ( !tmplate.isNull() )
{
if ( auto td = dynamic_cast( wizard() ) )
{
- if ( dynamic_cast(tmplate->frames().constFirst()) )
+ if ( dynamic_cast(tmplate.frame()) )
{
td->mIsTemplatePathBased = true;
}
- else if ( dynamic_cast(tmplate->frames().constFirst()) )
+ else if ( dynamic_cast(tmplate.frame()) )
{
td->mIsTemplateContinuousBased = true;
}
@@ -753,9 +773,9 @@ namespace glabels
if ( pageSizeCombo->currentText() != tr("Other") )
{
- const model::Paper* paper = model::Db::lookupPaperFromName( pageSizeCombo->currentText() );
- wSpin->setValue( paper->width().inUnits( model::Settings::units() ) );
- hSpin->setValue( paper->height().inUnits( model::Settings::units() ) );
+ auto paper = model::Db::lookupPaperFromName( pageSizeCombo->currentText() );
+ wSpin->setValue( paper.width().inUnits( model::Settings::units() ) );
+ hSpin->setValue( paper.height().inUnits( model::Settings::units() ) );
}
registerField( "pageSize.pageSize", pageSizeCombo, "currentText" );
@@ -789,9 +809,9 @@ namespace glabels
if ( !isOther && !isRoll )
{
- const model::Paper* paper = model::Db::lookupPaperFromName( pageSizeCombo->currentText() );
- wSpin->setValue( paper->width().inUnits( model::Settings::units() ) );
- hSpin->setValue( paper->height().inUnits( model::Settings::units() ) );
+ auto paper = model::Db::lookupPaperFromName( pageSizeCombo->currentText() );
+ wSpin->setValue( paper.width().inUnits( model::Settings::units() ) );
+ hSpin->setValue( paper.height().inUnits( model::Settings::units() ) );
}
if ( !isRoll )
@@ -1553,7 +1573,7 @@ namespace glabels
//
QString brand = field( "name.brand" ).toString();
QString part = field( "name.part" ).toString();
- QString filename = model::Db::userTemplateFilename( brand, part );
+ QString filename = model::Db::userTemplateFileName( brand, part );
if ( QFileInfo::exists(filename) )
{
diff --git a/glabels/TemplateDesigner.h b/glabels/TemplateDesigner.h
index 9e3a592..7d336f2 100644
--- a/glabels/TemplateDesigner.h
+++ b/glabels/TemplateDesigner.h
@@ -86,9 +86,10 @@ namespace glabels
double itemHeight();
double itemXWaste();
double itemYWaste();
- model::Template* buildTemplate();
+ model::Template buildTemplate();
+ void addLayouts( model::Frame& frame );
void printTestSheet();
- void loadFromTemplate( const model::Template* tmplate );
+ void loadFromTemplate( const model::Template& tmplate );
bool isBasedOnCopy();
diff --git a/glabels/TemplatePicker.cpp b/glabels/TemplatePicker.cpp
index d47f6e1..bc90f96 100644
--- a/glabels/TemplatePicker.cpp
+++ b/glabels/TemplatePicker.cpp
@@ -112,11 +112,11 @@ namespace glabels
///
/// Set List of Templates to Pick From
///
- void TemplatePicker::setTemplates( const QList& tmplates )
+ void TemplatePicker::setTemplates( const QList& tmplates )
{
auto mode = model::Settings::templatePickerMode();
- foreach (model::Template *tmplate, tmplates)
+ foreach (auto& tmplate, tmplates)
{
new TemplatePickerItem( tmplate, mode, this );
}
@@ -186,12 +186,12 @@ namespace glabels
{
if (auto* tItem = dynamic_cast(item(i)))
{
- bool nameMask = tItem->tmplate()->name().contains( searchString, Qt::CaseInsensitive );
+ bool nameMask = tItem->tmplate().name().contains( searchString, Qt::CaseInsensitive );
bool sizeMask =
- (isoMask && tItem->tmplate()->isSizeIso()) ||
- (usMask && tItem->tmplate()->isSizeUs()) ||
- (otherMask && tItem->tmplate()->isSizeOther());
+ (isoMask && tItem->tmplate().isSizeIso()) ||
+ (usMask && tItem->tmplate().isSizeUs()) ||
+ (otherMask && tItem->tmplate().isSizeOther());
bool categoryMask;
if ( anyCategory )
@@ -203,7 +203,7 @@ namespace glabels
categoryMask = false;
foreach ( QString id, categoryIds )
{
- categoryMask = categoryMask || tItem->tmplate()->hasCategory( id );
+ categoryMask = categoryMask || tItem->tmplate().hasCategory( id );
}
}
@@ -239,7 +239,7 @@ namespace glabels
bool match = false;
foreach ( QString name, names )
{
- if ( tItem->tmplate()->name() == name )
+ if ( tItem->tmplate().name() == name )
{
match = true;
break;
@@ -268,14 +268,14 @@ namespace glabels
///
/// Get Currently Selected Template
///
- const model::Template* TemplatePicker::selectedTemplate() const
+ model::Template TemplatePicker::selectedTemplate() const
{
if ( auto* tItem = selectedItem() )
{
return tItem->tmplate();
}
- return nullptr;
+ return model::Template();
}
diff --git a/glabels/TemplatePicker.h b/glabels/TemplatePicker.h
index 78186f0..cebf02d 100644
--- a/glabels/TemplatePicker.h
+++ b/glabels/TemplatePicker.h
@@ -51,7 +51,7 @@ namespace glabels
// Properties
/////////////////////////////////
public:
- void setTemplates( const QList& tmplates );
+ void setTemplates( const QList& tmplates );
void setMode( QListView::ViewMode mode );
QListView::ViewMode mode() const;
@@ -66,8 +66,8 @@ namespace glabels
void applyFilter( const QStringList& names );
- const model::Template* selectedTemplate() const;
- TemplatePickerItem* selectedItem() const;
+ model::Template selectedTemplate() const;
+ TemplatePickerItem* selectedItem() const;
};
diff --git a/glabels/TemplatePickerItem.cpp b/glabels/TemplatePickerItem.cpp
index 43ec4c7..59de53e 100644
--- a/glabels/TemplatePickerItem.cpp
+++ b/glabels/TemplatePickerItem.cpp
@@ -36,9 +36,9 @@ namespace glabels
///
/// Constructor
///
- TemplatePickerItem::TemplatePickerItem( model::Template* tmplate,
- QListView::ViewMode mode,
- QListWidget* parent )
+ TemplatePickerItem::TemplatePickerItem( const model::Template& tmplate,
+ QListView::ViewMode mode,
+ QListWidget* parent )
: QListWidgetItem( parent )
{
mTmplate = tmplate;
@@ -55,18 +55,18 @@ namespace glabels
///
void TemplatePickerItem::setMode( QListView::ViewMode mode )
{
- auto* frame = mTmplate->frames().first();
+ auto frame = mTmplate.frame();
switch ( mode )
{
case QListView::IconMode:
- setText( mTmplate->name() );
+ setText( mTmplate.name() );
break;
case QListView::ListMode:
- setText( "" + mTmplate->name() + "
" +
- mTmplate->description() + "
" +
+ setText( "" + mTmplate.name() + "
" +
+ mTmplate.description() + "
" +
frame->sizeDescription( model::Settings::units() ) + "
" +
frame->layoutDescription() );
break;
@@ -82,7 +82,7 @@ namespace glabels
///
/// Template Property Getter
///
- const model::Template *TemplatePickerItem::tmplate() const
+ model::Template TemplatePickerItem::tmplate() const
{
return mTmplate;
}
diff --git a/glabels/TemplatePickerItem.h b/glabels/TemplatePickerItem.h
index a67b3de..d43df26 100644
--- a/glabels/TemplatePickerItem.h
+++ b/glabels/TemplatePickerItem.h
@@ -44,9 +44,9 @@ namespace glabels
// Life Cycle
/////////////////////////////////
public:
- TemplatePickerItem( model::Template* tmplate,
- QListView::ViewMode mode,
- QListWidget* parent = nullptr );
+ TemplatePickerItem( const model::Template& tmplate,
+ QListView::ViewMode mode,
+ QListWidget* parent = nullptr );
/////////////////////////////////
@@ -60,14 +60,14 @@ namespace glabels
// Properties
/////////////////////////////////
public:
- const model::Template *tmplate() const;
+ model::Template tmplate() const;
/////////////////////////////////
// Private Data
/////////////////////////////////
private:
- model::Template *mTmplate;
+ model::Template mTmplate;
};
diff --git a/glabels/UndoRedoModel.cpp b/glabels/UndoRedoModel.cpp
index db0864e..341a181 100644
--- a/glabels/UndoRedoModel.cpp
+++ b/glabels/UndoRedoModel.cpp
@@ -38,15 +38,6 @@ namespace glabels
}
- ///
- /// Destructor
- ///
- UndoRedoModel::~UndoRedoModel()
- {
- // empty
- }
-
-
///
/// Checkpoint
///
diff --git a/glabels/UndoRedoModel.h b/glabels/UndoRedoModel.h
index 110af9c..398ac5c 100644
--- a/glabels/UndoRedoModel.h
+++ b/glabels/UndoRedoModel.h
@@ -45,7 +45,7 @@ namespace glabels
/////////////////////////////////
public:
UndoRedoModel( model::Model* model );
- ~UndoRedoModel() override;
+ virtual ~UndoRedoModel() = default;
/////////////////////////////////
diff --git a/glabels/VariablesView.cpp b/glabels/VariablesView.cpp
index 4f9d2c8..b87237c 100644
--- a/glabels/VariablesView.cpp
+++ b/glabels/VariablesView.cpp
@@ -82,15 +82,6 @@ namespace glabels
}
- ///
- /// Destructor
- ///
- VariablesView::~VariablesView()
- {
- // empty
- }
-
-
///
/// Set Model
///
@@ -132,7 +123,7 @@ namespace glabels
if ( dialog.exec() == QDialog::Accepted )
{
- mModel->variables()->addVariable( dialog.variable() );
+ mModel->variables().addVariable( dialog.variable() );
selectVariable( dialog.variable().name() );
}
}
@@ -146,9 +137,9 @@ namespace glabels
int iRow = table->selectedItems()[0]->row();
QString name = table->item( iRow, I_COL_NAME )->text();
- if ( mModel->variables()->hasVariable( name ) )
+ if ( mModel->variables().hasVariable( name ) )
{
- model::Variable v = mModel->variables()->value( name );
+ model::Variable v = mModel->variables().value( name );
EditVariableDialog dialog( this );
dialog.setVariable( v );
@@ -156,7 +147,7 @@ namespace glabels
if ( dialog.exec() == QDialog::Accepted )
{
- mModel->variables()->replaceVariable( name, dialog.variable() );
+ mModel->variables().replaceVariable( name, dialog.variable() );
selectVariable( dialog.variable().name() );
}
}
@@ -171,7 +162,7 @@ namespace glabels
int iRow = table->selectedItems()[0]->row();
QString name = table->item( iRow, I_COL_NAME )->text();
- mModel->variables()->deleteVariable( name );
+ mModel->variables().deleteVariable( name );
}
@@ -203,10 +194,10 @@ namespace glabels
void VariablesView::loadTable()
{
table->clearContents();
- table->setRowCount( mModel->variables()->size() );
+ table->setRowCount( mModel->variables().size() );
int iRow = 0;
- for( const auto& v : *mModel->variables() )
+ for( const auto& v : mModel->variables() )
{
auto* typeItem = new QTableWidgetItem( model::Variable::typeToI18nString(v.type()) );
typeItem->setFlags( typeItem->flags() ^ Qt::ItemIsEditable );
@@ -237,7 +228,7 @@ namespace glabels
void VariablesView::selectVariable( const QString& name )
{
int iRow = 0;
- for( const auto& v : *mModel->variables() )
+ for( const auto& v : mModel->variables() )
{
if ( v.name() == name )
{
diff --git a/glabels/VariablesView.h b/glabels/VariablesView.h
index 25c0088..c6232f6 100644
--- a/glabels/VariablesView.h
+++ b/glabels/VariablesView.h
@@ -47,7 +47,7 @@ namespace glabels
/////////////////////////////////
public:
VariablesView( QWidget *parent = nullptr );
- ~VariablesView() override;
+ virtual ~VariablesView() = default;
/////////////////////////////////
diff --git a/glabels/main.cpp b/glabels/main.cpp
index 5b98a00..f2e8d85 100644
--- a/glabels/main.cpp
+++ b/glabels/main.cpp
@@ -23,7 +23,6 @@
#include "model/FileUtil.h"
#include "model/Db.h"
#include "model/Model.h"
-#include "model/Settings.h"
#include "model/Version.h"
#include "model/XmlLabelParser.h"
@@ -43,9 +42,9 @@ int main( int argc, char **argv )
{
QApplication app( argc, argv );
- QCoreApplication::setOrganizationName( "glabels.org" );
- QCoreApplication::setOrganizationDomain( "glabels.org" );
- QCoreApplication::setApplicationName( "glabels-qt" );
+ QCoreApplication::setOrganizationName( glabels::model::Version::ORGANIZATION_NAME );
+ QCoreApplication::setOrganizationDomain( glabels::model::Version::ORGANIZATION_DOMAIN );
+ QCoreApplication::setApplicationName( glabels::model::Version::APPLICATION_NAME );
QCoreApplication::setApplicationVersion( glabels::model::Version::LONG_STRING );
QIcon::setThemeName( "glabels-flat" );
diff --git a/model/CMakeLists.txt b/model/CMakeLists.txt
index fbc3be4..f9384be 100644
--- a/model/CMakeLists.txt
+++ b/model/CMakeLists.txt
@@ -31,7 +31,7 @@ set (Model_sources
FramePath.cpp
FrameRect.cpp
FrameRound.cpp
- Handles.cpp
+ Handle.cpp
Layout.cpp
Markup.cpp
Model.cpp
diff --git a/model/Category.cpp b/model/Category.cpp
index 2b82870..34f4a5e 100644
--- a/model/Category.cpp
+++ b/model/Category.cpp
@@ -27,7 +27,8 @@ namespace glabels
{
Category::Category( const QString &id, const QString &name )
- : mId(id), mName(name)
+ : mId(id),
+ mName(name)
{
// empty
}
diff --git a/model/Category.h b/model/Category.h
index b483d11..de13e72 100644
--- a/model/Category.h
+++ b/model/Category.h
@@ -34,7 +34,9 @@ namespace glabels
{
public:
+ Category() = default;
Category( const QString& id, const QString& name );
+ ~Category() = default;
QString id() const;
QString name() const;
diff --git a/model/ColorNode.cpp b/model/ColorNode.cpp
index 5f6c04a..725c318 100644
--- a/model/ColorNode.cpp
+++ b/model/ColorNode.cpp
@@ -18,9 +18,8 @@
* along with gLabels-qt. If not, see .
*/
-#include "ColorNode.h"
-#include "merge/Record.h"
+#include "ColorNode.h"
namespace glabels
@@ -175,25 +174,25 @@ namespace glabels
///
/// Get color, expand if necessary
///
- QColor ColorNode::color( const merge::Record* record,
- const Variables* variables ) const
+ QColor ColorNode::color( const merge::Record& record,
+ const Variables& variables ) const
{
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();
+ bool haveRecordField = mIsField &&
+ record.contains(mKey) &&
+ !record.value(mKey).isEmpty();
+ bool haveVariable = mIsField &&
+ variables.contains(mKey) &&
+ !variables[mKey].value().isEmpty();
if ( haveRecordField )
{
- value = QColor( record->value(mKey) );
+ value = QColor( record.value(mKey) );
}
else if ( haveVariable )
{
- value = QColor( (*variables)[mKey].value() );
+ value = QColor( variables[mKey].value() );
}
else if ( !mIsField )
{
diff --git a/model/ColorNode.h b/model/ColorNode.h
index a509335..5819275 100644
--- a/model/ColorNode.h
+++ b/model/ColorNode.h
@@ -96,8 +96,8 @@ namespace glabels
/////////////////////////////////
public:
uint32_t rgba() const;
- QColor color( const merge::Record* record,
- const Variables* variables ) const;
+ QColor color( const merge::Record& record,
+ const Variables& variables ) const;
/////////////////////////////////
diff --git a/model/DataCache.cpp b/model/DataCache.cpp
index c484bef..cf45dbf 100644
--- a/model/DataCache.cpp
+++ b/model/DataCache.cpp
@@ -43,13 +43,14 @@ namespace glabels
TextNode filenameNode = imageObject->filenameNode();
if ( !filenameNode.isField() )
{
- if ( const QImage* image = imageObject->image() )
+ auto& image = imageObject->image();
+ if ( !image.isNull() )
{
- addImage( filenameNode.data(), *image );
+ addImage( filenameNode.data(), image );
}
else
{
- QByteArray svg = imageObject->svg();
+ auto& svg = imageObject->svg();
if ( !svg.isEmpty() )
{
addSvg( filenameNode.data(), svg );
diff --git a/model/Db.cpp b/model/Db.cpp
index e9efa15..8215d75 100644
--- a/model/Db.cpp
+++ b/model/Db.cpp
@@ -30,7 +30,7 @@
#include "XmlTemplateCreator.h"
#include "XmlVendorParser.h"
-#include
+#include
#include
#include
@@ -48,9 +48,9 @@ namespace glabels
{
const QString empty = "";
- bool partNameLessThan( const Template *a, const Template *b )
+ bool partNameLessThan( const Template& a, const Template& b )
{
- return StrUtil::comparePartNames( a->name(), b->name() ) < 0;
+ return StrUtil::comparePartNames( a.name(), b.name() ) < 0;
}
}
@@ -58,18 +58,29 @@ namespace glabels
//
// Static data
//
- QList Db::mPapers;
- QStringList Db::mPaperIds;
- QStringList Db::mPaperNames;
- QList Db::mCategories;
- QStringList Db::mCategoryIds;
- QStringList Db::mCategoryNames;
- QList Db::mVendors;
- QStringList Db::mVendorNames;
- QList Db::mTemplates;
+ QList Db::mPapers;
+ QMap Db::mPapersNameMap;
+ QMap Db::mPapersIdMap;
+ QStringList Db::mPaperIds;
+ QStringList Db::mPaperNames;
+
+ QList Db::mCategories;
+ QMap Db::mCategoriesNameMap;
+ QMap Db::mCategoriesIdMap;
+ QStringList Db::mCategoryIds;
+ QStringList Db::mCategoryNames;
+
+ QList Db::mVendors;
+ QMap Db::mVendorsNameMap;
+ QStringList Db::mVendorNames;
+
+ QList Db::mTemplates;
+ QMap Db::mTemplatesNameMap;
+
+ QMap Db::mUserTemplatesNameMap;
- Db::Db()
+ void Db::init()
{
readPapers();
readCategories();
@@ -77,21 +88,8 @@ namespace glabels
readTemplates();
}
-
- void Db::init()
- {
- instance();
- }
-
- Db* Db::instance()
- {
- static auto* db = new Db();
- return db;
- }
-
-
- const QList& Db::papers()
+ const QList& Db::papers()
{
return mPapers;
}
@@ -109,7 +107,7 @@ namespace glabels
}
- const QList& Db::categories()
+ const QList& Db::categories()
{
return mCategories;
}
@@ -127,7 +125,7 @@ namespace glabels
}
- const QList& Db::vendors()
+ const QList& Db::vendors()
{
return mVendors;
}
@@ -139,383 +137,251 @@ namespace glabels
}
- const QList& Db::templates()
+ QList Db::templates()
{
- return mTemplates;
+ auto list = mTemplates;
+ list.append( mUserTemplatesNameMap.values() );
+
+ std::stable_sort( list.begin(), list.end(), partNameLessThan );
+
+ return list;
}
- void Db::registerPaper( Paper *paper )
+ const Paper Db::lookupPaperFromName( const QString& name )
{
- if ( !isPaperIdKnown( paper->id() ) )
- {
- mPapers << paper;
- mPaperIds << paper->id();
- mPaperNames << paper->name();
- }
- else
- {
- qWarning() << "Duplicate paper ID: " << paper->id();
- }
- }
-
-
- const Paper *Db::lookupPaperFromName( const QString& name )
- {
- if ( name.isNull() || name.isEmpty() )
+ if ( name.isEmpty() )
{
qWarning() << "NULL paper name.";
- return mPapers.first();
+ return Paper();
}
- foreach ( Paper *paper, mPapers )
+ auto it = mPapersNameMap.find( name );
+ if ( it != mPapersNameMap.end() )
{
- if ( paper->name() == name )
- {
- return paper;
- }
+ return *it;
}
qWarning() << "Unknown paper name: " << name;
- return nullptr;
+ return Paper();
}
- const Paper *Db::lookupPaperFromId( const QString& id )
+ const Paper Db::lookupPaperFromId( const QString& id )
{
- if ( id.isNull() || id.isEmpty() )
+ if ( id.isEmpty() )
{
- qWarning() << "NULL paper ID.";
- return mPapers.first();
+ qWarning() << "NULL paper id.";
+ return Paper();
}
- foreach ( Paper *paper, mPapers )
+ auto it = mPapersIdMap.find( id );
+ if ( it != mPapersIdMap.end() )
{
- if ( paper->id() == id )
- {
- return paper;
- }
+ return *it;
}
qWarning() << "Unknown paper ID: " << id;
- return nullptr;
+ return Paper();
}
QString Db::lookupPaperIdFromName( const QString& name )
{
- if ( !name.isNull() && !name.isEmpty() )
- {
- if ( name == tr("Other") )
- {
- return "other";
- }
- else if ( name == tr("Roll") )
- {
- return "roll";
- }
-
- const Paper *paper = lookupPaperFromName( name );
- if ( paper != nullptr )
- {
- return paper->id();
- }
- }
-
- qWarning() << "Unknown paper name: " << name;
- return empty;
+ return lookupPaperFromName( name ).id();
}
QString Db::lookupPaperNameFromId( const QString& id )
{
- if ( !id.isNull() && !id.isEmpty() )
- {
- if ( id == "other" )
- {
- return tr("Other");
- }
- else if ( id == "roll" )
- {
- return tr("Roll");
- }
-
- const Paper *paper = lookupPaperFromId( id );
- if ( paper != nullptr )
- {
- return paper->name();
- }
- }
-
- qWarning() << "Unknown paper id: " << id;
- return empty;
+ return lookupPaperFromId( id ).name();
}
bool Db::isPaperIdKnown( const QString& id )
{
- foreach ( Paper *paper, mPapers )
- {
- if ( paper->id() == id )
- {
- return true;
- }
- }
-
- return false;
+ return mPapersIdMap.contains( id );
}
- void Db::registerCategory( Category *category )
+ const Category Db::lookupCategoryFromName( const QString& name )
{
- if ( !isCategoryIdKnown( category->id() ) )
- {
- mCategories << category;
- mCategoryIds << category->id();
- mCategoryNames << category->name();
- }
- else
- {
- qWarning() << "Duplicate category ID: " << category->id();
- }
- }
-
-
- const Category *Db::lookupCategoryFromName( const QString& name )
- {
- if ( name.isNull() || name.isEmpty() )
+ if ( name.isEmpty() )
{
qWarning() << "NULL category name.";
- return mCategories.first();
+ return Category();
}
- foreach ( Category *category, mCategories )
+ auto it = mCategoriesNameMap.find( name );
+ if ( it != mCategoriesNameMap.end() )
{
- if ( category->name() == name )
- {
- return category;
- }
+ return *it;
}
qWarning() << "Unknown category name: \"%s\"." << name;
- return nullptr;
+ return Category();
}
- const Category *Db::lookupCategoryFromId( const QString& id )
+ const Category Db::lookupCategoryFromId( const QString& id )
{
- if ( id.isNull() || id.isEmpty() )
+ if ( id.isEmpty() )
{
- qDebug() << "NULL category ID.";
- return mCategories.first();
+ qWarning() << "NULL category id.";
+ return Category();
}
- foreach ( Category *category, mCategories )
+ auto it = mCategoriesIdMap.find( id );
+ if ( it != mCategoriesIdMap.end() )
{
- if ( category->id() == id )
- {
- return category;
- }
+ return *it;
}
- qWarning() << "Unknown category ID: " << id;
- return nullptr;
+ qWarning() << "Unknown category ID: \"%s\"." << id;
+ return Category();
}
QString Db::lookupCategoryIdFromName( const QString& name )
{
- if ( !name.isNull() && !name.isEmpty() )
- {
- const Category *category = lookupCategoryFromName( name );
- if ( category != nullptr )
- {
- return category->id();
- }
- }
-
- qWarning() << "Unknown category name: " << name;
- return empty;
+ return lookupCategoryFromName( name ).id();
}
QString Db::lookupCategoryNameFromId( const QString& id )
{
- if ( !id.isNull() && !id.isEmpty() )
- {
- const Category *category = lookupCategoryFromId( id );
- if ( category != nullptr )
- {
- return category->name();
- }
- }
-
- qWarning() << "Unknown category id: " << id;
- return empty;
+ return lookupCategoryFromId( id ).name();
}
bool Db::isCategoryIdKnown( const QString& id )
{
- foreach ( Category *category, mCategories )
- {
- if ( category->id() == id )
- {
- return true;
- }
- }
-
- return false;
+ return mCategoriesIdMap.contains( id );
}
- void Db::registerVendor( Vendor *vendor )
+ const Vendor Db::lookupVendorFromName( const QString& name )
{
- if ( !isVendorNameKnown( vendor->name() ) )
- {
- mVendors << vendor;
- mVendorNames << vendor->name();
- }
- else
- {
- qWarning() << "Duplicate vendor name: " << vendor->name();
- }
- }
-
-
- const Vendor *Db::lookupVendorFromName( const QString& name )
- {
- if ( name.isNull() || name.isEmpty() )
+ if ( name.isEmpty() )
{
qWarning() << "NULL vendor name.";
- return mVendors.first();
+ return Vendor();
}
- foreach ( Vendor *vendor, mVendors )
+ auto it = mVendorsNameMap.find( name );
+ if ( it != mVendorsNameMap.end() )
{
- if ( vendor->name() == name )
- {
- return vendor;
- }
+ return *it;
}
qWarning() << "Unknown vendor name: " << name;
- return nullptr;
+ return Vendor();
}
QString Db::lookupVendorUrlFromName( const QString& name )
{
- if ( !name.isNull() && !name.isEmpty() )
- {
- const Vendor *vendor = lookupVendorFromName( name );
- if ( vendor != nullptr )
- {
- return vendor->url();
- }
- }
-
- qWarning() << "Unknown vendor name: " << name;
- return empty;
+ return lookupVendorFromName( name ).url();
}
bool Db::isVendorNameKnown( const QString& name )
{
- foreach ( Vendor *vendor, mVendors )
- {
- if ( vendor->name() == name )
- {
- return true;
- }
- }
-
- return false;
+ return mVendorsNameMap.contains( name );
}
- void Db::registerTemplate( Template *tmplate )
+ const Template Db::lookupTemplateFromName( const QString& name )
{
- if ( !isTemplateKnown( tmplate->brand(), tmplate->part() ) )
- {
- mTemplates << tmplate;
- }
- else
- {
- qWarning() << "Duplicate template name: " << tmplate->name();
- }
- }
-
-
- const Template *Db::lookupTemplateFromName( const QString& name )
- {
- if ( name.isNull() || name.isEmpty() )
+ if ( name.isEmpty() )
{
qWarning() << "NULL template name.";
- return mTemplates.first();
+ return Template();
}
- foreach ( Template *tmplate, mTemplates )
+ auto it = mTemplatesNameMap.find( name );
+ if ( it != mTemplatesNameMap.end() )
{
- if ( tmplate->name() == name )
- {
- return tmplate;
- }
+ return *it;
+ }
+
+ auto it2 = mUserTemplatesNameMap.find( name );
+ if ( it2 != mUserTemplatesNameMap.end() )
+ {
+ return *it2;
}
qWarning() << "Unknown template name: " << name;
- return nullptr;
+ return Template();
}
- const Template *Db::lookupTemplateFromBrandPart( const QString& brand, const QString& part )
+ const Template Db::lookupTemplateFromBrandPart( const QString& brand, const QString& part )
{
- if ( brand.isNull() || brand.isEmpty() || part.isNull() || part.isEmpty() )
+ if ( brand.isEmpty() || part.isEmpty() )
{
qWarning() << "NULL template brand and/or part.";
- return mTemplates.first();
+ return Template();
}
- foreach ( Template *tmplate, mTemplates )
+ auto name = Template::brandPartToName( brand, part );
+
+ auto it = mTemplatesNameMap.find( name );
+ if ( it != mTemplatesNameMap.end() )
{
- if ( (tmplate->brand() == brand) && (tmplate->part() == part) )
- {
- return tmplate;
- }
+ return *it;
+ }
+
+ auto it2 = mUserTemplatesNameMap.find( name );
+ if ( it2 != mUserTemplatesNameMap.end() )
+ {
+ return *it2;
}
qWarning() << "Unknown template brand, part: " << brand << ", " << part;
- return nullptr;
+ return Template();
+ }
+
+
+ const Template Db::lookupUserTemplateFromBrandPart( const QString& brand, const QString& part )
+ {
+ if ( brand.isEmpty() || part.isEmpty() )
+ {
+ qWarning() << "NULL template brand and/or part.";
+ return Template();
+ }
+
+ auto name = Template::brandPartToName( brand, part );
+
+ auto it = mUserTemplatesNameMap.find( name );
+ if ( it != mUserTemplatesNameMap.end() )
+ {
+ return *it;
+ }
+
+ qWarning() << "Unknown user template brand, part: " << brand << ", " << part;
+ return Template();
}
bool Db::isTemplateKnown( const QString& brand, const QString& part )
{
- foreach ( Template *tmplate, mTemplates )
- {
- if ( (tmplate->brand() == brand) && (tmplate->part() == part) )
- {
- return true;
- }
- }
-
- return false;
+ auto name = Template::brandPartToName( brand, part );
+ return mTemplatesNameMap.contains( name ) || mUserTemplatesNameMap.contains( name );
}
bool Db::isSystemTemplateKnown( const QString& brand, const QString& part )
{
- foreach ( Template *tmplate, mTemplates )
- {
- if ( (tmplate->brand() == brand) &&
- (tmplate->part() == part) &&
- !tmplate->isUserDefined() )
- {
- return true;
- }
- }
+ auto name = Template::brandPartToName( brand, part );
+ return mTemplatesNameMap.contains( name );
+ }
- return false;
+
+ bool Db::isUserTemplateKnown( const QString& brand, const QString& part )
+ {
+ auto name = Template::brandPartToName( brand, part );
+ return mUserTemplatesNameMap.contains( name );
}
@@ -523,20 +389,20 @@ namespace glabels
{
QStringList list;
- const Template *tmplate1 = lookupTemplateFromName( name );
- if ( tmplate1 == nullptr )
+ auto tmplate1 = lookupTemplateFromName( name );
+ if ( tmplate1.isNull() )
{
qWarning() << "Unknown template name: " << name;
return list;
}
- foreach (const Template *tmplate2, mTemplates )
+ for ( auto& tmplate2 : templates() )
{
- if ( tmplate1->name() != tmplate2->name() )
+ if ( tmplate1.name() != tmplate2.name() )
{
- if ( tmplate1->isSimilarTo( tmplate2 ) )
+ if ( tmplate1.isSimilarTo( tmplate2 ) )
{
- list << tmplate2->name();
+ list << tmplate2.name();
}
}
}
@@ -545,51 +411,53 @@ namespace glabels
}
- QString Db::userTemplateFilename( const QString& brand, const QString& part )
+ QString Db::userTemplateFileName( const QString& brand, const QString& part )
{
- QString filename = brand + "_" + part + ".template";
- return FileUtil::userTemplatesDir().filePath( filename );
+ QString fileName = brand + "_" + part + ".template";
+ return FileUtil::userTemplatesDir().filePath( fileName );
}
- void Db::registerUserTemplate( Template *tmplate )
+ void Db::registerUserTemplate( const Template& tmplate )
{
- QString filename = userTemplateFilename( tmplate->brand(), tmplate->part() );
+ if ( isTemplateKnown( tmplate.brand(), tmplate.part() ) )
+ {
+ qWarning() << "Duplicate template name: " << tmplate.name();
+ return;
+ }
+
+ QString fileName = userTemplateFileName( tmplate.brand(), tmplate.part() );
// Write file
- if ( XmlTemplateCreator().writeTemplate( tmplate, filename ) )
+ if ( XmlTemplateCreator().writeTemplate( tmplate, fileName ) )
{
// Add template to list of registered templates
- registerTemplate( tmplate );
- Settings::addToRecentTemplateList( tmplate->name() );
+ mUserTemplatesNameMap[ tmplate.name() ] = tmplate;
+ mUserTemplatesNameMap[ tmplate.name() ].setFileName( fileName );
+ mUserTemplatesNameMap[ tmplate.name() ].setIsUserDefined( true );
+
+ Settings::addToRecentTemplateList( tmplate.name() );
+
}
else
{
- qWarning() << "Problem writing user template" << filename;
+ qWarning() << "Problem writing user template" << fileName;
}
}
void Db::deleteUserTemplateByBrandPart( const QString& brand, const QString& part )
{
- Template* tmplate;
- foreach ( Template *candidate, mTemplates )
+ auto tmplate = lookupUserTemplateFromBrandPart( brand, part );
+ if ( !tmplate.isNull() && tmplate.isUserDefined() )
{
- if ( candidate->isUserDefined() &&
- (candidate->brand() == brand) && (candidate->part() == part) )
- {
- tmplate = candidate;
- break;
- }
+ mUserTemplatesNameMap.remove( Template::brandPartToName( brand, part ) );
+
+ QFile( tmplate.fileName() ).remove();
}
-
- if ( tmplate )
+ else
{
- mTemplates.removeOne( tmplate );
- delete tmplate;
-
- QString filename = userTemplateFilename( brand, part );
- QFile( filename ).remove();
+ qWarning() << "Not a user defined template:" << tmplate.name();
}
}
@@ -598,14 +466,14 @@ namespace glabels
{
qDebug() << "KNOWN PAPERS:";
- foreach ( Paper *paper, mPapers )
+ for ( auto& paper : mPapers )
{
qDebug() << "paper "
- << "id=" << paper->id() << ", "
- << "name=" << paper->name() << ", "
- << "width=" << paper->width().pt() << "pts, "
- << "height=" << paper->height().pt() << "pts, "
- << "pwg_size=" << paper->pwgSize();
+ << "id=" << paper.id() << ", "
+ << "name=" << paper.name() << ", "
+ << "width=" << paper.width().pt() << "pts, "
+ << "height=" << paper.height().pt() << "pts, "
+ << "pwg_size=" << paper.pwgSize();
}
qDebug();
@@ -616,11 +484,11 @@ namespace glabels
{
qDebug() << "KNOWN CATEGORIES:";
- foreach ( Category *category, mCategories )
+ for ( auto& category : mCategories )
{
qDebug() << "category "
- << "id=" << category->id() << ", "
- << "name=" << category->name();
+ << "id=" << category.id() << ", "
+ << "name=" << category.name();
}
qDebug();
@@ -631,11 +499,11 @@ namespace glabels
{
qDebug() << "KNOWN VENDORS:";
- foreach ( Vendor *vendor, mVendors )
+ for ( auto& vendor : mVendors )
{
qDebug() << "vendor "
- << "name='" << vendor->name() << ", "
- << "url='" << vendor->url();
+ << "name='" << vendor.name() << ", "
+ << "url='" << vendor.url();
}
qDebug();
@@ -646,12 +514,12 @@ namespace glabels
{
qDebug() << "KNOWN TEMPLATES:";
- foreach ( Template *tmplate, mTemplates )
+ for ( auto& tmplate : mTemplates )
{
qDebug() << "template "
- << "brand=" << tmplate->brand() << ", "
- << "part=" << tmplate->part() << ", "
- << "description=" << tmplate->description();
+ << "brand=" << tmplate.brand() << ", "
+ << "part=" << tmplate.part() << ", "
+ << "description=" << tmplate.description();
}
qDebug();
@@ -668,16 +536,37 @@ namespace glabels
{
XmlPaperParser parser;
- foreach ( QString fileName, dir.entryList( QDir::Files ) )
+ for ( auto fileName : dir.entryList( QDir::Files ) )
{
if ( fileName == "paper-sizes.xml" )
{
- parser.readFile( dir.absoluteFilePath( fileName ) );
+ auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
+ for ( auto& paper : list )
+ {
+ registerPaper( paper );
+ }
}
}
}
+ void Db::registerPaper( const Paper& paper )
+ {
+ if ( !isPaperIdKnown( paper.id() ) )
+ {
+ mPapers.push_back( paper );
+ mPapersNameMap[ paper.name() ] = paper;
+ mPapersIdMap[ paper.id() ] = paper;
+ mPaperIds.push_back( paper.id() );
+ mPaperNames.push_back( paper.name() );
+ }
+ else
+ {
+ qWarning() << "Duplicate paper ID: " << paper.id();
+ }
+ }
+
+
void Db::readCategories()
{
readCategoriesFromDir( FileUtil::systemTemplatesDir() );
@@ -688,16 +577,37 @@ namespace glabels
{
XmlCategoryParser parser;
- foreach ( QString fileName, dir.entryList( QDir::Files ) )
+ for ( auto fileName : dir.entryList( QDir::Files ) )
{
if ( fileName == "categories.xml" )
{
- parser.readFile( dir.absoluteFilePath( fileName ) );
+ auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
+ for ( auto& category : list )
+ {
+ registerCategory( category );
+ }
}
}
}
+ void Db::registerCategory( const Category& category )
+ {
+ if ( !isCategoryIdKnown( category.id() ) )
+ {
+ mCategories.push_back( category );
+ mCategoriesNameMap[ category.name() ] = category;
+ mCategoriesIdMap[ category.id() ] = category;
+ mCategoryIds.push_back( category.id() );
+ mCategoryNames.push_back( category.name() );
+ }
+ else
+ {
+ qWarning() << "Duplicate category ID: " << category.id();
+ }
+ }
+
+
void Db::readVendors()
{
readVendorsFromDir( FileUtil::systemTemplatesDir() );
@@ -708,36 +618,98 @@ namespace glabels
{
XmlVendorParser parser;
- foreach ( QString fileName, dir.entryList( QDir::Files ) )
+ for ( auto fileName : dir.entryList( QDir::Files ) )
{
if ( fileName == "vendors.xml" )
{
- parser.readFile( dir.absoluteFilePath( fileName ) );
+ auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
+ for ( auto& vendor : list )
+ {
+ registerVendor( vendor );
+ }
}
}
}
+ void Db::registerVendor( const Vendor& vendor )
+ {
+ if ( !isVendorNameKnown( vendor.name() ) )
+ {
+ mVendors.push_back( vendor );
+ mVendorsNameMap[ vendor.name() ] = vendor;
+ mVendorNames.push_back( vendor.name() );
+ }
+ else
+ {
+ qWarning() << "Duplicate vendor name: " << vendor.name();
+ }
+ }
+
+
void Db::readTemplates()
{
- readTemplatesFromDir( FileUtil::systemTemplatesDir(), false );
- readTemplatesFromDir( FileUtil::manualUserTemplatesDir(), false );
- readTemplatesFromDir( FileUtil::userTemplatesDir(), true );
+ readTemplatesFromDir( FileUtil::systemTemplatesDir() );
+ readTemplatesFromDir( FileUtil::manualUserTemplatesDir() );
std::stable_sort( mTemplates.begin(), mTemplates.end(), partNameLessThan );
+
+ readUserTemplatesFromDir( FileUtil::userTemplatesDir() );
}
- void Db::readTemplatesFromDir( const QDir& dir, bool isUserDefined )
+ void Db::readTemplatesFromDir( const QDir& dir )
{
QStringList filters;
filters << "*-templates.xml" << "*.template";
XmlTemplateParser parser;
- foreach ( QString fileName, dir.entryList( filters, QDir::Files ) )
+ for ( auto& fileName : dir.entryList( filters, QDir::Files ) )
{
- parser.readFile( dir.absoluteFilePath( fileName ), isUserDefined );
+ auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
+ for ( auto& tmplate : list )
+ {
+ registerTemplate( tmplate );
+ }
+
+ list = parser.readEquivsFromFile( dir.absoluteFilePath( fileName ) );
+ for ( auto& tmplate : list )
+ {
+ registerTemplate( tmplate );
+ }
+ }
+ }
+
+
+ void Db::registerTemplate( const Template& tmplate )
+ {
+ if ( !isTemplateKnown( tmplate.brand(), tmplate.part() ) )
+ {
+ mTemplates.push_back( tmplate );
+ mTemplatesNameMap[ tmplate.name() ] = tmplate;
+ }
+ else
+ {
+ qWarning() << "Duplicate template name: " << tmplate.name();
+ }
+ }
+
+
+ void Db::readUserTemplatesFromDir( const QDir& dir )
+ {
+ QStringList filters;
+ filters << "*-templates.xml" << "*.template";
+
+ XmlTemplateParser parser;
+
+ for ( auto& fileName : dir.entryList( filters, QDir::Files ) )
+ {
+ auto list = parser.readFile( dir.absoluteFilePath( fileName ) );
+ for ( auto& tmplate : list )
+ {
+ registerUserTemplate( tmplate );
+ }
}
}
diff --git a/model/Db.h b/model/Db.h
index dbebb35..071bf79 100644
--- a/model/Db.h
+++ b/model/Db.h
@@ -27,7 +27,6 @@
#include "Template.h"
#include "Vendor.h"
-#include
#include
#include
#include
@@ -40,60 +39,55 @@ namespace glabels
class Db
{
- Q_DECLARE_TR_FUNCTIONS(Db)
- private:
- Db();
-
-
public:
+ Db() = delete;
+
static void init();
- static Db* instance();
- static const QList& papers();
+ static const QList& papers();
static const QStringList& paperIds();
static const QStringList& paperNames();
- static const QList& categories();
+ static const QList& categories();
static const QStringList& categoryIds();
static const QStringList& categoryNames();
- static const QList& vendors();
+ static const QList& vendors();
static const QStringList& vendorNames();
- static const QList& templates();
+ static QList templates();
- static void registerPaper( Paper *paper );
- static const Paper *lookupPaperFromName( const QString& name );
- static const Paper *lookupPaperFromId( const QString& id );
+ static const Paper lookupPaperFromName( const QString& name );
+ static const Paper lookupPaperFromId( const QString& id );
static QString lookupPaperIdFromName( const QString& name );
static QString lookupPaperNameFromId( const QString& id );
static bool isPaperIdKnown( const QString& id );
- static void registerCategory( Category *category );
- static const Category *lookupCategoryFromName( const QString& name );
- static const Category *lookupCategoryFromId( const QString& id );
+ static const Category lookupCategoryFromName( const QString& name );
+ static const Category lookupCategoryFromId( const QString& id );
static QString lookupCategoryIdFromName( const QString& name );
static QString lookupCategoryNameFromId( const QString& id );
static bool isCategoryIdKnown( const QString& id );
- static void registerVendor( Vendor *vendor );
- static const Vendor *lookupVendorFromName( const QString& name );
+ static const Vendor lookupVendorFromName( const QString& name );
static QString lookupVendorUrlFromName( const QString& name );
static bool isVendorNameKnown( const QString& id );
- static void registerTemplate( Template *tmplate );
- static const Template *lookupTemplateFromName( const QString& name );
- static const Template *lookupTemplateFromBrandPart( const QString& brand,
- const QString& part );
+ static const Template lookupTemplateFromName( const QString& name );
+ static const Template lookupTemplateFromBrandPart( const QString& brand,
+ const QString& part );
+ static const Template lookupUserTemplateFromBrandPart( const QString& brand,
+ const QString& part );
static bool isTemplateKnown( const QString& brand, const QString& part );
static bool isSystemTemplateKnown( const QString& brand, const QString& part );
+ static bool isUserTemplateKnown( const QString& brand, const QString& part );
static QStringList getNameListOfSimilarTemplates( const QString& name );
- static QString userTemplateFilename( const QString& brand, const QString& part );
- static void registerUserTemplate( Template *tmplate );
+ static QString userTemplateFileName( const QString& brand, const QString& part );
+ static void registerUserTemplate( const Template &tmplate );
static void deleteUserTemplateByBrandPart( const QString& brand,
const QString& part );
@@ -108,30 +102,44 @@ namespace glabels
static void readPapers();
static void readPapersFromDir( const QDir& dir );
+ static void registerPaper( const Paper& paper );
static void readCategories();
static void readCategoriesFromDir( const QDir& dir );
+ static void registerCategory( const Category& category );
static void readVendors();
static void readVendorsFromDir( const QDir& dir );
+ static void registerVendor( const Vendor& vendor );
static void readTemplates();
- static void readTemplatesFromDir( const QDir& dir, bool isUserDefined );
+ static void readTemplatesFromDir( const QDir& dir );
+ static void registerTemplate( const Template& tmplate );
+
+ static void readUserTemplatesFromDir( const QDir& dir );
private:
- static QList mPapers;
- static QStringList mPaperIds;
- static QStringList mPaperNames;
+ static QList mPapers;
+ static QMap mPapersNameMap;
+ static QMap mPapersIdMap;
+ static QStringList mPaperIds;
+ static QStringList mPaperNames;
- static QList mCategories;
- static QStringList mCategoryIds;
- static QStringList mCategoryNames;
+ static QList mCategories;
+ static QMap mCategoriesNameMap;
+ static QMap mCategoriesIdMap;
+ static QStringList mCategoryIds;
+ static QStringList mCategoryNames;
- static QList mVendors;
- static QStringList mVendorNames;
+ static QList mVendors;
+ static QMap mVendorsNameMap;
+ static QStringList mVendorNames;
- static QList mTemplates;
+ static QList mTemplates;
+ static QMap mTemplatesNameMap;
+
+ static QMap mUserTemplatesNameMap;
};
diff --git a/model/Distance.cpp b/model/Distance.cpp
index b510f00..aa46073 100644
--- a/model/Distance.cpp
+++ b/model/Distance.cpp
@@ -56,7 +56,7 @@ namespace glabels
}
- Distance::Distance( double d, const Units& units )
+ Distance::Distance( double d, Units units )
{
switch (units.toEnum())
{
@@ -128,7 +128,7 @@ namespace glabels
}
- double Distance::inUnits( const Units& units ) const
+ double Distance::inUnits( Units units ) const
{
double d;
@@ -188,7 +188,7 @@ namespace glabels
}
- QString Distance::toString( const Units& units ) const
+ QString Distance::toString( Units units ) const
{
return QString::number( inUnits(units) ) + units.toIdString();
}
@@ -211,7 +211,7 @@ namespace glabels
}
-QDebug operator<<( QDebug dbg, const glabels::model::Distance& distance )
+QDebug operator<<( QDebug dbg, glabels::model::Distance distance )
{
QDebugStateSaver saver(dbg);
diff --git a/model/Distance.h b/model/Distance.h
index 0f7f2c3..585d776 100644
--- a/model/Distance.h
+++ b/model/Distance.h
@@ -41,7 +41,7 @@ namespace glabels
public:
Distance();
Distance( double d, Units::Enum unitsEnum = Units::PT );
- Distance( double d, const Units& units );
+ Distance( double d, Units units );
Distance( double d, const QString& unitsId );
static Distance pt( double dPts );
@@ -57,38 +57,38 @@ namespace glabels
double mm() const;
double cm() const;
double pc() const;
- double inUnits( const Units& units ) const;
+ double inUnits( Units units ) const;
double inUnits( Units::Enum unitsEnum ) const;
double inUnits( const QString& unitsId ) const;
- QString toString( const Units& units ) const;
+ QString toString( Units units ) const;
QString toString( Units::Enum unitsEnum ) const;
QString toString( const QString& unitsId ) const;
- Distance& operator+=( const Distance& d );
- Distance& operator-=( const Distance& d );
+ Distance& operator+=( Distance d );
+ Distance& operator-=( Distance d );
Distance& operator*=( double f );
Distance operator-();
- friend inline Distance operator+( const Distance& d1, const Distance& d2 );
- friend inline Distance operator-( const Distance& d1, const Distance& d2 );
- friend inline Distance operator*( double x, const Distance& d );
- friend inline Distance operator*( const Distance& d, double x );
- friend inline double operator/( const Distance& d1, const Distance& d2 );
- friend inline Distance operator/( const Distance& d, double x );
+ friend inline Distance operator+( Distance d1, Distance d2 );
+ friend inline Distance operator-( Distance d1, Distance d2 );
+ friend inline Distance operator*( double x, Distance d );
+ friend inline Distance operator*( Distance d, double x );
+ friend inline double operator/( Distance d1, Distance d2 );
+ friend inline Distance operator/( Distance d, double x );
- friend inline bool operator<( const Distance& d1, const Distance& d2 );
- friend inline bool operator<=( const Distance& d1, const Distance& d2 );
- friend inline bool operator>( const Distance& d1, const Distance& d2 );
- friend inline bool operator>=( const Distance& d1, const Distance& d2 );
- friend inline bool operator==( const Distance& d1, const Distance& d2 );
- friend inline bool operator!=( const Distance& d1, const Distance& d2 );
+ friend inline bool operator<( Distance d1, Distance d2 );
+ friend inline bool operator<=( Distance d1, Distance d2 );
+ friend inline bool operator>( Distance d1, Distance d2 );
+ friend inline bool operator>=( Distance d1, Distance d2 );
+ friend inline bool operator==( Distance d1, Distance d2 );
+ friend inline bool operator!=( Distance d1, Distance d2 );
- friend inline Distance fabs( const Distance& d );
- friend inline Distance min( const Distance& d1, const Distance& d2 );
- friend inline Distance max( const Distance& d1, const Distance& d2 );
- friend inline Distance fmod( const Distance& d1, const Distance& d2 );
+ friend inline Distance fabs( Distance d );
+ friend inline Distance min( Distance d1, Distance d2 );
+ friend inline Distance max( Distance d1, Distance d2 );
+ friend inline Distance fmod( Distance d1, Distance d2 );
private:
@@ -101,7 +101,7 @@ namespace glabels
// Debugging support
-QDebug operator<<( QDebug dbg, const glabels::model::Distance& distance );
+QDebug operator<<( QDebug dbg, const glabels::model::Distance distance );
//
@@ -190,14 +190,14 @@ namespace glabels
}
- inline Distance& Distance::operator+=( const Distance& d )
+ inline Distance& Distance::operator+=( Distance d )
{
mDPts += d.mDPts;
return *this;
}
- inline Distance& Distance::operator-=( const Distance& d )
+ inline Distance& Distance::operator-=( Distance d )
{
mDPts -= d.mDPts;
return *this;
@@ -217,97 +217,97 @@ namespace glabels
}
- inline Distance operator+( const Distance& d1, const Distance& d2 )
+ inline Distance operator+( Distance d1, Distance d2 )
{
return Distance::pt( d1.mDPts + d2.mDPts );
}
- inline Distance operator-( const Distance& d1, const Distance& d2 )
+ inline Distance operator-( Distance d1, Distance d2 )
{
return Distance::pt( d1.mDPts - d2.mDPts );
}
- inline Distance operator*( double x, const Distance& d )
+ inline Distance operator*( double x, Distance d )
{
return Distance::pt( x * d.mDPts );
}
- inline Distance operator*( const Distance& d, double x )
+ inline Distance operator*( Distance d, double x )
{
return Distance::pt( d.mDPts * x );
}
- inline double operator/( const Distance& d1, const Distance& d2 )
+ inline double operator/( Distance d1, Distance d2 )
{
return d1.mDPts / d2.mDPts;
}
- inline Distance operator/( const Distance& d, double x )
+ inline Distance operator/( Distance d, double x )
{
return Distance::pt( d.mDPts / x );
}
- inline bool operator<( const Distance& d1, const Distance& d2 )
+ inline bool operator<( Distance d1, Distance d2 )
{
return d1.mDPts < d2.mDPts;
}
- inline bool operator<=( const Distance& d1, const Distance& d2 )
+ inline bool operator<=( Distance d1, Distance d2 )
{
return d1.mDPts <= d2.mDPts;
}
- inline bool operator>( const Distance& d1, const Distance& d2 )
+ inline bool operator>( Distance d1, Distance d2 )
{
return d1.mDPts > d2.mDPts;
}
- inline bool operator>=( const Distance& d1, const Distance& d2 )
+ inline bool operator>=( Distance d1, Distance d2 )
{
return d1.mDPts >= d2.mDPts;
}
- inline bool operator==( const Distance& d1, const Distance& d2 )
+ inline bool operator==( Distance d1, Distance d2 )
{
return d1.mDPts == d2.mDPts;
}
- inline bool operator!=( const Distance& d1, const Distance& d2 )
+ inline bool operator!=( Distance d1, Distance d2 )
{
return d1.mDPts != d2.mDPts;
}
- inline Distance fabs( const Distance& d )
+ inline Distance fabs( Distance d )
{
return Distance::pt( qFabs( d.mDPts ) );
}
- inline Distance min( const Distance& d1, const Distance& d2 )
+ inline Distance min( Distance d1, Distance d2 )
{
return (d1.mDPts < d2.mDPts) ? d1 : d2;
}
- inline Distance max( const Distance& d1, const Distance& d2 )
+ inline Distance max( Distance d1, Distance d2 )
{
return (d1.mDPts > d2.mDPts) ? d1 : d2;
}
- inline Distance fmod( const Distance& d1, const Distance& d2 )
+ inline Distance fmod( Distance d1, Distance d2 )
{
return Distance::pt( std::fmod( d1.mDPts, d2.mDPts ) );
}
diff --git a/model/Frame.cpp b/model/Frame.cpp
index 36089f1..8b9111a 100644
--- a/model/Frame.cpp
+++ b/model/Frame.cpp
@@ -18,15 +18,11 @@
* along with gLabels-qt. If not, see .
*/
+
+
#include "Frame.h"
-#include "FrameCd.h"
-#include "FrameContinuous.h"
-#include "FrameEllipse.h"
-#include "FramePath.h"
-#include "FrameRect.h"
-#include "FrameRound.h"
-#include "Markup.h"
+#include
#include
@@ -37,7 +33,9 @@ namespace glabels
{
Frame::Frame( const QString& id )
- : mId(id), mNLabels(0), mLayoutDescription("")
+ : mId(id),
+ mNLabels(0),
+ mLayoutDescription("")
{
// empty
}
@@ -48,23 +46,14 @@ namespace glabels
mId = other.mId;
mNLabels = 0;
- foreach ( const Layout& layout, other.mLayouts )
+ for ( const auto& layout : other.mLayouts )
{
addLayout( layout );
}
- foreach ( Markup *markup, other.mMarkups )
+ for ( const auto& markup : other.mMarkups )
{
- addMarkup( markup->dup() );
- }
- }
-
-
- Frame::~Frame()
- {
- while ( !mMarkups.isEmpty() )
- {
- delete mMarkups.takeFirst();
+ mMarkups.push_back( markup->clone() );
}
}
@@ -87,13 +76,13 @@ namespace glabels
}
- const QList& Frame::layouts() const
+ const std::list& Frame::layouts() const
{
return mLayouts;
}
- const QList& Frame::markups() const
+ const std::list>& Frame::markups() const
{
return mMarkups;
}
@@ -104,7 +93,7 @@ namespace glabels
QVector origins( nLabels() );
int i = 0;
- foreach ( const Layout& layout, mLayouts )
+ for ( auto& layout : mLayouts )
{
for ( int iy = 0; iy < layout.ny(); iy++ )
{
@@ -123,7 +112,7 @@ namespace glabels
void Frame::addLayout( const Layout& layout )
{
- mLayouts << layout;
+ mLayouts.push_back( layout );
// Update total number of labels
mNLabels += layout.nx() * layout.ny();
@@ -147,15 +136,16 @@ namespace glabels
}
- void Frame::addMarkup( Markup *markup )
+ void Frame::addMarkup( const Markup& markup )
{
- mMarkups << markup;
+ mMarkups.push_back( markup.clone() );
}
- void Frame::setH( const Distance& h )
+ bool Frame::setH( Distance h )
{
// Default implementation does nothing
+ return false;
}
}
@@ -164,42 +154,9 @@ namespace glabels
QDebug operator<<( QDebug dbg, const glabels::model::Frame& frame )
{
- if ( auto* frameCd = dynamic_cast(&frame) )
- {
- dbg << *frameCd;
- return dbg;
- }
- else if ( auto* frameContinuous = dynamic_cast(&frame) )
- {
- dbg << *frameContinuous;
- return dbg;
- }
- else if ( auto* frameEllipse = dynamic_cast(&frame) )
- {
- dbg << *frameEllipse;
- return dbg;
- }
- else if ( auto* framePath = dynamic_cast(&frame) )
- {
- dbg << *framePath;
- return dbg;
- }
- else if ( auto* frameRect = dynamic_cast(&frame) )
- {
- dbg << *frameRect;
- return dbg;
- }
- else if ( auto* frameRound = dynamic_cast(&frame) )
- {
- dbg << *frameRound;
- return dbg;
- }
- else
- {
- QDebugStateSaver saver(dbg);
+ QDebugStateSaver saver(dbg);
- dbg.nospace() << "UNKNOWN FRAME";
+ frame.print( dbg );
- return dbg;
- }
+ return dbg;
}
diff --git a/model/Frame.h b/model/Frame.h
index b657a91..c8ac9c1 100644
--- a/model/Frame.h
+++ b/model/Frame.h
@@ -24,25 +24,23 @@
#include "Distance.h"
#include "Layout.h"
+#include "Markup.h"
#include "Point.h"
#include
#include
-#include
#include
#include
#include
+#include
+
namespace glabels
{
namespace model
{
- // Forward references
- class Markup;
-
-
class Frame
{
Q_DECLARE_TR_FUNCTIONS(Frame)
@@ -52,32 +50,35 @@ namespace glabels
Frame( const Frame& other );
public:
- virtual ~Frame();
- virtual Frame* dup() const = 0;
+ virtual ~Frame() = default;
+
+ virtual std::unique_ptr clone() const = 0;
QString id() const;
int nLabels() const;
QString layoutDescription() const;
- const QList& layouts() const;
- const QList& markups() const;
+ const std::list& layouts() const;
+ const std::list>& markups() const;
QVector getOrigins() const;
void addLayout( const Layout& layout );
- void addMarkup( Markup* markup );
+ void addMarkup( const Markup& markup );
virtual Distance w() const = 0;
virtual Distance h() const = 0;
- virtual void setH( const Distance& h );
+ virtual bool setH( Distance h );
- virtual QString sizeDescription( const Units& units ) const = 0;
- virtual bool isSimilarTo( Frame* other ) const = 0;
+ virtual QString sizeDescription( Units units ) const = 0;
+ virtual bool isSimilarTo( const Frame& other ) const = 0;
virtual const QPainterPath& path() const = 0;
virtual const QPainterPath& clipPath() const = 0;
- virtual QPainterPath marginPath( const Distance& xSize,
- const Distance& ySize ) const = 0;
+ virtual QPainterPath marginPath( Distance xSize, Distance ySize ) const = 0;
+
+ // Debugging support
+ virtual void print( QDebug& dbg ) const = 0;
private:
@@ -85,8 +86,8 @@ namespace glabels
int mNLabels;
QString mLayoutDescription;
- QList mLayouts;
- QList mMarkups;
+ std::list mLayouts;
+ std::list> mMarkups;
};
}
diff --git a/model/FrameCd.cpp b/model/FrameCd.cpp
index 84322a9..23d5217 100644
--- a/model/FrameCd.cpp
+++ b/model/FrameCd.cpp
@@ -18,12 +18,13 @@
* along with gLabels-qt. If not, see .
*/
+
#include "FrameCd.h"
#include "Constants.h"
#include "StrUtil.h"
-#include
+#include
namespace glabels
@@ -31,13 +32,18 @@ namespace glabels
namespace model
{
- FrameCd::FrameCd( const Distance& r1,
- const Distance& r2,
- const Distance& w,
- const Distance& h,
- const Distance& waste,
- const QString& id )
- : Frame(id), mR1(r1), mR2(r2), mW(w), mH(h), mWaste(waste)
+ FrameCd::FrameCd( Distance r1,
+ Distance r2,
+ Distance w,
+ Distance h,
+ Distance waste,
+ const QString& id )
+ : Frame(id),
+ mR1(r1),
+ mR2(r2),
+ mW(w),
+ mH(h),
+ mWaste(waste)
{
Distance wReal = (mW == 0) ? 2*mR1 : mW;
Distance hReal = (mH == 0) ? 2*mR1 : mH;
@@ -93,9 +99,9 @@ namespace glabels
}
- Frame* FrameCd::dup() const
+ std::unique_ptr FrameCd::clone() const
{
- return new FrameCd( *this );
+ return std::make_unique( *this );
}
@@ -129,7 +135,7 @@ namespace glabels
}
- QString FrameCd::sizeDescription( const Units& units ) const
+ QString FrameCd::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -145,9 +151,9 @@ namespace glabels
}
- bool FrameCd::isSimilarTo( Frame* other ) const
+ bool FrameCd::isSimilarTo( const Frame& other ) const
{
- if ( auto *otherCd = dynamic_cast(other) )
+ if ( auto *otherCd = dynamic_cast(&other) )
{
if ( (fabs( mW - otherCd->mW ) <= EPSILON) &&
(fabs( mH - otherCd->mH ) <= EPSILON) &&
@@ -173,8 +179,7 @@ namespace glabels
}
- QPainterPath FrameCd::marginPath( const Distance& xSize,
- const Distance& ySize ) const
+ QPainterPath FrameCd::marginPath( Distance xSize, Distance ySize ) const
{
// Note: ignore ySize, assume xSize == ySize
Distance size = xSize;
@@ -207,24 +212,33 @@ namespace glabels
return path;
}
+
+ // Debugging support
+ void FrameCd::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "FrameCd{ "
+ << id() << ","
+ << r1() << ","
+ << r2() << ","
+ << waste() << ","
+ << w() << ","
+ << h() << ","
+ << "list{ ";
+ for ( auto& layout : layouts() )
+ {
+ dbg.nospace() << layout << ",";
+ }
+ dbg.nospace() << " }"
+ << "list{ ";
+ for ( auto& markup : markups() )
+ {
+ dbg.nospace() << *markup << ",";
+ }
+ dbg.nospace() << " }"
+ << " }";
+ }
+
}
}
-QDebug operator<<( QDebug dbg, const glabels::model::FrameCd& frame )
-{
- QDebugStateSaver saver(dbg);
-
- dbg.nospace() << "FrameCd{ "
- << frame.id() << ","
- << frame.r1() << ","
- << frame.r2() << ","
- << frame.waste() << ","
- << frame.w() << ","
- << frame.h() << ","
- << frame.layouts() << ","
- << frame.markups()
- << " }";
-
- return dbg;
-}
diff --git a/model/FrameCd.h b/model/FrameCd.h
index 557ed07..e49e622 100644
--- a/model/FrameCd.h
+++ b/model/FrameCd.h
@@ -35,16 +35,16 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameCd)
public:
- FrameCd( const Distance& r1,
- const Distance& r2,
- const Distance& w,
- const Distance& h,
- const Distance& waste,
- const QString& id = "0" );
+ FrameCd( Distance r1,
+ Distance r2,
+ Distance w,
+ Distance h,
+ Distance waste,
+ const QString& id = "0" );
FrameCd( const FrameCd &other ) = default;
- Frame *dup() const override;
+ std::unique_ptr clone() const override;
Distance r1() const;
Distance r2() const;
@@ -53,13 +53,15 @@ namespace glabels
Distance w() const override;
Distance h() const override;
- QString sizeDescription( const Units& units ) const override;
- bool isSimilarTo( Frame* other ) const override;
+ QString sizeDescription( Units units ) const override;
+ bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
- QPainterPath marginPath( const Distance& xSize,
- const Distance& ySize ) const override;
+ QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
@@ -78,8 +80,4 @@ namespace glabels
}
-// Debugging support
-QDebug operator<<( QDebug dbg, const glabels::model::FrameCd& frame );
-
-
#endif // model_FrameCd_h
diff --git a/model/FrameContinuous.cpp b/model/FrameContinuous.cpp
index 5530b9e..9843d5f 100644
--- a/model/FrameContinuous.cpp
+++ b/model/FrameContinuous.cpp
@@ -18,31 +18,39 @@
* along with gLabels-qt. If not, see .
*/
+
#include "FrameContinuous.h"
#include "Constants.h"
#include "StrUtil.h"
+#include
+
namespace glabels
{
namespace model
{
- FrameContinuous::FrameContinuous( const Distance& w,
- const Distance& hMin,
- const Distance& hMax,
- const Distance& hDefault,
- const QString& id )
- : Frame(id), mW(w), mHMin(hMin), mHMax(hMax), mHDefault(hDefault), mH(hDefault)
+ FrameContinuous::FrameContinuous( Distance w,
+ Distance hMin,
+ Distance hMax,
+ Distance hDefault,
+ const QString& id )
+ : Frame(id),
+ mW(w),
+ mHMin(hMin),
+ mHMax(hMax),
+ mHDefault(hDefault),
+ mH(hDefault)
{
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
}
- Frame* FrameContinuous::dup() const
+ std::unique_ptr FrameContinuous::clone() const
{
- return new FrameContinuous( *this );
+ return std::make_unique( *this );
}
@@ -76,15 +84,16 @@ namespace glabels
}
- void FrameContinuous::setH( const Distance& h )
+ bool FrameContinuous::setH( Distance h )
{
mH = h;
mPath = QPainterPath(); // clear path
mPath.addRect( 0, 0, mW.pt(), mH.pt() );
+ return true;
}
- QString FrameContinuous::sizeDescription( const Units& units ) const
+ QString FrameContinuous::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -99,9 +108,9 @@ namespace glabels
}
- bool FrameContinuous::isSimilarTo( Frame* other ) const
+ bool FrameContinuous::isSimilarTo( const Frame& other ) const
{
- if ( auto *otherContinuous = dynamic_cast(other) )
+ if ( auto *otherContinuous = dynamic_cast(&other) )
{
if ( fabs( mW - otherContinuous->mW ) <= EPSILON )
{
@@ -124,8 +133,7 @@ namespace glabels
}
- QPainterPath FrameContinuous::marginPath( const Distance& xSize,
- const Distance& ySize ) const
+ QPainterPath FrameContinuous::marginPath( Distance xSize, Distance ySize ) const
{
Distance w = mW - 2*xSize;
Distance h = mH - 2*ySize;
@@ -137,24 +145,31 @@ namespace glabels
}
+ // Debugging support
+ void FrameContinuous::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "FrameContinuous{ "
+ << id() << ","
+ << w() << ","
+ << h() << ","
+ << hMin() << ","
+ << hMax() << ","
+ << hDefault() << ","
+ << "list{ ";
+ for ( auto& layout : layouts() )
+ {
+ dbg.nospace() << layout << ",";
+ }
+ dbg.nospace() << " }"
+ << "list{ ";
+ for ( auto& markup : markups() )
+ {
+ dbg.nospace() << *markup << ",";
+ }
+ dbg.nospace() << " }"
+ << " }";
+ }
+
+
}
}
-
-
-QDebug operator<<( QDebug dbg, const glabels::model::FrameContinuous& frame )
-{
- QDebugStateSaver saver(dbg);
-
- dbg.nospace() << "FrameContinuous{ "
- << frame.id() << ","
- << frame.w() << ","
- << frame.h() << ","
- << frame.hMin() << ","
- << frame.hMax() << ","
- << frame.hDefault() << ","
- << frame.layouts() << ","
- << frame.markups()
- << " }";
-
- return dbg;
-}
diff --git a/model/FrameContinuous.h b/model/FrameContinuous.h
index f2e5cc9..da51276 100644
--- a/model/FrameContinuous.h
+++ b/model/FrameContinuous.h
@@ -35,15 +35,15 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameContinuous)
public:
- FrameContinuous( const Distance& w,
- const Distance& hMin,
- const Distance& hMax,
- const Distance& hDefault,
- const QString& id = "0" );
+ FrameContinuous( Distance w,
+ Distance hMin,
+ Distance hMax,
+ Distance hDefault,
+ const QString& id = "0" );
FrameContinuous( const FrameContinuous& other ) = default;
- Frame* dup() const override;
+ std::unique_ptr clone() const override;
Distance w() const override;
Distance h() const override;
@@ -52,16 +52,18 @@ namespace glabels
Distance hMax() const;
Distance hDefault() const;
- void setH( const Distance& h ) override;
+ bool setH( Distance h ) override;
- QString sizeDescription( const Units& units ) const override;
+ QString sizeDescription( Units units ) const override;
- bool isSimilarTo( Frame* other ) const override;
+ bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
- QPainterPath marginPath( const Distance& xSize,
- const Distance& ySize ) const override;
+ QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
@@ -78,8 +80,4 @@ namespace glabels
}
-// Debugging support
-QDebug operator<<( QDebug dbg, const glabels::model::FrameContinuous& frame );
-
-
#endif // model_FrameContinuous_h
diff --git a/model/FrameEllipse.cpp b/model/FrameEllipse.cpp
index 79c9661..cff344f 100644
--- a/model/FrameEllipse.cpp
+++ b/model/FrameEllipse.cpp
@@ -18,31 +18,37 @@
* along with gLabels-qt. If not, see .
*/
+
#include "FrameEllipse.h"
#include "Constants.h"
#include "StrUtil.h"
+#include
+
namespace glabels
{
namespace model
{
- FrameEllipse::FrameEllipse( const Distance& w,
- const Distance& h,
- const Distance& waste,
- const QString& id )
- : Frame(id), mW(w), mH(h), mWaste(waste)
+ FrameEllipse::FrameEllipse( Distance w,
+ Distance h,
+ Distance waste,
+ const QString& id )
+ : Frame(id),
+ mW(w),
+ mH(h),
+ mWaste(waste)
{
mPath.addEllipse( 0, 0, mW.pt(), mH.pt() );
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), (mW+2*mWaste).pt(), (mH+2*mWaste).pt() );
}
- Frame* FrameEllipse::dup() const
+ std::unique_ptr FrameEllipse::clone() const
{
- return new FrameEllipse( *this );
+ return std::make_unique( *this );
}
@@ -64,7 +70,7 @@ namespace glabels
}
- QString FrameEllipse::sizeDescription( const Units& units ) const
+ QString FrameEllipse::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -82,9 +88,9 @@ namespace glabels
}
- bool FrameEllipse::isSimilarTo( Frame* other ) const
+ bool FrameEllipse::isSimilarTo( const Frame& other ) const
{
- if ( auto* otherEllipse = dynamic_cast(other) )
+ if ( auto* otherEllipse = dynamic_cast(&other) )
{
if ( (fabs( mW - otherEllipse->mW ) <= EPSILON) &&
(fabs( mH - otherEllipse->mH ) <= EPSILON) )
@@ -108,8 +114,7 @@ namespace glabels
}
- QPainterPath FrameEllipse::marginPath( const Distance& xSize,
- const Distance& ySize ) const
+ QPainterPath FrameEllipse::marginPath( Distance xSize, Distance ySize ) const
{
// Note: ignore ySize, assume xSize == ySize
Distance size = xSize;
@@ -123,22 +128,30 @@ namespace glabels
return path;
}
+
+ // Debugging support
+ void FrameEllipse::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "FrameEllipse{ "
+ << id() << ","
+ << w() << ","
+ << h() << ","
+ << waste() << ","
+ << "list{ ";
+ for ( auto& layout : layouts() )
+ {
+ dbg.nospace() << layout << ",";
+ }
+ dbg.nospace() << " }"
+ << "list{ ";
+ for ( auto& markup : markups() )
+ {
+ dbg.nospace() << *markup << ",";
+ }
+ dbg.nospace() << " }"
+ << " }";
+ }
+
+
}
}
-
-
-QDebug operator<<( QDebug dbg, const glabels::model::FrameEllipse& frame )
-{
- QDebugStateSaver saver(dbg);
-
- dbg.nospace() << "FrameEllipse{ "
- << frame.id() << ","
- << frame.w() << ","
- << frame.h() << ","
- << frame.waste() << ","
- << frame.layouts() << ","
- << frame.markups()
- << " }";
-
- return dbg;
-}
diff --git a/model/FrameEllipse.h b/model/FrameEllipse.h
index 1816949..8374bd6 100644
--- a/model/FrameEllipse.h
+++ b/model/FrameEllipse.h
@@ -35,27 +35,29 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameEllipse)
public:
- FrameEllipse( const Distance& w,
- const Distance& h,
- const Distance& waste,
- const QString& id = "0" );
+ FrameEllipse( Distance w,
+ Distance h,
+ Distance waste,
+ const QString& id = "0" );
FrameEllipse( const FrameEllipse& other ) = default;
- Frame* dup() const override;
+ std::unique_ptr clone() const override;
Distance waste() const;
Distance w() const override;
Distance h() const override;
- QString sizeDescription( const Units& units ) const override;
- bool isSimilarTo( Frame* other ) const override;
+ QString sizeDescription( Units units ) const override;
+ bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
- QPainterPath marginPath( const Distance& xSize,
- const Distance& ySize ) const override;
+ QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
@@ -72,8 +74,4 @@ namespace glabels
}
-// Debugging support
-QDebug operator<<( QDebug dbg, const glabels::model::FrameEllipse& frame );
-
-
#endif // model_FrameEllipse_h
diff --git a/model/FramePath.cpp b/model/FramePath.cpp
index 18a3660..62e907b 100644
--- a/model/FramePath.cpp
+++ b/model/FramePath.cpp
@@ -18,11 +18,14 @@
* along with gLabels-qt. If not, see .
*/
+
#include "FramePath.h"
#include "Constants.h"
#include "StrUtil.h"
+#include
+
namespace glabels
{
@@ -30,11 +33,15 @@ namespace glabels
{
FramePath::FramePath( const QPainterPath& path,
- const Distance& xWaste,
- const Distance& yWaste,
- const Units& originalUnits,
+ Distance xWaste,
+ Distance yWaste,
+ Units originalUnits,
const QString& id )
- : Frame(id), mXWaste(xWaste), mYWaste(yWaste), mPath(path), mOriginalUnits(originalUnits)
+ : Frame(id),
+ mXWaste(xWaste),
+ mYWaste(yWaste),
+ mPath(path),
+ mOriginalUnits(originalUnits)
{
QRectF r = path.boundingRect();
@@ -46,9 +53,9 @@ namespace glabels
}
- Frame* FramePath::dup() const
+ std::unique_ptr FramePath::clone() const
{
- return new FramePath( *this );
+ return std::make_unique( *this );
}
@@ -82,7 +89,7 @@ namespace glabels
}
- QString FramePath::sizeDescription( const Units& units ) const
+ QString FramePath::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -100,9 +107,9 @@ namespace glabels
}
- bool FramePath::isSimilarTo( Frame* other ) const
+ bool FramePath::isSimilarTo( const Frame& other ) const
{
- if ( auto *otherPath = dynamic_cast(other) )
+ if ( auto *otherPath = dynamic_cast(&other) )
{
if ( mPath == otherPath->mPath )
{
@@ -125,29 +132,35 @@ namespace glabels
}
- QPainterPath FramePath::marginPath( const Distance& xSize,
- const Distance& ySize ) const
+ QPainterPath FramePath::marginPath( Distance xSize, Distance ySize ) const
{
return mPath; // No margin
}
+ // Debugging support
+ void FramePath::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "FramePath{ "
+ << id() << ","
+ << path() << ","
+ << xWaste() << ","
+ << yWaste() << ","
+ << "list{ ";
+ for ( auto& layout : layouts() )
+ {
+ dbg.nospace() << layout << ",";
+ }
+ dbg.nospace() << " }"
+ << "list{ ";
+ for ( auto& markup : markups() )
+ {
+ dbg.nospace() << *markup << ",";
+ }
+ dbg.nospace() << " }"
+ << " }";
+ }
+
+
}
}
-
-
-QDebug operator<<( QDebug dbg, const glabels::model::FramePath& frame )
-{
- QDebugStateSaver saver(dbg);
-
- dbg.nospace() << "FramePath{ "
- << frame.id() << ","
- << frame.path() << ","
- << frame.xWaste() << ","
- << frame.yWaste() << ","
- << frame.layouts() << ","
- << frame.markups()
- << " }";
-
- return dbg;
-}
diff --git a/model/FramePath.h b/model/FramePath.h
index 777f621..a0aab6a 100644
--- a/model/FramePath.h
+++ b/model/FramePath.h
@@ -36,14 +36,14 @@ namespace glabels
public:
FramePath( const QPainterPath& path,
- const Distance& xWaste,
- const Distance& yWaste,
- const Units& originalUnits,
+ Distance xWaste,
+ Distance yWaste,
+ Units originalUnits,
const QString& id = "0" );
FramePath( const FramePath& other ) = default;
- Frame* dup() const override;
+ std::unique_ptr clone() const override;
Distance xWaste() const;
Distance yWaste() const;
@@ -53,14 +53,16 @@ namespace glabels
Distance w() const override;
Distance h() const override;
- QString sizeDescription( const Units& units ) const override;
+ QString sizeDescription( Units units ) const override;
- bool isSimilarTo( Frame* other ) const override;
+ bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
- QPainterPath marginPath( const Distance& xSize,
- const Distance& ySize ) const override;
+ QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
@@ -79,8 +81,4 @@ namespace glabels
}
-// Debugging support
-QDebug operator<<( QDebug dbg, const glabels::model::FramePath& frame );
-
-
#endif // model_FramePath_h
diff --git a/model/FrameRect.cpp b/model/FrameRect.cpp
index aaca3a1..adcc65c 100644
--- a/model/FrameRect.cpp
+++ b/model/FrameRect.cpp
@@ -18,24 +18,32 @@
* along with gLabels-qt. If not, see .
*/
+
#include "FrameRect.h"
#include "Constants.h"
#include "StrUtil.h"
+#include
+
namespace glabels
{
namespace model
{
- FrameRect::FrameRect( const Distance& w,
- const Distance& h,
- const Distance& r,
- const Distance& xWaste,
- const Distance& yWaste,
- const QString& id )
- : Frame(id), mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste)
+ FrameRect::FrameRect( Distance w,
+ Distance h,
+ Distance r,
+ Distance xWaste,
+ Distance yWaste,
+ const QString& id )
+ : Frame(id),
+ mW(w),
+ mH(h),
+ mR(r),
+ mXWaste(xWaste),
+ mYWaste(yWaste)
{
mPath.addRoundedRect( 0, 0, mW.pt(), mH.pt(), mR.pt(), mR.pt() );
@@ -45,9 +53,9 @@ namespace glabels
}
- Frame* FrameRect::dup() const
+ std::unique_ptr FrameRect::clone() const
{
- return new FrameRect( *this );
+ return std::make_unique( *this );
}
@@ -81,7 +89,7 @@ namespace glabels
}
- QString FrameRect::sizeDescription( const Units& units ) const
+ QString FrameRect::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -99,9 +107,9 @@ namespace glabels
}
- bool FrameRect::isSimilarTo( Frame* other ) const
+ bool FrameRect::isSimilarTo( const Frame& other ) const
{
- if ( auto *otherRect = dynamic_cast(other) )
+ if ( auto *otherRect = dynamic_cast(&other) )
{
if ( (fabs( mW - otherRect->mW ) <= EPSILON) &&
(fabs( mH - otherRect->mH ) <= EPSILON) )
@@ -125,8 +133,7 @@ namespace glabels
}
- QPainterPath FrameRect::marginPath( const Distance& xSize,
- const Distance& ySize ) const
+ QPainterPath FrameRect::marginPath( Distance xSize, Distance ySize ) const
{
Distance w = mW - 2*xSize;
Distance h = mH - 2*ySize;
@@ -139,24 +146,31 @@ namespace glabels
}
+ // Debugging support
+ void FrameRect::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "FrameRect{ "
+ << id() << ","
+ << w() << ","
+ << h() << ","
+ << r() << ","
+ << xWaste() << ","
+ << yWaste() << ","
+ << "list{ ";
+ for ( auto& layout : layouts() )
+ {
+ dbg.nospace() << layout << ",";
+ }
+ dbg.nospace() << " }"
+ << "list{ ";
+ for ( auto& markup : markups() )
+ {
+ dbg.nospace() << *markup << ",";
+ }
+ dbg.nospace() << " }"
+ << " }";
+ }
+
+
}
}
-
-
-QDebug operator<<( QDebug dbg, const glabels::model::FrameRect& frame )
-{
- QDebugStateSaver saver(dbg);
-
- dbg.nospace() << "FrameRect{ "
- << frame.id() << ","
- << frame.w() << ","
- << frame.h() << ","
- << frame.r() << ","
- << frame.xWaste() << ","
- << frame.yWaste() << ","
- << frame.layouts() << ","
- << frame.markups()
- << " }";
-
- return dbg;
-}
diff --git a/model/FrameRect.h b/model/FrameRect.h
index cfad7df..9aadf37 100644
--- a/model/FrameRect.h
+++ b/model/FrameRect.h
@@ -35,16 +35,16 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameRect)
public:
- FrameRect( const Distance& w,
- const Distance& h,
- const Distance& r,
- const Distance& xWaste,
- const Distance& yWaste,
- const QString& id = "0" );
+ FrameRect( Distance w,
+ Distance h,
+ Distance r,
+ Distance xWaste,
+ Distance yWaste,
+ const QString& id = "0" );
FrameRect( const FrameRect& other ) = default;
- Frame* dup() const override;
+ std::unique_ptr clone() const override;
Distance r() const;
Distance xWaste() const;
@@ -53,14 +53,16 @@ namespace glabels
Distance w() const override;
Distance h() const override;
- QString sizeDescription( const Units& units ) const override;
+ QString sizeDescription( Units units ) const override;
- bool isSimilarTo( Frame* other ) const override;
+ bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
- QPainterPath marginPath( const Distance& xSize,
- const Distance& ySize ) const override;
+ QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
@@ -79,8 +81,4 @@ namespace glabels
}
-// Debugging support
-QDebug operator<<( QDebug dbg, const glabels::model::FrameRect& frame );
-
-
#endif // model_FrameRect_h
diff --git a/model/FrameRound.cpp b/model/FrameRound.cpp
index da44c6f..612d91c 100644
--- a/model/FrameRound.cpp
+++ b/model/FrameRound.cpp
@@ -18,21 +18,26 @@
* along with gLabels-qt. If not, see .
*/
+
#include "FrameRound.h"
#include "Constants.h"
#include "StrUtil.h"
+#include
+
namespace glabels
{
namespace model
{
- FrameRound::FrameRound( const Distance& r,
- const Distance& waste,
- const QString& id )
- : Frame(id), mR(r), mWaste(waste)
+ FrameRound::FrameRound( Distance r,
+ Distance waste,
+ const QString& id )
+ : Frame(id),
+ mR(r),
+ mWaste(waste)
{
mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() );
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(),
@@ -40,9 +45,9 @@ namespace glabels
}
- Frame* FrameRound::dup() const
+ std::unique_ptr FrameRound::clone() const
{
- return new FrameRound( *this );
+ return std::make_unique( *this );
}
@@ -70,7 +75,7 @@ namespace glabels
}
- QString FrameRound::sizeDescription( const Units& units ) const
+ QString FrameRound::sizeDescription( Units units ) const
{
if ( units.toEnum() == Units::IN )
{
@@ -86,9 +91,9 @@ namespace glabels
}
- bool FrameRound::isSimilarTo( Frame* other ) const
+ bool FrameRound::isSimilarTo( const Frame& other ) const
{
- if ( auto *otherRound = dynamic_cast(other) )
+ if ( auto *otherRound = dynamic_cast(&other) )
{
if ( fabs( mR - otherRound->mR ) <= EPSILON )
{
@@ -111,8 +116,7 @@ namespace glabels
}
- QPainterPath FrameRound::marginPath( const Distance& xSize,
- const Distance& ySize ) const
+ QPainterPath FrameRound::marginPath( Distance xSize, Distance ySize ) const
{
// Note: ignore ySize, assume xSize == ySize
Distance size = xSize;
@@ -125,21 +129,30 @@ namespace glabels
return path;
}
+
+ // Debugging support
+ void FrameRound::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "FrameRound{ "
+ << id() << ","
+ << r() << ","
+ << waste() << ","
+ << "list{ ";
+ for ( auto& layout : layouts() )
+ {
+ dbg.nospace() << layout << ",";
+ }
+ dbg.nospace() << " }"
+ << "list{ ";
+ for ( auto& markup : markups() )
+ {
+ dbg.nospace() << *markup << ",";
+ }
+ dbg.nospace() << " }"
+ << " }";
+ }
+
+
}
}
-
-
-QDebug operator<<( QDebug dbg, const glabels::model::FrameRound& frame )
-{
- QDebugStateSaver saver(dbg);
-
- dbg.nospace() << "FrameRound{ "
- << frame.id() << ","
- << frame.r() << ","
- << frame.waste() << ","
- << frame.layouts() << ","
- << frame.markups()
- << " }";
-
- return dbg;
-}
+
diff --git a/model/FrameRound.h b/model/FrameRound.h
index ab337ae..ced79d2 100644
--- a/model/FrameRound.h
+++ b/model/FrameRound.h
@@ -35,13 +35,13 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameRound)
public:
- FrameRound( const Distance& r,
- const Distance& waste,
- const QString& id = "0" );
+ FrameRound( Distance r,
+ Distance waste,
+ const QString& id = "0" );
FrameRound( const FrameRound &other ) = default;
- Frame *dup() const override;
+ std::unique_ptr clone() const override;
Distance r() const;
Distance waste() const;
@@ -49,13 +49,15 @@ namespace glabels
Distance w() const override;
Distance h() const override;
- QString sizeDescription( const Units& units ) const override;
- bool isSimilarTo( Frame* other ) const override;
+ QString sizeDescription( Units units ) const override;
+ bool isSimilarTo( const Frame& other ) const override;
const QPainterPath& path() const override;
const QPainterPath& clipPath() const override;
- QPainterPath marginPath( const Distance& xSize,
- const Distance& ySize ) const override;
+ QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
@@ -71,8 +73,4 @@ namespace glabels
}
-// Debugging support
-QDebug operator<<( QDebug dbg, const glabels::model::FrameRound& frame );
-
-
#endif // model_FrameRound_h
diff --git a/model/Handle.cpp b/model/Handle.cpp
new file mode 100644
index 0000000..97492e0
--- /dev/null
+++ b/model/Handle.cpp
@@ -0,0 +1,225 @@
+/* Handles.cpp
+ *
+ * Copyright (C) 2013 Jaye 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 "Handle.h"
+
+#include "ModelObject.h"
+
+#include
+#include
+
+
+namespace glabels
+{
+
+ namespace model
+ {
+
+ //
+ // Private
+ //
+ namespace
+ {
+ const double handlePixels = 7;
+ const double handleOutlineWidthPixels = 1;
+
+ const QColor handleFillColor( 0, 192, 0, 96 );
+ const QColor originHandleFillColor( 192, 0, 0, 96 );
+ const QColor handleOutlineColor( 0, 0, 0, 192 );
+ }
+
+
+ ///
+ /// Handle Constructor
+ ///
+ Handle::Handle( ModelObject* owner, Location location )
+ : mOwner(owner), mLocation(location)
+ {
+ // empty
+ }
+
+
+ ///
+ /// Is Handle null?
+ ///
+ bool Handle::isNull() const
+ {
+ return mLocation == NULL_HANDLE;
+ }
+
+
+ ///
+ /// Handle owner
+ ///
+ ModelObject* Handle::owner() const
+ {
+ return mOwner;
+ }
+
+
+ ///
+ /// Handle location
+ ///
+ Handle::Location Handle::location() const
+ {
+ return mLocation;
+ }
+
+
+ ///
+ /// Draw Handle
+ ///
+ void Handle::draw( QPainter* painter, double scale ) const
+ {
+ switch ( mLocation )
+ {
+ case NW:
+ drawAt( painter, scale, 0, 0, originHandleFillColor );
+ break;
+ case N:
+ drawAt( painter, scale, mOwner->w()/2, 0, handleFillColor );
+ break;
+ case NE:
+ drawAt( painter, scale, mOwner->w(), 0, handleFillColor );
+ break;
+ case E:
+ drawAt( painter, scale, mOwner->w(), mOwner->h()/2, handleFillColor );
+ break;
+ case SE:
+ drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
+ break;
+ case S:
+ drawAt( painter, scale, mOwner->w()/2, mOwner->h(), handleFillColor );
+ break;
+ case SW:
+ drawAt( painter, scale, 0, mOwner->h(), handleFillColor );
+ break;
+ case W:
+ drawAt( painter, scale, 0, mOwner->h()/2, handleFillColor );
+ break;
+ case P1:
+ drawAt( painter, scale, 0, 0, originHandleFillColor );
+ break;
+ case P2:
+ drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
+ break;
+ default:
+ qWarning() << "Unknown Handle location";
+ break;
+ }
+ }
+
+
+ ///
+ /// Handle Path
+ ///
+ QPainterPath Handle::path( double scale ) const
+ {
+ switch ( mLocation )
+ {
+ case NW:
+ return pathAt( scale, 0, 0 );
+ break;
+ case N:
+ return pathAt( scale, mOwner->w()/2, 0 );
+ break;
+ case NE:
+ return pathAt( scale, mOwner->w(), 0 );
+ break;
+ case E:
+ return pathAt( scale, mOwner->w(), mOwner->h()/2 );
+ break;
+ case SE:
+ return pathAt( scale, mOwner->w(), mOwner->h() );
+ break;
+ case S:
+ return pathAt( scale, mOwner->w()/2, mOwner->h() );
+ break;
+ case SW:
+ return pathAt( scale, 0, mOwner->h() );
+ break;
+ case W:
+ return pathAt( scale, 0, mOwner->h()/2 );
+ break;
+ case P1:
+ return pathAt( scale, 0, 0 );
+ break;
+ case P2:
+ return pathAt( scale, mOwner->w(), mOwner->h() );
+ break;
+ default:
+ qWarning() << "Unknown Handle location";
+ return QPainterPath(); // Empty
+ break;
+ }
+ }
+
+
+ ///
+ /// Draw Handle at x,y
+ ///
+ void Handle::drawAt( QPainter* painter,
+ double scale,
+ Distance x,
+ Distance y,
+ QColor color ) const
+ {
+ painter->save();
+
+ painter->translate( x.pt(), y.pt() );
+
+ double s = 1.0 / scale;
+
+ QPen pen( handleOutlineColor );
+ pen.setCosmetic( true );
+ pen.setWidth( handleOutlineWidthPixels );
+
+ painter->setPen( pen );
+ painter->setBrush( color );
+
+ painter->drawRect( QRectF( -s*handlePixels/2.0, -s*handlePixels/2.0,
+ s*handlePixels, s*handlePixels ) );
+
+ painter->restore();
+ }
+
+
+ ///
+ /// Create Handle path at x,y
+ ///
+ QPainterPath Handle::pathAt( double scale,
+ Distance x,
+ Distance y ) const
+ {
+ QPainterPath path;
+
+ double s = 1/scale;
+
+ path.addRect( -s*handlePixels/2, -s*handlePixels/2, s*handlePixels, s*handlePixels );
+ path.translate( x.pt(), y.pt() );
+
+ return path;
+ }
+
+
+ }
+
+}
diff --git a/model/Handle.h b/model/Handle.h
new file mode 100644
index 0000000..0ac5f8c
--- /dev/null
+++ b/model/Handle.h
@@ -0,0 +1,101 @@
+/* Handles.h
+ *
+ * Copyright (C) 2013 Jaye 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_Handles_h
+#define model_Handles_h
+
+
+#include "Distance.h"
+
+#include
+#include
+
+
+namespace glabels
+{
+ namespace model
+ {
+
+ // Forward References
+ class ModelObject;
+
+
+ ///
+ /// Handle Base Class
+ ///
+ class Handle
+ {
+ ////////////////////////////
+ // Location enumeration
+ ////////////////////////////
+ public:
+ enum Location { NULL_HANDLE, NW, N, NE, E, SE, S, SW, W, P1, P2 };
+
+
+ ////////////////////////////
+ // Lifecycle Methods
+ ////////////////////////////
+ public:
+ Handle() = default;
+ Handle( ModelObject* owner, Location location );
+ ~Handle() = default;
+
+
+ ////////////////////////////
+ // Attribute Methods
+ ////////////////////////////
+ bool isNull() const;
+ ModelObject* owner() const;
+ Location location() const;
+
+
+ ////////////////////////////
+ // Drawing Methods
+ ////////////////////////////
+ public:
+ void draw( QPainter* painter, double scale ) const;
+ QPainterPath path( double scale ) const;
+
+ private:
+ void drawAt( QPainter* painter,
+ double scale,
+ Distance x,
+ Distance y,
+ QColor color ) const;
+
+ QPainterPath pathAt( double scale,
+ Distance x,
+ Distance y ) const;
+
+
+ ////////////////////////////
+ // Private Data
+ ////////////////////////////
+ protected:
+ ModelObject* mOwner{ nullptr };
+ Location mLocation{ NULL_HANDLE };
+
+ };
+
+ }
+}
+
+
+#endif // model_Handles_h
diff --git a/model/Handles.cpp b/model/Handles.cpp
deleted file mode 100644
index 78277ef..0000000
--- a/model/Handles.cpp
+++ /dev/null
@@ -1,591 +0,0 @@
-/* Handles.cpp
- *
- * Copyright (C) 2013 Jaye 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 "Handles.h"
-
-#include "ModelObject.h"
-
-#include
-#include
-
-
-namespace glabels
-{
- namespace model
- {
-
- //
- // Private
- //
- namespace
- {
- const double handlePixels = 7;
- const double handleOutlineWidthPixels = 1;
-
- const QColor handleFillColor( 0, 192, 0, 96 );
- const QColor originHandleFillColor( 192, 0, 0, 96 );
- const QColor handleOutlineColor( 0, 0, 0, 192 );
- }
-
-
- ///
- /// Handle Constructor
- ///
- Handle::Handle( ModelObject* owner, Location location )
- : mOwner(owner), mLocation(location)
- {
- // empty
- }
-
-
- ///
- /// Handle Destructor
- ///
- Handle::~Handle()
- {
- // empty
- }
-
-
- ///
- /// Handle owner
- ///
- ModelObject* Handle::owner() const
- {
- return mOwner;
- }
-
-
- ///
- /// Handle location
- ///
- Handle::Location Handle::location() const
- {
- return mLocation;
- }
-
-
- ///
- /// Draw Handle at x,y
- ///
- void Handle::drawAt( QPainter* painter,
- double scale,
- const Distance& x,
- const Distance& y,
- QColor color ) const
- {
- painter->save();
-
- painter->translate( x.pt(), y.pt() );
-
- double s = 1.0 / scale;
-
- QPen pen( handleOutlineColor );
- pen.setCosmetic( true );
- pen.setWidth( handleOutlineWidthPixels );
-
- painter->setPen( pen );
- painter->setBrush( color );
-
- painter->drawRect( QRectF( -s*handlePixels/2.0, -s*handlePixels/2.0,
- s*handlePixels, s*handlePixels ) );
-
- painter->restore();
- }
-
-
- ///
- /// Create Handle path at x,y
- ///
- QPainterPath Handle::pathAt( double scale,
- const Distance& x,
- const Distance& y ) const
- {
- QPainterPath path;
-
- double s = 1/scale;
-
- path.addRect( -s*handlePixels/2, -s*handlePixels/2, s*handlePixels, s*handlePixels );
- path.translate( x.pt(), y.pt() );
-
- return path;
- }
-
-
- ///
- /// HandleNorth Constructor
- ///
- HandleNorth::HandleNorth( ModelObject* owner )
- : Handle( owner, N )
- {
- // empty
- }
-
-
- ///
- /// HandleNorth Destructor
- ///
- HandleNorth::~HandleNorth()
- {
- // empty
- }
-
-
- ///
- /// HandleNorth Clone
- ///
- HandleNorth* HandleNorth::clone( ModelObject* newOwner ) const
- {
- return new HandleNorth( newOwner );
- }
-
-
- ///
- /// Draw HandleNorth
- ///
- void HandleNorth::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, mOwner->w()/2, 0, handleFillColor );
- }
-
-
- ///
- /// HandleNorth Path
- ///
- QPainterPath HandleNorth::path( double scale ) const
- {
- return pathAt( scale, mOwner->w()/2, 0 );
- }
-
-
- ///
- /// HandleNorthEast Constructor
- ///
- HandleNorthEast::HandleNorthEast( ModelObject* owner )
- : Handle( owner, NE )
- {
- // empty
- }
-
-
- ///
- /// HandleNorthEast Destructor
- ///
- HandleNorthEast::~HandleNorthEast()
- {
- // empty
- }
-
-
- ///
- /// HandleNorthEast Clone
- ///
- HandleNorthEast* HandleNorthEast::clone( ModelObject* newOwner ) const
- {
- return new HandleNorthEast( newOwner );
- }
-
-
- ///
- /// Draw HandleNorthEast
- ///
- void HandleNorthEast::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, mOwner->w(), 0, handleFillColor );
- }
-
-
- ///
- /// HandleNorthEast Path
- ///
- QPainterPath HandleNorthEast::path( double scale ) const
- {
- return pathAt( scale, mOwner->w(), 0 );
- }
-
-
- ///
- /// HandleEast Constructor
- ///
- HandleEast::HandleEast( ModelObject* owner )
- : Handle( owner, E )
- {
- // empty
- }
-
-
- ///
- /// HandleEast Destructor
- ///
- HandleEast::~HandleEast()
- {
- // empty
- }
-
-
- ///
- /// HandleEast Clone
- ///
- HandleEast* HandleEast::clone( ModelObject* newOwner ) const
- {
- return new HandleEast( newOwner );
- }
-
-
- ///
- /// Draw HandleEast
- ///
- void HandleEast::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, mOwner->w(), mOwner->h()/2, handleFillColor );
- }
-
-
- ///
- /// HandleEast Path
- ///
- QPainterPath HandleEast::path( double scale ) const
- {
- return pathAt( scale, mOwner->w(), mOwner->h()/2 );
- }
-
-
- ///
- /// HandleSouthEast Constructor
- ///
- HandleSouthEast::HandleSouthEast( ModelObject* owner )
- : Handle( owner, SE )
- {
- // empty
- }
-
-
- ///
- /// HandleSouthEast Destructor
- ///
- HandleSouthEast::~HandleSouthEast()
- {
- // empty
- }
-
-
- ///
- /// HandleSouthEast Clone
- ///
- HandleSouthEast* HandleSouthEast::clone( ModelObject* newOwner ) const
- {
- return new HandleSouthEast( newOwner );
- }
-
-
- ///
- /// Draw HandleSouthEast
- ///
- void HandleSouthEast::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
- }
-
-
- ///
- /// HandleSouthEast Path
- ///
- QPainterPath HandleSouthEast::path( double scale ) const
- {
- return pathAt( scale, mOwner->w(), mOwner->h() );
- }
-
-
- ///
- /// HandleSouth Constructor
- ///
- HandleSouth::HandleSouth( ModelObject* owner )
- : Handle( owner, S )
- {
- // empty
- }
-
-
- ///
- /// HandleSouth Destructor
- ///
- HandleSouth::~HandleSouth()
- {
- // empty
- }
-
-
- ///
- /// HandleSouth Clone
- ///
- HandleSouth* HandleSouth::clone( ModelObject* newOwner ) const
- {
- return new HandleSouth( newOwner );
- }
-
-
- ///
- /// Draw HandleSouth
- ///
- void HandleSouth::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, mOwner->w()/2, mOwner->h(), handleFillColor );
- }
-
-
- ///
- /// HandleSouth Path
- ///
- QPainterPath HandleSouth::path( double scale ) const
- {
- return pathAt( scale, mOwner->w()/2, mOwner->h() );
- }
-
-
- ///
- /// HandleSouthWest Constructor
- ///
- HandleSouthWest::HandleSouthWest( ModelObject* owner )
- : Handle( owner, SW )
- {
- // empty
- }
-
-
- ///
- /// HandleSouthWest Destructor
- ///
- HandleSouthWest::~HandleSouthWest()
- {
- // empty
- }
-
-
- ///
- /// HandleSouthWest Clone
- ///
- HandleSouthWest* HandleSouthWest::clone( ModelObject* newOwner ) const
- {
- return new HandleSouthWest( newOwner );
- }
-
-
- ///
- /// Draw HandleSouthWest
- ///
- void HandleSouthWest::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, 0, mOwner->h(), handleFillColor );
- }
-
-
- ///
- /// HandleSouthWest Path
- ///
- QPainterPath HandleSouthWest::path( double scale ) const
- {
- return pathAt( scale, 0, mOwner->h() );
- }
-
-
- ///
- /// HandleWest Constructor
- ///
- HandleWest::HandleWest( ModelObject* owner )
- : Handle( owner, W )
- {
- // empty
- }
-
-
- ///
- /// HandleWest Destructor
- ///
- HandleWest::~HandleWest()
- {
- // empty
- }
-
-
- ///
- /// HandleWest Clone
- ///
- HandleWest* HandleWest::clone( ModelObject* newOwner ) const
- {
- return new HandleWest( newOwner );
- }
-
-
- ///
- /// Draw HandleWest
- ///
- void HandleWest::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, 0, mOwner->h()/2, handleFillColor );
- }
-
-
- ///
- /// HandleWest Path
- ///
- QPainterPath HandleWest::path( double scale ) const
- {
- return pathAt( scale, 0, mOwner->h()/2 );
- }
-
-
- ///
- /// HandleNorthWest Constructor
- ///
- HandleNorthWest::HandleNorthWest( ModelObject* owner )
- : Handle( owner, NW )
- {
- // empty
- }
-
-
- ///
- /// HandleNorthWest Destructor
- ///
- HandleNorthWest::~HandleNorthWest()
- {
- // empty
- }
-
- ///
- /// HandleNorthWest Clone
- ///
- HandleNorthWest* HandleNorthWest::clone( ModelObject* newOwner ) const
- {
- return new HandleNorthWest( newOwner );
- }
-
-
- ///
- /// Draw HandleNorthWest
- ///
- void HandleNorthWest::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, 0, 0, originHandleFillColor );
- }
-
-
- ///
- /// HandleNorthWest Path
- ///
- QPainterPath HandleNorthWest::path( double scale ) const
- {
- return pathAt( scale, 0, 0 );
- }
-
-
- ///
- /// HandleP1 Constructor
- ///
- HandleP1::HandleP1( ModelObject* owner )
- : Handle( owner, P1 )
- {
- // empty
- }
-
-
- ///
- /// HandleP1 Destructor
- ///
- HandleP1::~HandleP1()
- {
- // empty
- }
-
-
- ///
- /// HandleP1 Clone
- ///
- HandleP1* HandleP1::clone( ModelObject* newOwner ) const
- {
- return new HandleP1( newOwner );
- }
-
-
- ///
- /// Draw HandleP1
- ///
- void HandleP1::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, 0, 0, originHandleFillColor );
- }
-
-
- ///
- /// HandleP1 Path
- ///
- QPainterPath HandleP1::path( double scale ) const
- {
- return pathAt( scale, 0, 0 );
- }
-
-
- ///
- /// HandleP2 Constructor
- ///
- HandleP2::HandleP2( ModelObject* owner )
- : Handle( owner, P2 )
- {
- // empty
- }
-
-
- ///
- /// HandleP2 Destructor
- ///
- HandleP2::~HandleP2()
- {
- // empty
- }
-
-
- ///
- /// HandleP2 Clone
- ///
- HandleP2* HandleP2::clone( ModelObject* newOwner ) const
- {
- return new HandleP2( newOwner );
- }
-
-
- ///
- /// Draw HandleP2
- ///
- void HandleP2::draw( QPainter* painter, double scale ) const
- {
- drawAt( painter, scale, mOwner->w(), mOwner->h(), handleFillColor );
- }
-
-
- ///
- /// HandleP2 Path
- ///
- QPainterPath HandleP2::path( double scale ) const
- {
- return pathAt( scale, mOwner->w(), mOwner->h() );
- }
-
- }
-}
diff --git a/model/Handles.h b/model/Handles.h
deleted file mode 100644
index 9d3e0e3..0000000
--- a/model/Handles.h
+++ /dev/null
@@ -1,339 +0,0 @@
-/* Handles.h
- *
- * Copyright (C) 2013 Jaye 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_Handles_h
-#define model_Handles_h
-
-
-#include "Distance.h"
-
-#include
-#include
-
-
-namespace glabels
-{
- namespace model
- {
-
- // Forward References
- class ModelObject;
-
-
- ///
- /// Handle Base Class
- ///
- class Handle
- {
- ////////////////////////////
- // Location enumeration
- ////////////////////////////
- public:
- enum Location { NW, N, NE, E, SE, S, SW, W, P1, P2 };
-
-
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- protected:
- Handle( ModelObject* owner, Location location );
- public:
- virtual ~Handle();
-
-
- ////////////////////////////
- // Duplication
- ////////////////////////////
- virtual Handle* clone( ModelObject* newOwner ) const = 0;
-
-
- ////////////////////////////
- // Attribute Methods
- ////////////////////////////
- ModelObject* owner() const;
- Location location() const;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- virtual void draw( QPainter* painter, double scale ) const = 0;
- virtual QPainterPath path( double scale ) const = 0;
- protected:
- void drawAt( QPainter* painter,
- double scale,
- const Distance& x,
- const Distance& y,
- QColor color ) const;
-
- QPainterPath pathAt( double scale,
- const Distance& x,
- const Distance& y ) const;
-
-
- ////////////////////////////
- // Protected Data
- ////////////////////////////
- protected:
- ModelObject* mOwner;
- Location mLocation;
-
- };
-
-
- ///
- /// HandleNorth Class
- ///
- class HandleNorth : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleNorth( ModelObject* owner );
- ~HandleNorth() override;
- HandleNorth* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
-
- ///
- /// HandleNorthEast Class
- ///
- class HandleNorthEast : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleNorthEast( ModelObject* owner );
- ~HandleNorthEast() override;
- HandleNorthEast* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
-
- ///
- /// HandleEast Class
- ///
- class HandleEast : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleEast( ModelObject* owner );
- ~HandleEast() override;
- HandleEast* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
-
- ///
- /// HandleSouthEast Class
- ///
- class HandleSouthEast : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleSouthEast( ModelObject* owner );
- ~HandleSouthEast() override;
- HandleSouthEast* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
-
- ///
- /// HandleSouth Class
- ///
- class HandleSouth : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleSouth( ModelObject* owner );
- ~HandleSouth() override;
- HandleSouth* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
-
- ///
- /// HandleSouthWest Class
- ///
- class HandleSouthWest : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleSouthWest( ModelObject* owner );
- ~HandleSouthWest() override;
- HandleSouthWest* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
-
- ///
- /// HandleWest Class
- ///
- class HandleWest : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleWest( ModelObject* owner );
- ~HandleWest() override;
- HandleWest* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
-
- ///
- /// HandleNorthWest Class
- ///
- class HandleNorthWest : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleNorthWest( ModelObject* owner );
- ~HandleNorthWest() override;
- HandleNorthWest* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
-
- ///
- /// HandleP1 Class
- ///
- class HandleP1 : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleP1( ModelObject* owner );
- ~HandleP1() override;
- HandleP1* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
-
- ///
- /// HandleP2 Class
- ///
- class HandleP2 : public Handle
- {
- ////////////////////////////
- // Lifecycle Methods
- ////////////////////////////
- public:
- HandleP2( ModelObject* owner );
- ~HandleP2() override;
-
- ////////////////////////////
- // Duplication
- ////////////////////////////
- HandleP2* clone( ModelObject* newOwner ) const override;
-
-
- ////////////////////////////
- // Drawing Methods
- ////////////////////////////
- public:
- void draw( QPainter* painter, double scale ) const override;
- QPainterPath path( double scale ) const override;
- };
-
- }
-}
-
-
-#endif // model_Handles_h
diff --git a/model/Layout.cpp b/model/Layout.cpp
index 2e2f88b..2e97f8c 100644
--- a/model/Layout.cpp
+++ b/model/Layout.cpp
@@ -30,26 +30,23 @@ namespace glabels
namespace model
{
- Layout::Layout( int nx,
- int ny,
- const Distance& x0,
- const Distance& y0,
- const Distance& dx,
- const Distance& dy )
- : mNx(nx), mNy(ny), mX0(x0), mY0(y0), mDx(dx), mDy(dy)
+ Layout::Layout( int nx,
+ int ny,
+ Distance x0,
+ Distance y0,
+ Distance dx,
+ Distance dy )
+ : mNx(nx),
+ mNy(ny),
+ mX0(x0),
+ mY0(y0),
+ mDx(dx),
+ mDy(dy)
{
// empty
}
- Layout::Layout( const Layout& other )
- : mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0),
- mDx(other.mDx), mDy(other.mDy)
- {
- // empty
- }
-
-
int Layout::nx() const
{
return mNx;
diff --git a/model/Layout.h b/model/Layout.h
index 45b6139..a89941b 100644
--- a/model/Layout.h
+++ b/model/Layout.h
@@ -36,14 +36,14 @@ namespace glabels
{
public:
- Layout( int nx,
- int ny,
- const Distance& x0,
- const Distance& y0,
- const Distance& dx,
- const Distance& dy );
+ Layout( int nx,
+ int ny,
+ Distance x0,
+ Distance y0,
+ Distance dx,
+ Distance dy );
- Layout( const Layout &other );
+ Layout( const Layout& other ) = default;
int nx() const;
int ny() const;
diff --git a/model/Markup.cpp b/model/Markup.cpp
index ee12c9a..6386bea 100644
--- a/model/Markup.cpp
+++ b/model/Markup.cpp
@@ -18,44 +18,49 @@
* along with gLabels-qt. If not, see .
*/
+
#include "Markup.h"
+#include "Frame.h"
+
namespace glabels
{
namespace model
{
- QPainterPath Markup::path( const Frame* frame ) const
+ QPainterPath Markup::path( const Frame& frame ) const
{
// Use cached path -- default does not depend on frame size
return mPath;
}
- MarkupMargin::MarkupMargin( const Distance& size )
- : mXSize(size), mYSize(size)
+ MarkupMargin::MarkupMargin( Distance size )
+ : mXSize(size),
+ mYSize(size)
{
}
- MarkupMargin::MarkupMargin( const Distance& xSize,
- const Distance& ySize )
- : mXSize(xSize), mYSize(ySize)
+ MarkupMargin::MarkupMargin( Distance xSize,
+ Distance ySize )
+ : mXSize(xSize),
+ mYSize(ySize)
{
}
- QPainterPath MarkupMargin::path( const Frame* frame ) const
+ QPainterPath MarkupMargin::path( const Frame& frame ) const
{
// Re-calculate path -- frame size may have changed
- return frame->marginPath( mXSize, mYSize );
+ return frame.marginPath( mXSize, mYSize );
}
- Markup* MarkupMargin::dup() const
+ std::unique_ptr MarkupMargin::clone() const
{
- return new MarkupMargin( mXSize, mYSize );
+ return std::make_unique( mXSize, mYSize );
}
@@ -71,20 +76,31 @@ namespace glabels
}
- MarkupLine::MarkupLine( const Distance& x1,
- const Distance& y1,
- const Distance& x2,
- const Distance& y2 )
- : mX1(x1), mY1(y1), mX2(x2), mY2(y2)
+ void MarkupMargin::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "MarkupMargin{ "
+ << mXSize << "," << mYSize
+ << " }";
+ }
+
+
+ MarkupLine::MarkupLine( Distance x1,
+ Distance y1,
+ Distance x2,
+ Distance y2 )
+ : mX1(x1),
+ mY1(y1),
+ mX2(x2),
+ mY2(y2)
{
mPath.moveTo( x1.pt(), y1.pt() );
mPath.lineTo( x2.pt(), y2.pt() );
}
- Markup* MarkupLine::dup() const
+ std::unique_ptr MarkupLine::clone() const
{
- return new MarkupLine( mX1, mY1, mX2, mY2 );
+ return std::make_unique( mX1, mY1, mX2, mY2 );
}
@@ -112,20 +128,33 @@ namespace glabels
}
- MarkupRect::MarkupRect( const Distance& x1,
- const Distance& y1,
- const Distance& w,
- const Distance& h,
- const Distance& r )
- : mX1(x1), mY1(y1), mW(w), mH(h), mR(r)
+ void MarkupLine::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "MarkupLine{ "
+ << mX1 << "," << mY1 << ","
+ << mX2 << "," << mY2
+ << " }";
+ }
+
+
+ MarkupRect::MarkupRect( Distance x1,
+ Distance y1,
+ Distance w,
+ Distance h,
+ Distance r )
+ : mX1(x1),
+ mY1(y1),
+ mW(w),
+ mH(h),
+ mR(r)
{
mPath.addRoundedRect( x1.pt(), y1.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
}
- Markup* MarkupRect::dup() const
+ std::unique_ptr MarkupRect::clone() const
{
- return new MarkupRect( mX1, mY1, mW, mH, mR );
+ return std::make_unique( mX1, mY1, mW, mH, mR );
}
@@ -159,19 +188,32 @@ namespace glabels
}
- MarkupEllipse::MarkupEllipse( const Distance& x1,
- const Distance& y1,
- const Distance& w,
- const Distance& h )
- : mX1(x1), mY1(y1), mW(w), mH(h)
+ void MarkupRect::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "MarkupRect{ "
+ << mX1 << "," << mY1 << ","
+ << mW << "," << mH << ","
+ << mR
+ << " }";
+ }
+
+
+ MarkupEllipse::MarkupEllipse( Distance x1,
+ Distance y1,
+ Distance w,
+ Distance h )
+ : mX1(x1),
+ mY1(y1),
+ mW(w),
+ mH(h)
{
mPath.addEllipse( x1.pt(), y1.pt(), w.pt(), h.pt() );
}
- Markup* MarkupEllipse::dup() const
+ std::unique_ptr MarkupEllipse::clone() const
{
- return new MarkupEllipse( mX1, mY1, mW, mH );
+ return std::make_unique( mX1, mY1, mW, mH );
}
@@ -199,17 +241,28 @@ namespace glabels
}
- MarkupCircle::MarkupCircle( const Distance& x0,
- const Distance& y0,
- const Distance& r )
- : mX0(x0), mY0(y0), mR(r)
+ void MarkupEllipse::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "MarkupEllipse{ "
+ << mX1 << "," << mY1 << ","
+ << mW << "," << mH
+ << " }";
+ }
+
+
+ MarkupCircle::MarkupCircle( Distance x0,
+ Distance y0,
+ Distance r )
+ : mX0(x0),
+ mY0(y0),
+ mR(r)
{
mPath.addEllipse( (x0-r).pt(), (y0-r).pt(), 2*r.pt(), 2*r.pt() );
}
- Markup* MarkupCircle::dup() const
+ std::unique_ptr MarkupCircle::clone() const
{
- return new MarkupCircle( mX0, mY0, mR );
+ return std::make_unique( mX0, mY0, mR );
}
@@ -230,5 +283,25 @@ namespace glabels
return mR;
}
+
+ void MarkupCircle::print( QDebug& dbg ) const
+ {
+ dbg.nospace() << "MarkupCircle{ "
+ << mX0 << "," << mY0 << ","
+ << mR
+ << " }";
+ }
+
}
}
+
+
+QDebug operator<<( QDebug dbg, const glabels::model::Markup& markup )
+{
+ QDebugStateSaver saver(dbg);
+
+ markup.print( dbg );
+
+ return dbg;
+}
+
diff --git a/model/Markup.h b/model/Markup.h
index 87deb16..d588d89 100644
--- a/model/Markup.h
+++ b/model/Markup.h
@@ -22,24 +22,31 @@
#define model_Markup_h
-#include "Frame.h"
+#include "Distance.h"
#include
+#include
+
namespace glabels
{
namespace model
{
+ class Frame; // Forward reference
+
class Markup
{
public:
virtual ~Markup() = default;
- virtual Markup* dup() const = 0;
+ virtual std::unique_ptr clone() const = 0;
- virtual QPainterPath path( const Frame* frame ) const;
+ virtual QPainterPath path( const Frame& frame ) const;
+
+ // Debugging support
+ virtual void print( QDebug& dbg ) const = 0;
protected:
QPainterPath mPath;
@@ -49,17 +56,20 @@ namespace glabels
class MarkupMargin : public Markup
{
public:
- MarkupMargin( const Distance& size );
+ MarkupMargin( Distance size );
- MarkupMargin( const Distance& xSize,
- const Distance& ySize );
+ MarkupMargin( Distance xSize,
+ Distance ySize );
- QPainterPath path( const Frame* frame ) const override;
+ QPainterPath path( const Frame& frame ) const override;
Distance xSize() const;
Distance ySize() const;
- Markup* dup() const override;
+ std::unique_ptr clone() const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
Distance mXSize;
@@ -70,17 +80,20 @@ namespace glabels
class MarkupLine : public Markup
{
public:
- MarkupLine( const Distance& x1,
- const Distance& y1,
- const Distance& x2,
- const Distance& y2 );
+ MarkupLine( Distance x1,
+ Distance y1,
+ Distance x2,
+ Distance y2 );
Distance x1() const;
Distance y1() const;
Distance x2() const;
Distance y2() const;
- Markup* dup() const override;
+ std::unique_ptr clone() const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
Distance mX1;
@@ -93,11 +106,11 @@ namespace glabels
class MarkupRect : public Markup
{
public:
- MarkupRect( const Distance& x1,
- const Distance& y1,
- const Distance& w,
- const Distance& h,
- const Distance& r );
+ MarkupRect( Distance x1,
+ Distance y1,
+ Distance w,
+ Distance h,
+ Distance r );
Distance x1() const;
Distance y1() const;
@@ -105,7 +118,10 @@ namespace glabels
Distance h() const;
Distance r() const;
- Markup* dup() const override;
+ std::unique_ptr clone() const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
Distance mX1;
@@ -119,17 +135,20 @@ namespace glabels
class MarkupEllipse : public Markup
{
public:
- MarkupEllipse( const Distance& x1,
- const Distance& y1,
- const Distance& w,
- const Distance& h );
+ MarkupEllipse( Distance x1,
+ Distance y1,
+ Distance w,
+ Distance h );
Distance x1() const;
Distance y1() const;
Distance w() const;
Distance h() const;
- Markup* dup() const override;
+ std::unique_ptr clone() const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
Distance mX1;
@@ -142,15 +161,18 @@ namespace glabels
class MarkupCircle : public Markup
{
public:
- MarkupCircle( const Distance& x0,
- const Distance& y0,
- const Distance& r );
+ MarkupCircle( Distance x0,
+ Distance y0,
+ Distance r );
Distance x0() const;
Distance y0() const;
Distance r() const;
- Markup* dup() const override;
+ std::unique_ptr clone() const override;
+
+ // Debugging support
+ void print( QDebug& dbg ) const override;
private:
Distance mX0;
@@ -163,4 +185,8 @@ namespace glabels
}
+// Debugging support
+QDebug operator<<( QDebug dbg, const glabels::model::Markup& markup );
+
+
#endif // model_Markup_h
diff --git a/model/Model.cpp b/model/Model.cpp
index 325a91f..abd3e5a 100644
--- a/model/Model.cpp
+++ b/model/Model.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "Model.h"
#include "ModelObject.h"
@@ -55,17 +56,9 @@ namespace glabels
///
Model::Model()
{
- mVariables = new Variables();
- mMerge = new merge::None();
+ mMerge.reset( new merge::None() );
- connect( mVariables, SIGNAL(changed()), this, SLOT(onVariablesChanged()) );
- }
-
-
- Model::Model( merge::Merge* merge, Variables* variables )
- {
- mVariables = variables; // Shared
- mMerge = merge; // Shared
+ connect( &mVariables, SIGNAL(changed()), this, SLOT(onVariablesChanged()) );
}
@@ -75,7 +68,6 @@ namespace glabels
Model::~Model()
{
qDeleteAll( mObjectList );
- // Final instance of mMerge and mVariables to be deleted by Model owner
}
@@ -84,7 +76,7 @@ namespace glabels
///
Model* Model::save() const
{
- auto* savedModel = new Model( mMerge, mVariables ); // mMerge and mVariables shared between models
+ auto* savedModel = new Model(); // mMerge shared between models
if ( mFileName.isEmpty() && mUntitledInstance == 0 )
{
@@ -127,6 +119,10 @@ namespace glabels
connect( object, SIGNAL(moved()), this, SLOT(onObjectMoved()) );
}
+ mVariables.copy( savedModel->mVariables );
+
+ mMerge = savedModel->mMerge;
+
// Emit signals based on potential changes
emit changed();
emit selectionChanged();
@@ -170,34 +166,34 @@ namespace glabels
///
/// Get template
///
- const Template* Model::tmplate() const
+ const Template& Model::tmplate() const
{
- return &mTmplate;
+ return mTmplate;
}
///
/// Get frame
///
- const Frame* Model::frame() const
+ const Frame* Model::frame( const QString& id ) const
{
- return mTmplate.frames().constFirst();
+ return mTmplate.frame( id );
}
///
/// Set template
///
- void Model::setTmplate( const Template* tmplate )
+ void Model::setTmplate( const Template& tmplate )
{
- mTmplate = *tmplate;
+ mTmplate = tmplate;
setModified();
emit changed();
emit sizeChanged();
- Settings::addToRecentTemplateList( tmplate->name() );
+ Settings::addToRecentTemplateList( tmplate.name() );
}
@@ -232,10 +228,9 @@ namespace glabels
///
Distance Model::w() const
{
- auto& frames = mTmplate.frames();
- if ( !frames.isEmpty() )
+ auto frame = mTmplate.frame();
+ if ( frame )
{
- auto* frame = mTmplate.frames().constFirst();
return mRotate ? frame->h() : frame->w();
}
else
@@ -250,10 +245,9 @@ namespace glabels
///
Distance Model::h() const
{
- auto& frames = mTmplate.frames();
- if ( !frames.isEmpty() )
+ auto frame = mTmplate.frame();
+ if ( frame )
{
- auto* frame = mTmplate.frames().constFirst();
return mRotate ? frame->w() : frame->h();
}
else
@@ -266,12 +260,10 @@ namespace glabels
///
/// Set height (if variable length)
///
- void Model::setH( const Distance& h )
+ void Model::setH( Distance h )
{
- if ( auto* frame = mTmplate.frames().first() )
+ if ( mTmplate.setH( h ) )
{
- frame->setH( h );
-
setModified();
emit changed();
@@ -350,7 +342,16 @@ namespace glabels
///
/// Get variables object
///
- Variables* Model::variables() const
+ Variables& Model::variables()
+ {
+ return mVariables;
+ }
+
+
+ ///
+ /// Get const reference to variables object
+ ///
+ const Variables& Model::constVariables() const
{
return mVariables;
}
@@ -361,7 +362,7 @@ namespace glabels
///
merge::Merge* Model::merge() const
{
- return mMerge;
+ return mMerge.get();
}
@@ -372,11 +373,10 @@ namespace glabels
{
if ( merge != mMerge )
{
- delete mMerge;
- mMerge = merge;
+ mMerge.reset( merge );
- connect( mMerge, SIGNAL(sourceChanged()), this, SLOT(onMergeSourceChanged()) );
- connect( mMerge, SIGNAL(selectionChanged()), this, SLOT(onMergeSelectionChanged()) );
+ connect( mMerge.get(), SIGNAL(sourceChanged()), this, SLOT(onMergeSourceChanged()) );
+ connect( mMerge.get(), SIGNAL(selectionChanged()), this, SLOT(onMergeSelectionChanged()) );
setModified();
@@ -445,9 +445,9 @@ namespace glabels
///
/// Object at x,y
///
- ModelObject* Model::objectAt( double scale,
- const Distance& x,
- const Distance& y ) const
+ ModelObject* Model::objectAt( double scale,
+ Distance x,
+ Distance y ) const
{
/* Search object list in reverse order. I.e. from top to bottom. */
QList::const_iterator it = mObjectList.end();
@@ -468,20 +468,22 @@ namespace glabels
///
/// Handle at x,y
///
- Handle* Model::handleAt( double scale,
- const Distance& x,
- const Distance& y ) const
+ const Handle& Model::handleAt( double scale,
+ Distance x,
+ Distance y ) const
{
+ static Handle nullHandle;
+
foreach( ModelObject* object, mObjectList )
{
- Handle* handle = object->handleAt( scale, x, y );
- if ( handle )
+ auto& handle = object->handleAt( scale, x, y );
+ if ( !handle.isNull() )
{
return handle;
}
}
- return nullptr;
+ return nullHandle;
}
@@ -1216,7 +1218,7 @@ namespace glabels
///
/// Move Selected Objects By dx,dy
///
- void Model::moveSelection( const Distance& dx, const Distance& dy )
+ void Model::moveSelection( Distance dx, Distance dy )
{
foreach ( ModelObject* object, mObjectList )
{
@@ -1387,7 +1389,7 @@ namespace glabels
///
/// Set Line Width Of Selected Objects
///
- void Model::setSelectionLineWidth( const Distance& lineWidth )
+ void Model::setSelectionLineWidth( Distance lineWidth )
{
foreach ( ModelObject* object, mObjectList )
{
@@ -1450,8 +1452,7 @@ namespace glabels
{
QClipboard *clipboard = QApplication::clipboard();
- QByteArray buffer;
- XmlLabelCreator::serializeObjects( getSelection(), this, buffer );
+ auto buffer = XmlLabelCreator::serializeObjects( getSelection(), this );
auto *mimeData = new QMimeData;
mimeData->setData( MIME_TYPE, buffer );
@@ -1607,11 +1608,14 @@ namespace glabels
///
/// Draw label objects
///
- void Model::draw( QPainter* painter, bool inEditor, merge::Record* record, Variables* variables ) const
+ void Model::draw( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variablesInstance ) const
{
foreach ( ModelObject* object, mObjectList )
{
- object->draw( painter, inEditor, record, variables );
+ object->draw( painter, inEditor, record, variablesInstance );
}
}
diff --git a/model/Model.h b/model/Model.h
index 52cec1f..2eb46de 100644
--- a/model/Model.h
+++ b/model/Model.h
@@ -60,7 +60,7 @@ namespace glabels
/////////////////////////////////
public:
Model();
- Model( merge::Merge* merge, Variables* variables );
+ Model( merge::Merge* merge );
~Model();
@@ -100,9 +100,9 @@ namespace glabels
const QString& fileName() const;
void setFileName( const QString &fileName );
- const Template* tmplate() const;
- const Frame* frame() const;
- void setTmplate( const Template* tmplate );
+ const Template& tmplate() const;
+ const Frame* frame( const QString& id = "0" ) const;
+ void setTmplate( const Template& tmplate );
bool rotate() const;
void setRotate( bool rotate );
@@ -110,11 +110,12 @@ namespace glabels
Distance w() const;
Distance h() const;
- void setH( const Distance& h );
+ void setH( Distance h );
const QList& objectList() const;
- Variables* variables() const;
+ Variables& variables();
+ const Variables& constVariables() const;
merge::Merge* merge() const;
void setMerge( merge::Merge* merge );
@@ -127,13 +128,13 @@ namespace glabels
void addObject( ModelObject* object );
void deleteObject( ModelObject* object );
- ModelObject* objectAt( double scale,
- const Distance& x,
- const Distance& y ) const;
+ ModelObject* objectAt( double scale,
+ Distance x,
+ Distance y ) const;
- Handle* handleAt( double scale,
- const Distance& x,
- const Distance& y ) const;
+ const Handle& handleAt( double scale,
+ Distance x,
+ Distance y ) const;
/////////////////////////////////
@@ -188,7 +189,7 @@ namespace glabels
void centerSelection();
void centerSelectionHoriz();
void centerSelectionVert();
- void moveSelection( const Distance& dx, const Distance& dy );
+ void moveSelection( Distance dx, Distance dy );
void setSelectionFontFamily( const QString& fontFamily );
void setSelectionFontSize( double fontSize );
void setSelectionFontWeight( QFont::Weight fontWeight );
@@ -197,7 +198,7 @@ namespace glabels
void setSelectionTextVAlign( Qt::Alignment textVAlign );
void setSelectionTextLineSpacing( double textLineSpacing );
void setSelectionTextColorNode( ColorNode textColorNode );
- void setSelectionLineWidth( const Distance& lineWidth );
+ void setSelectionLineWidth( Distance lineWidth );
void setSelectionLineColorNode( ColorNode lineColorNode );
void setSelectionFillColorNode( ColorNode fillColorNode );
@@ -218,10 +219,10 @@ namespace glabels
// Drawing operations
/////////////////////////////////
public:
- void draw( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const;
+ void draw( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variablesInstance ) const;
/////////////////////////////////
@@ -247,8 +248,9 @@ namespace glabels
QList mObjectList;
- Variables* mVariables;
- merge::Merge* mMerge;
+ Variables mVariables;
+
+ QSharedPointer mMerge;
};
}
diff --git a/model/ModelBarcodeObject.cpp b/model/ModelBarcodeObject.cpp
index 20b41f8..baeddf6 100644
--- a/model/ModelBarcodeObject.cpp
+++ b/model/ModelBarcodeObject.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "ModelBarcodeObject.h"
#include "Size.h"
@@ -58,16 +59,16 @@ namespace glabels
///
ModelBarcodeObject::ModelBarcodeObject()
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
mBcStyle = barcode::Backends::defaultStyle();
mBcTextFlag = mBcStyle.canText();
@@ -76,9 +77,6 @@ namespace glabels
mBcData = "";
mBcColorNode = ColorNode( Qt::black );
- mEditorBarcode = nullptr;
- mEditorDefaultBarcode = nullptr;
-
update(); // Initialize cached editor layouts
}
@@ -86,10 +84,10 @@ namespace glabels
///
/// Constructor
///
- ModelBarcodeObject::ModelBarcodeObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
+ ModelBarcodeObject::ModelBarcodeObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
bool lockAspectRatio,
const barcode::Style& bcStyle,
bool bcTextFlag,
@@ -99,16 +97,16 @@ namespace glabels
const QTransform& matrix )
: ModelObject( x0, y0, w, h, lockAspectRatio, matrix )
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
mBcStyle = bcStyle;
mBcTextFlag = bcTextFlag;
@@ -117,9 +115,6 @@ namespace glabels
mBcData = bcData;
mBcColorNode = bcColorNode;
- mEditorBarcode = nullptr;
- mEditorDefaultBarcode = nullptr;
-
update(); // Initialize cached editor layouts
}
@@ -137,30 +132,10 @@ namespace glabels
mBcData = object->mBcData;
mBcColorNode = object->mBcColorNode;
- mEditorBarcode = nullptr;
- mEditorDefaultBarcode = nullptr;
-
update(); // Initialize cached editor layouts
}
- ///
- /// Destructor
- ///
- ModelBarcodeObject::~ModelBarcodeObject()
- {
- delete mOutline;
-
- foreach( Handle* handle, mHandles )
- {
- delete handle;
- }
- mHandles.clear();
-
- delete mEditorBarcode;
- }
-
-
///
/// Clone
///
@@ -311,10 +286,10 @@ namespace glabels
///
/// Draw shadow of object
///
- void ModelBarcodeObject::drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelBarcodeObject::drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
// Barcodes don't support shadows.
}
@@ -323,10 +298,10 @@ namespace glabels
///
/// Draw object itself
///
- void ModelBarcodeObject::drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelBarcodeObject::drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QColor bcColor = mBcColorNode.color( record, variables );
@@ -367,16 +342,12 @@ namespace glabels
//
// Build barcode from data
//
- if ( mEditorBarcode )
- {
- delete mEditorBarcode;
- }
- mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
+ mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
if ( !mEditorBarcode )
{
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
mBcStyle = barcode::Backends::defaultStyle();
- mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
+ mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
}
mEditorBarcode->setChecksum(mBcChecksumFlag);
mEditorBarcode->setShowText(mBcTextFlag);
@@ -386,16 +357,12 @@ namespace glabels
//
// Build a place holder barcode to display in editor, if cannot display actual barcode
//
- if ( mEditorDefaultBarcode )
- {
- delete mEditorDefaultBarcode;
- }
- mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
+ mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
if ( !mEditorDefaultBarcode )
{
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
mBcStyle = barcode::Backends::defaultStyle();
- mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() );
+ mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
}
mEditorDefaultBarcode->setChecksum(mBcChecksumFlag);
mEditorDefaultBarcode->setShowText(mBcTextFlag);
@@ -452,10 +419,10 @@ namespace glabels
/// Draw barcode in final printout or preview
///
void
- ModelBarcodeObject::drawBc( QPainter* painter,
- const QColor& color,
- merge::Record* record,
- Variables* variables ) const
+ ModelBarcodeObject::drawBc( QPainter* painter,
+ const QColor& color,
+ const merge::Record& record,
+ const Variables& variables ) const
{
painter->setPen( QPen( color ) );
diff --git a/model/ModelBarcodeObject.h b/model/ModelBarcodeObject.h
index 1e2ef09..e40b047 100644
--- a/model/ModelBarcodeObject.h
+++ b/model/ModelBarcodeObject.h
@@ -28,6 +28,8 @@
#include "glbarcode/Barcode.h"
+#include
+
namespace glabels
{
@@ -47,10 +49,10 @@ namespace glabels
public:
ModelBarcodeObject();
- ModelBarcodeObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
+ ModelBarcodeObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
bool lockAspectRatio,
const barcode::Style& bcStyle,
bool bcTextFlag,
@@ -61,7 +63,7 @@ namespace glabels
ModelBarcodeObject( const ModelBarcodeObject* object );
- ~ModelBarcodeObject() override;
+ virtual ~ModelBarcodeObject() = default;
///////////////////////////////////////////////////////////////
@@ -127,15 +129,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
- void drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
- void drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
@@ -149,10 +151,10 @@ namespace glabels
void drawBcInEditor( QPainter* painter, const QColor& color ) const;
- void drawBc( QPainter* painter,
- const QColor& color,
- merge::Record* record,
- Variables* variables ) const;
+ void drawBc( QPainter* painter,
+ const QColor& color,
+ const merge::Record& record,
+ const Variables& variables ) const;
void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const;
@@ -169,8 +171,8 @@ namespace glabels
RawText mBcData;
ColorNode mBcColorNode;
- glbarcode::Barcode* mEditorBarcode;
- glbarcode::Barcode* mEditorDefaultBarcode;
+ std::unique_ptr mEditorBarcode;
+ std::unique_ptr mEditorDefaultBarcode;
QPainterPath mHoverPath;
diff --git a/model/ModelBoxObject.cpp b/model/ModelBoxObject.cpp
index 6a379a5..59ce4b7 100644
--- a/model/ModelBoxObject.cpp
+++ b/model/ModelBoxObject.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "ModelBoxObject.h"
#include
@@ -50,24 +51,34 @@ namespace glabels
///
/// Constructor
///
- ModelBoxObject::ModelBoxObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const Distance& lineWidth,
- const ColorNode& lineColorNode,
- const ColorNode& fillColorNode,
+ ModelBoxObject::ModelBoxObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ Distance lineWidth,
+ const ColorNode& lineColorNode,
+ const ColorNode& fillColorNode,
const QTransform& matrix,
- bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
- double shadowOpacity,
- const ColorNode& shadowColorNode )
- : ModelShapeObject( x0, y0, w, h, lockAspectRatio,
- lineWidth, lineColorNode, fillColorNode,
+ bool shadowState,
+ Distance shadowX,
+ Distance shadowY,
+ double shadowOpacity,
+ const ColorNode& shadowColorNode )
+ : ModelShapeObject( x0,
+ y0,
+ w,
+ h,
+ lockAspectRatio,
+ lineWidth,
+ lineColorNode,
+ fillColorNode,
matrix,
- shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
+ shadowState,
+ shadowX,
+ shadowY,
+ shadowOpacity,
+ shadowColorNode )
{
// empty
}
@@ -83,15 +94,6 @@ namespace glabels
}
- ///
- /// Destructor
- ///
- ModelBoxObject::~ModelBoxObject()
- {
- // empty
- }
-
-
///
/// Clone
///
@@ -104,10 +106,10 @@ namespace glabels
///
/// Draw shadow of object
///
- void ModelBoxObject::drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelBoxObject::drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables );
@@ -152,10 +154,10 @@ namespace glabels
///
/// Draw object itself
///
- void ModelBoxObject::drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelBoxObject::drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables );
diff --git a/model/ModelBoxObject.h b/model/ModelBoxObject.h
index ddd333f..1848261 100644
--- a/model/ModelBoxObject.h
+++ b/model/ModelBoxObject.h
@@ -43,24 +43,24 @@ namespace glabels
public:
ModelBoxObject();
- ModelBoxObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const Distance& lineWidth,
- const ColorNode& lineColorNode,
- const ColorNode& fillColorNode,
+ ModelBoxObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ Distance lineWidth,
+ const ColorNode& lineColorNode,
+ const ColorNode& fillColorNode,
const QTransform& matrix = QTransform(),
- bool shadowState = false,
- const Distance& shadowX = 0,
- const Distance& shadowY = 0,
- double shadowOpacity = 1.0,
- const ColorNode& shadowColorNode = ColorNode() );
+ bool shadowState = false,
+ Distance shadowX = 0,
+ Distance shadowY = 0,
+ double shadowOpacity = 1.0,
+ const ColorNode& shadowColorNode = ColorNode() );
ModelBoxObject( const ModelBoxObject* object );
- ~ModelBoxObject() override;
+ virtual ~ModelBoxObject() = default;
///////////////////////////////////////////////////////////////
@@ -73,15 +73,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
- void drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
- void drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
diff --git a/model/ModelEllipseObject.cpp b/model/ModelEllipseObject.cpp
index e2b4a40..f64bdda 100644
--- a/model/ModelEllipseObject.cpp
+++ b/model/ModelEllipseObject.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "ModelEllipseObject.h"
#include
@@ -50,24 +51,34 @@ namespace glabels
///
/// Constructor
///
- ModelEllipseObject::ModelEllipseObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const Distance& lineWidth,
- const ColorNode& lineColorNode,
- const ColorNode& fillColorNode,
+ ModelEllipseObject::ModelEllipseObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ Distance lineWidth,
+ const ColorNode& lineColorNode,
+ const ColorNode& fillColorNode,
const QTransform& matrix,
- bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
- double shadowOpacity,
- const ColorNode& shadowColorNode )
- : ModelShapeObject( x0, y0, w, h, lockAspectRatio,
- lineWidth, lineColorNode, fillColorNode,
+ bool shadowState,
+ Distance shadowX,
+ Distance shadowY,
+ double shadowOpacity,
+ const ColorNode& shadowColorNode )
+ : ModelShapeObject( x0,
+ y0,
+ w,
+ h,
+ lockAspectRatio,
+ lineWidth,
+ lineColorNode,
+ fillColorNode,
matrix,
- shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
+ shadowState,
+ shadowX,
+ shadowY,
+ shadowOpacity,
+ shadowColorNode )
{
// empty
}
@@ -83,15 +94,6 @@ namespace glabels
}
- ///
- /// Destructor
- ///
- ModelEllipseObject::~ModelEllipseObject()
- {
- // empty
- }
-
-
///
/// Clone
///
@@ -104,10 +106,10 @@ namespace glabels
///
/// Draw shadow of object
///
- void ModelEllipseObject::drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelEllipseObject::drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables );
@@ -152,10 +154,10 @@ namespace glabels
///
/// Draw object itself
///
- void ModelEllipseObject::drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelEllipseObject::drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables );
diff --git a/model/ModelEllipseObject.h b/model/ModelEllipseObject.h
index b1ee244..7d57a97 100644
--- a/model/ModelEllipseObject.h
+++ b/model/ModelEllipseObject.h
@@ -43,24 +43,24 @@ namespace glabels
public:
ModelEllipseObject();
- ModelEllipseObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const Distance& lineWidth,
- const ColorNode& lineColorNode,
- const ColorNode& fillColorNode,
+ ModelEllipseObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ Distance lineWidth,
+ const ColorNode& lineColorNode,
+ const ColorNode& fillColorNode,
const QTransform& matrix = QTransform(),
- bool shadowState = false,
- const Distance& shadowX = 0,
- const Distance& shadowY = 0,
- double shadowOpacity = 1.0,
- const ColorNode& shadowColorNode = ColorNode() );
+ bool shadowState = false,
+ Distance shadowX = 0,
+ Distance shadowY = 0,
+ double shadowOpacity = 1.0,
+ const ColorNode& shadowColorNode = ColorNode() );
ModelEllipseObject( const ModelEllipseObject* object );
- ~ModelEllipseObject() override;
+ virtual ~ModelEllipseObject() = default;
///////////////////////////////////////////////////////////////
@@ -73,15 +73,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
- void drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
- void drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
diff --git a/model/ModelImageObject.cpp b/model/ModelImageObject.cpp
index e95f7ef..8363966 100644
--- a/model/ModelImageObject.cpp
+++ b/model/ModelImageObject.cpp
@@ -18,17 +18,18 @@
* along with gLabels-qt. If not, see .
*/
+
#include "ModelImageObject.h"
#include "Model.h"
#include "Size.h"
#include
+#include
#include
#include
#include
#include
-#include
namespace glabels
@@ -39,7 +40,7 @@ namespace glabels
///
/// Static data
///
- QImage* ModelImageObject::smDefaultImage = nullptr;
+ QImage ModelImageObject::smDefaultImage( ":images/checkerboard.png" );
//
@@ -56,23 +57,18 @@ namespace glabels
///
/// Constructor
///
- ModelImageObject::ModelImageObject() : mImage(nullptr), mSvgRenderer(nullptr)
+ ModelImageObject::ModelImageObject()
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
-
- if ( smDefaultImage == nullptr )
- {
- smDefaultImage = new QImage( ":images/checkerboard.png" );
- }
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
mLockAspectRatio = true;
}
@@ -81,43 +77,43 @@ namespace glabels
///
/// Constructor
///
- ModelImageObject::ModelImageObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const TextNode& filenameNode,
+ ModelImageObject::ModelImageObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ const TextNode& filenameNode,
const QTransform& matrix,
- bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
- double shadowOpacity,
- const ColorNode& shadowColorNode )
- : ModelObject( x0, y0, w, h, lockAspectRatio,
+ bool shadowState,
+ Distance shadowX,
+ Distance shadowY,
+ double shadowOpacity,
+ const ColorNode& shadowColorNode )
+ : ModelObject( x0,
+ y0,
+ w,
+ h,
+ lockAspectRatio,
matrix,
- shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
+ shadowState,
+ shadowX,
+ shadowY,
+ shadowOpacity,
+ shadowColorNode )
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
-
- if ( smDefaultImage == nullptr )
- {
- smDefaultImage = new QImage( ":images/checkerboard.png" );
- }
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
mFilenameNode = filenameNode;
- mImage = nullptr;
- mSvgRenderer = nullptr;
-
loadImage();
}
@@ -125,85 +121,92 @@ namespace glabels
///
/// Constructor
///
- ModelImageObject::ModelImageObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const QString& filename,
- const QImage& image,
+ ModelImageObject::ModelImageObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ const QString& filename,
+ const QImage& image,
const QTransform& matrix,
- bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
- double shadowOpacity,
- const ColorNode& shadowColorNode )
- : ModelObject( x0, y0, w, h, lockAspectRatio,
+ bool shadowState,
+ Distance shadowX,
+ Distance shadowY,
+ double shadowOpacity,
+ const ColorNode& shadowColorNode )
+ : ModelObject( x0,
+ y0,
+ w,
+ h,
+ lockAspectRatio,
matrix,
- shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
+ shadowState,
+ shadowX,
+ shadowY,
+ shadowOpacity,
+ shadowColorNode )
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
- if ( smDefaultImage == nullptr )
- {
- smDefaultImage = new QImage( ":images/checkerboard.png" );
- }
-
- mImage = new QImage(image);
+ mImage = image;
mFilenameNode = TextNode( false, filename );
- mSvgRenderer = nullptr;
}
///
/// Constructor
///
- ModelImageObject::ModelImageObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
+ ModelImageObject::ModelImageObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
bool lockAspectRatio,
const QString& filename,
const QByteArray& svg,
const QTransform& matrix,
bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
+ Distance shadowX,
+ Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
- : ModelObject( x0, y0, w, h, lockAspectRatio,
+ : ModelObject( x0,
+ y0,
+ w,
+ h,
+ lockAspectRatio,
matrix,
- shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
+ shadowState,
+ shadowX,
+ shadowY,
+ shadowOpacity,
+ shadowColorNode )
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
- if ( smDefaultImage == nullptr )
+ if ( QSvgRenderer( svg ).isValid() )
{
- smDefaultImage = new QImage( ":images/checkerboard.png" );
+ mSvg = svg;
}
- mSvg = svg;
- mSvgRenderer = new QSvgRenderer( mSvg );
mFilenameNode = TextNode( false, filename );
- mImage = nullptr;
}
@@ -213,50 +216,11 @@ namespace glabels
ModelImageObject::ModelImageObject( const ModelImageObject* object ) : ModelObject(object)
{
mFilenameNode = object->mFilenameNode;
- if ( object->mImage )
- {
- mImage = new QImage( *object->mImage );
- }
- else
- {
- mImage = nullptr;
- }
- if ( object->mSvgRenderer )
- {
- mSvgRenderer = new QSvgRenderer( object->mSvg );
- }
- else
- {
- mSvgRenderer = nullptr;
- }
+ mImage = object->mImage;
mSvg = object->mSvg;
}
- ///
- /// Destructor
- ///
- ModelImageObject::~ModelImageObject()
- {
- delete mOutline;
-
- foreach( Handle* handle, mHandles )
- {
- delete handle;
- }
- mHandles.clear();
-
- if ( mImage )
- {
- delete mImage;
- }
- if ( mSvgRenderer )
- {
- delete mSvgRenderer;
- }
- }
-
-
///
/// Clone
///
@@ -293,7 +257,7 @@ namespace glabels
///
/// Image image Property Getter
///
- const QImage* ModelImageObject::image() const
+ const QImage& ModelImageObject::image() const
{
return mImage;
}
@@ -306,19 +270,10 @@ namespace glabels
{
if ( !value.isNull() )
{
- if ( mImage )
- {
- delete mImage;
- mImage = nullptr;
- }
- if ( mSvgRenderer )
- {
- delete mSvgRenderer;
- mSvgRenderer = nullptr;
- }
+ mSvg.clear();
- mImage = new QImage(value);
- quint16 cs = qChecksum( QByteArray( (const char*)mImage->constBits(), mImage->sizeInBytes() ) );
+ mImage = value;
+ quint16 cs = qChecksum( QByteArray( (const char*)mImage.constBits(), mImage.sizeInBytes() ) );
mFilenameNode = TextNode( false, QString("%image_%1%").arg( cs ) );
emit changed();
@@ -333,18 +288,9 @@ namespace glabels
{
if ( !value.isNull() )
{
- if ( mImage )
- {
- delete mImage;
- mImage = nullptr;
- }
- if ( mSvgRenderer )
- {
- delete mSvgRenderer;
- mSvgRenderer = nullptr;
- }
+ mSvg.clear();
- mImage = new QImage(value);
+ mImage = value;
mFilenameNode = TextNode( false, name );
emit changed();
@@ -355,7 +301,7 @@ namespace glabels
///
/// Image svg Property Getter
///
- QByteArray ModelImageObject::svg() const
+ const QByteArray& ModelImageObject::svg() const
{
return mSvg;
}
@@ -368,19 +314,13 @@ namespace glabels
{
if ( !value.isEmpty() )
{
- if ( mImage )
- {
- delete mImage;
- mImage = nullptr;
- }
- if ( mSvgRenderer )
- {
- delete mSvgRenderer;
- mSvgRenderer = nullptr;
- }
+ mImage = QImage(); // clear
+ mSvg.clear();
- mSvg = value;
- mSvgRenderer = new QSvgRenderer( mSvg );
+ if ( QSvgRenderer( value ).isValid() )
+ {
+ mSvg = value;
+ }
mFilenameNode = TextNode( false, name );
emit changed();
@@ -395,15 +335,15 @@ namespace glabels
{
Size size( Distance::pt(72), Distance::pt(72) );
- if ( mImage )
+ if ( !mImage.isNull() )
{
- QSize qsize = mImage->size();
+ QSize qsize = mImage.size();
size.setW( Distance::pt( qsize.width() ) );
size.setH( Distance::pt( qsize.height() ) );
}
- else if ( mSvgRenderer )
+ else if ( !mSvg.isEmpty() )
{
- QSize qsize = mSvgRenderer->defaultSize();
+ QSize qsize = QSvgRenderer( mSvg ).defaultSize();
size.setW( Distance::pt( qsize.width() ) );
size.setH( Distance::pt( qsize.height() ) );
}
@@ -415,23 +355,22 @@ namespace glabels
///
/// Draw shadow of object
///
- void ModelImageObject::drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelImageObject::drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
QColor shadowColor = mShadowColorNode.color( record, variables );
shadowColor.setAlphaF( mShadowOpacity );
- if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) )
+ if ( !mImage.isNull() && mImage.hasAlphaChannel() && (mImage.depth() == 32) )
{
- QImage* shadowImage = createShadowImage( *mImage, shadowColor );
- painter->drawImage( destRect, *shadowImage );
- delete shadowImage;
+ auto shadowImage = createShadowImage( mImage, shadowColor );
+ painter->drawImage( destRect, shadowImage );
}
- else if ( mImage || mSvgRenderer || inEditor )
+ else if ( !mImage.isNull() || !mSvg.isEmpty() || inEditor )
{
painter->setBrush( shadowColor );
painter->setPen( QPen( Qt::NoPen ) );
@@ -441,16 +380,14 @@ namespace glabels
else
{
QString filename = mFilenameNode.text( record, variables ).trimmed();
- QImage* image;
- QSvgRenderer* svgRenderer;
+ QImage image;
QByteArray svg;
- if ( readImageFile( filename, image, svgRenderer, svg ) )
+ if ( readImageFile( filename, image, svg ) )
{
- if ( image && image->hasAlphaChannel() && (image->depth() == 32) )
+ if ( !image.isNull() && image.hasAlphaChannel() && (image.depth() == 32) )
{
- QImage* shadowImage = createShadowImage( *image, shadowColor );
- painter->drawImage( destRect, *shadowImage );
- delete shadowImage;
+ QImage shadowImage = createShadowImage( image, shadowColor );
+ painter->drawImage( destRect, shadowImage );
}
else
{
@@ -459,14 +396,6 @@ namespace glabels
painter->drawRect( destRect );
}
- if ( image )
- {
- delete image;
- }
- else
- {
- delete svgRenderer;
- }
}
}
}
@@ -475,21 +404,21 @@ namespace glabels
///
/// Draw object itself
///
- void ModelImageObject::drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelImageObject::drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QRectF destRect( 0, 0, mW.pt(), mH.pt() );
- if ( inEditor && (mFilenameNode.isField() || (!mImage && !mSvgRenderer) ) )
+ if ( inEditor && (mFilenameNode.isField() || (mImage.isNull() && mSvg.isEmpty()) ) )
{
//
// Render default place holder image
//
painter->save();
painter->setRenderHint( QPainter::SmoothPixmapTransform, false );
- painter->drawImage( destRect, *smDefaultImage );
+ painter->drawImage( destRect, smDefaultImage );
painter->restore();
//
@@ -540,31 +469,28 @@ namespace glabels
labelText );
}
}
- else if ( mImage )
+ else if ( !mImage.isNull() )
{
- painter->drawImage( destRect, *mImage );
+ painter->drawImage( destRect, mImage );
}
- else if ( mSvgRenderer )
+ else if ( !mSvg.isEmpty() )
{
- mSvgRenderer->render( painter, destRect );
+ QSvgRenderer( mSvg ).render( painter, destRect );
}
else if ( mFilenameNode.isField() )
{
QString filename = mFilenameNode.text( record, variables ).trimmed();
- QImage* image;
- QSvgRenderer* svgRenderer;
+ QImage image;
QByteArray svg;
- if ( readImageFile( filename, image, svgRenderer, svg ) )
+ if ( readImageFile( filename, image, svg ) )
{
- if ( image )
+ if ( !image.isNull() )
{
- painter->drawImage( destRect, *image );
- delete image;
+ painter->drawImage( destRect, image );
}
- else
+ else if ( !svg.isEmpty() )
{
- svgRenderer->render( painter, destRect );
- delete svgRenderer;
+ QSvgRenderer( svg ).render( painter, destRect );
}
}
}
@@ -588,34 +514,26 @@ namespace glabels
///
void ModelImageObject::loadImage()
{
- if ( mImage )
- {
- delete mImage;
- mImage = nullptr;
- }
- if ( mSvgRenderer )
- {
- delete mSvgRenderer;
- mSvgRenderer = nullptr;
- }
+ mImage = QImage(); // clear
+ mSvg.clear();
if ( !mFilenameNode.isField() )
{
QString filename = mFilenameNode.data();
- if ( readImageFile( filename, mImage, mSvgRenderer, mSvg ) )
+ if ( readImageFile( filename, mImage, mSvg ) )
{
double aspectRatio = 0;
- if ( mSvgRenderer )
+ if ( !mSvg.isEmpty() )
{
// Adjust size based on aspect ratio of SVG image
- QRectF rect = mSvgRenderer->viewBoxF();
+ QRectF rect = QSvgRenderer( mSvg ).viewBoxF();
aspectRatio = rect.width() ? rect.height() / rect.width() : 0;
}
else
{
// Adjust size based on aspect ratio of image
- double imageW = mImage->width();
- double imageH = mImage->height();
+ double imageW = mImage.width();
+ double imageH = mImage.height();
aspectRatio = imageW ? imageH / imageW : 0;
}
@@ -639,12 +557,10 @@ namespace glabels
/// Read an image or svg file
///
bool ModelImageObject::readImageFile( const QString& fileName,
- QImage*& image,
- QSvgRenderer*& svgRenderer,
+ QImage& image,
QByteArray& svg ) const
{
- image = nullptr;
- svgRenderer = nullptr;
+ image = QImage(); // clear
svg.clear();
if ( !fileName.isEmpty() )
@@ -667,48 +583,41 @@ namespace glabels
{
svg = file.readAll();
file.close();
- svgRenderer = new QSvgRenderer( svg );
- if ( !svgRenderer->isValid() )
+ QSvgRenderer renderer( svg );
+ if ( !renderer.isValid() )
{
- delete svgRenderer;
- svgRenderer = nullptr;
svg.clear();
}
}
}
else
{
- image = new QImage( fileInfo.filePath() );
- if ( image->isNull() )
- {
- delete image;
- image = nullptr;
- }
+ image = QImage( fileInfo.filePath() );
}
}
}
- return image != nullptr || svgRenderer != nullptr;
+ return !image.isNull() || !svg.isEmpty();
}
///
/// Create shadow image
///
- QImage* ModelImageObject::createShadowImage( const QImage& image,
- 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( image );
- for ( int iy = 0; iy < shadow->height(); iy++ )
+ QImage shadow = image;
+ for ( int iy = 0; iy < shadow.height(); iy++ )
{
- auto* scanLine = (QRgb*)shadow->scanLine( iy );
+ auto* scanLine = (QRgb*)shadow.scanLine( iy );
- for ( int ix = 0; ix < shadow->width(); ix++ )
+ for ( int ix = 0; ix < shadow.width(); ix++ )
{
scanLine[ix] = qRgba( r, g, b, (a*qAlpha(scanLine[ix]))/255 );
}
diff --git a/model/ModelImageObject.h b/model/ModelImageObject.h
index 0f27653..a29d7e8 100644
--- a/model/ModelImageObject.h
+++ b/model/ModelImageObject.h
@@ -45,50 +45,50 @@ namespace glabels
public:
ModelImageObject();
- ModelImageObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const TextNode& filenameNode,
+ ModelImageObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ const TextNode& filenameNode,
const QTransform& matrix = QTransform(),
- bool shadowState = false,
- const Distance& shadowX = 0,
- const Distance& shadowY = 0,
- double shadowOpacity = 1.0,
- const ColorNode& shadowColorNode = ColorNode() );
+ bool shadowState = false,
+ Distance shadowX = 0,
+ Distance shadowY = 0,
+ double shadowOpacity = 1.0,
+ const ColorNode& shadowColorNode = ColorNode() );
- ModelImageObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const QString& filename,
- const QImage& image,
+ ModelImageObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ const QString& filename,
+ const QImage& image,
const QTransform& matrix = QTransform(),
- bool shadowState = false,
- const Distance& shadowX = 0,
- const Distance& shadowY = 0,
- double shadowOpacity = 1.0,
- const ColorNode& shadowColorNode = ColorNode() );
+ bool shadowState = false,
+ Distance shadowX = 0,
+ Distance shadowY = 0,
+ double shadowOpacity = 1.0,
+ const ColorNode& shadowColorNode = ColorNode() );
- ModelImageObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
+ ModelImageObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
bool lockAspectRatio,
const QString& filename,
const QByteArray& svg,
const QTransform& matrix = QTransform(),
bool shadowState = false,
- const Distance& shadowX = 0,
- const Distance& shadowY = 0,
+ Distance shadowX = 0,
+ Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelImageObject( const ModelImageObject* object );
- ~ModelImageObject() override;
+ virtual ~ModelImageObject() = default;
///////////////////////////////////////////////////////////////
@@ -110,14 +110,14 @@ namespace glabels
//
// Image Property: image
//
- const QImage* image() const override;
+ const QImage& image() const override;
void setImage( const QImage& value ) override;
void setImage( const QString& name, const QImage& value ) override;
//
// Image Property: svg
//
- QByteArray svg() const override;
+ const QByteArray& svg() const override;
void setSvg( const QString& name, const QByteArray& value ) override;
//
@@ -135,15 +135,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
- void drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
- void drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
@@ -154,24 +154,22 @@ namespace glabels
void loadImage();
bool readImageFile( const QString& fileName,
- QImage*& image,
- QSvgRenderer*& svgRenderer,
+ QImage& image,
QByteArray& svg ) const;
- QImage* createShadowImage( const QImage& image,
- const QColor& color ) const;
+ QImage createShadowImage( const QImage& image,
+ const QColor& color ) const;
///////////////////////////////////////////////////////////////
// Private Members
///////////////////////////////////////////////////////////////
protected:
- TextNode mFilenameNode;
- QImage* mImage;
- QSvgRenderer* mSvgRenderer;
- QByteArray mSvg;
+ TextNode mFilenameNode;
+ QImage mImage;
+ QByteArray mSvg;
- static QImage* smDefaultImage;
+ static QImage smDefaultImage;
};
diff --git a/model/ModelLineObject.cpp b/model/ModelLineObject.cpp
index 13d8cc8..fbfb421 100644
--- a/model/ModelLineObject.cpp
+++ b/model/ModelLineObject.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "ModelLineObject.h"
#include
@@ -43,10 +44,8 @@ namespace glabels
///
ModelLineObject::ModelLineObject()
{
- mOutline = nullptr;
-
- mHandles << new HandleP1( this );
- mHandles << new HandleP2( this );
+ mHandles.push_back( Handle( this, Handle::P1 ) );
+ mHandles.push_back( Handle( this, Handle::P2 ) );
mLineWidth = 1.0;
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
@@ -56,32 +55,32 @@ namespace glabels
///
/// Constructor
///
- ModelLineObject::ModelLineObject( const Distance& x0,
- const Distance& y0,
- const Distance& dx,
- const Distance& dy,
- const Distance& lineWidth,
- const ColorNode& lineColorNode,
+ ModelLineObject::ModelLineObject( Distance x0,
+ Distance y0,
+ Distance dx,
+ Distance dy,
+ Distance lineWidth,
+ const ColorNode& lineColorNode,
const QTransform& matrix,
- bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
- double shadowOpacity,
- const ColorNode& shadowColorNode )
- : ModelObject( x0, y0, dx, dy, false /*lockAspectRatio*/,
+ bool shadowState,
+ Distance shadowX,
+ Distance shadowY,
+ double shadowOpacity,
+ const ColorNode& shadowColorNode )
+ : ModelObject( x0,
+ y0,
+ dx,
+ dy,
+ false /*lockAspectRatio*/,
matrix,
- shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
+ shadowState,
+ shadowX,
+ shadowY,
+ shadowOpacity,
+ shadowColorNode )
{
- mOutline = new Outline( this );
-
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
+ mHandles.push_back( Handle( this, Handle::P1 ) );
+ mHandles.push_back( Handle( this, Handle::P2 ) );
mLineWidth = lineWidth;
mLineColorNode = lineColorNode;
@@ -99,19 +98,6 @@ namespace glabels
}
- ///
- /// Destructor
- ///
- ModelLineObject::~ModelLineObject()
- {
- foreach( Handle* handle, mHandles )
- {
- delete handle;
- }
- mHandles.clear();
- }
-
-
///
/// Clone
///
@@ -133,7 +119,7 @@ namespace glabels
///
/// Line Width Property Setter
///
- void ModelLineObject::setLineWidth( const Distance& value )
+ void ModelLineObject::setLineWidth( Distance value )
{
if ( mLineWidth != value )
{
@@ -186,10 +172,10 @@ namespace glabels
///
/// Draw shadow of object
///
- void ModelLineObject::drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelLineObject::drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
QColor shadowColor = mShadowColorNode.color( record, variables );
@@ -207,10 +193,10 @@ namespace glabels
///
/// Draw object itself
///
- void ModelLineObject::drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelLineObject::drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QColor lineColor = mLineColorNode.color( record, variables );
diff --git a/model/ModelLineObject.h b/model/ModelLineObject.h
index 9fc60b6..4fae277 100644
--- a/model/ModelLineObject.h
+++ b/model/ModelLineObject.h
@@ -43,22 +43,22 @@ namespace glabels
public:
ModelLineObject();
- ModelLineObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- const Distance& lineWidth,
- const ColorNode& lineColorNode,
+ ModelLineObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ Distance lineWidth,
+ const ColorNode& lineColorNode,
const QTransform& matrix = QTransform(),
- bool shadowState = false,
- const Distance& shadowX = 0,
- const Distance& shadowY = 0,
- double shadowOpacity = 1.0,
- const ColorNode& shadowColorNode = ColorNode() );
+ bool shadowState = false,
+ Distance shadowX = 0,
+ Distance shadowY = 0,
+ double shadowOpacity = 1.0,
+ const ColorNode& shadowColorNode = ColorNode() );
ModelLineObject( const ModelLineObject* object );
- ~ModelLineObject() override;
+ virtual ~ModelLineObject() = default;
///////////////////////////////////////////////////////////////
@@ -75,7 +75,7 @@ namespace glabels
// Line Property: lineWidth
//
Distance lineWidth() const override;
- void setLineWidth( const Distance& value ) override;
+ void setLineWidth( Distance value ) override;
//
@@ -97,15 +97,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
- void drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
- void drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
diff --git a/model/ModelObject.cpp b/model/ModelObject.cpp
index c338d5f..3e5a082 100644
--- a/model/ModelObject.cpp
+++ b/model/ModelObject.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "ModelObject.h"
#include "ColorNode.h"
@@ -43,7 +44,8 @@ namespace glabels
///
/// Constructor
///
- ModelObject::ModelObject() : QObject(nullptr)
+ ModelObject::ModelObject()
+ : QObject(nullptr)
{
mId = msNextId++;
@@ -61,25 +63,24 @@ namespace glabels
mShadowOpacity = 0.5;
mSelectedFlag = false;
-
- mOutline = nullptr;
}
///
/// Constructor
///
- ModelObject::ModelObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
+ ModelObject::ModelObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
const QTransform& matrix,
- bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
- double shadowOpacity,
- const ColorNode& shadowColorNode ) : QObject(nullptr)
+ bool shadowState,
+ Distance shadowX,
+ Distance shadowY,
+ double shadowOpacity,
+ const ColorNode& shadowColorNode )
+ : QObject(nullptr)
{
mId = msNextId++;
@@ -97,8 +98,6 @@ namespace glabels
mShadowOpacity = shadowOpacity;
mSelectedFlag = false;
-
- mOutline = nullptr;
}
@@ -123,33 +122,21 @@ namespace glabels
mShadowOpacity = object->mShadowOpacity;
mShadowColorNode = object->mShadowColorNode;
- foreach ( Handle* handle, object->mHandles )
+ if ( object->mOutline.isEnabled() )
{
- mHandles.append( handle->clone( this ) );
+ mOutline = object->mOutline;
+ mOutline.setOwner( this );
+ }
+
+ for ( auto& handle : object->mHandles )
+ {
+ mHandles.push_back( Handle( this, handle.location() ) );
}
- if ( object->mOutline )
- {
- mOutline = object->mOutline->clone( this );
- }
- else
- {
- mOutline = nullptr;
- }
-
mMatrix = object->mMatrix;
}
- ///
- /// Destructor
- ///
- ModelObject::~ModelObject()
- {
- // empty
- }
-
-
///
/// ID Property Getter
///
@@ -198,7 +185,7 @@ namespace glabels
///
/// X0 Property Setter
///
- void ModelObject::setX0( const Distance& value )
+ void ModelObject::setX0( Distance value )
{
if ( mX0 != value )
{
@@ -220,7 +207,7 @@ namespace glabels
///
/// Y0 Property Setter
///
- void ModelObject::setY0( const Distance& value )
+ void ModelObject::setY0( Distance value )
{
if ( mY0 != value )
{
@@ -242,7 +229,7 @@ namespace glabels
///
/// W (Width) Property Setter
///
- void ModelObject::setW( const Distance& value )
+ void ModelObject::setW( Distance value )
{
if ( mW != value )
{
@@ -265,7 +252,7 @@ namespace glabels
///
/// H (Height) Property Setter
///
- void ModelObject::setH( const Distance& value )
+ void ModelObject::setH( Distance value )
{
if ( mH != value )
{
@@ -354,7 +341,7 @@ namespace glabels
///
/// Shadow X Property Setter
///
- void ModelObject::setShadowX( const Distance& value )
+ void ModelObject::setShadowX( Distance value )
{
if ( mShadowX != value )
{
@@ -376,7 +363,7 @@ namespace glabels
///
/// Shadow Y Property Setter
///
- void ModelObject::setShadowY( const Distance& value )
+ void ModelObject::setShadowY( Distance value )
{
if ( mShadowY != value )
{
@@ -704,9 +691,10 @@ namespace glabels
/// Virtual Image Property Default Getter
/// (Overridden by concrete class)
///
- const QImage* ModelObject::image() const
+ const QImage& ModelObject::image() const
{
- return nullptr;
+ static QImage dummyImage;
+ return dummyImage;
}
@@ -734,9 +722,10 @@ namespace glabels
/// Virtual SVG Property Default Getter
/// (Overridden by concrete class)
///
- QByteArray ModelObject::svg() const
+ const QByteArray& ModelObject::svg() const
{
- return QByteArray();
+ static QByteArray dummySvg;
+ return dummySvg;
}
@@ -764,7 +753,7 @@ namespace glabels
/// Virtual Line Width Property Default Setter
/// (Overridden by concrete class)
///
- void ModelObject::setLineWidth( const Distance& value )
+ void ModelObject::setLineWidth( Distance value )
{
// empty
}
@@ -973,8 +962,8 @@ namespace glabels
///
/// Set Absolute Position
///
- void ModelObject::setPosition( const Distance& x0,
- const Distance& y0 )
+ void ModelObject::setPosition( Distance x0,
+ Distance y0 )
{
if ( ( mX0 != x0 ) || ( mY0 != y0 ) )
{
@@ -989,8 +978,8 @@ namespace glabels
///
/// Set Relative Position
///
- void ModelObject::setPositionRelative( const Distance& dx,
- const Distance& dy )
+ void ModelObject::setPositionRelative( Distance dx,
+ Distance dy )
{
if ( ( dx != 0 ) || ( dy != 0 ) )
{
@@ -1014,8 +1003,8 @@ namespace glabels
///
/// Set Size
///
- void ModelObject::setSize( const Distance& w,
- const Distance& h )
+ void ModelObject::setSize( Distance w,
+ Distance h )
{
mW = w;
mH = h;
@@ -1028,7 +1017,7 @@ namespace glabels
///
/// Set Size
///
- void ModelObject::setSize( const Size& size )
+ void ModelObject::setSize( Size size )
{
mW = size.w();
mH = size.h();
@@ -1041,8 +1030,8 @@ namespace glabels
///
/// Set Size (But Maintain Current Aspect Ratio)
///
- void ModelObject::setSizeHonorAspect( const Distance& w,
- const Distance& h )
+ void ModelObject::setSizeHonorAspect( Distance w,
+ Distance h )
{
double aspectRatio = mH / mW;
Distance wNew = w;
@@ -1064,7 +1053,7 @@ namespace glabels
///
/// Set Width (But Maintain Current Aspect Ratio)
///
- void ModelObject::setWHonorAspect( const Distance& w )
+ void ModelObject::setWHonorAspect( Distance w )
{
double aspectRatio = mH / mW;
Distance h = w * aspectRatio;
@@ -1083,7 +1072,7 @@ namespace glabels
///
/// Set Height (But Maintain Current Aspect Ratio)
///
- void ModelObject::setHHonorAspect( const Distance& h )
+ void ModelObject::setHHonorAspect( Distance h )
{
double aspectRatio = mH / mW;
Distance w = h / aspectRatio;
@@ -1169,9 +1158,9 @@ namespace glabels
///
/// Is this object located at x,y?
///
- bool ModelObject::isLocatedAt( double scale,
- const Distance& x,
- const Distance& y ) const
+ bool ModelObject::isLocatedAt( double scale,
+ Distance x,
+ Distance y ) const
{
QPointF p( x.pt(), y.pt() );
@@ -1185,9 +1174,9 @@ namespace glabels
{
return true;
}
- else if ( isSelected() && mOutline )
+ else if ( isSelected() )
{
- if ( mOutline->hoverPath( scale ).contains( p ) )
+ if ( mOutline.hoverPath( scale ).contains( p ) )
{
return true;
}
@@ -1200,18 +1189,20 @@ namespace glabels
///
/// Is one of this object's handles locate at x,y? If so, return it.
///
- Handle* ModelObject::handleAt( double scale,
- const Distance& x,
- const Distance& y ) const
+ const Handle& ModelObject::handleAt( double scale,
+ Distance x,
+ Distance y ) const
{
+ static Handle nullHandle;
+
if ( mSelectedFlag )
{
QPointF p( x.pt(), y.pt() );
p -= QPointF( mX0.pt(), mY0.pt() ); // Translate point to x0,y0
- foreach ( Handle* handle, mHandles )
+ for ( auto& handle : mHandles )
{
- QPainterPath handlePath = mMatrix.map( handle->path( scale ) );
+ QPainterPath handlePath = mMatrix.map( handle.path( scale ) );
if ( handlePath.contains( p ) )
{
return handle;
@@ -1219,17 +1210,17 @@ namespace glabels
}
}
- return nullptr;
+ return nullHandle;
}
///
/// Draw object + shadow
///
- void ModelObject::draw( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelObject::draw( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
painter->save();
painter->translate( mX0.pt(), mY0.pt() );
@@ -1260,14 +1251,11 @@ namespace glabels
painter->translate( mX0.pt(), mY0.pt() );
painter->setTransform( mMatrix, true );
- if ( mOutline )
- {
- mOutline->draw( painter );
- }
+ mOutline.draw( painter );
- foreach( Handle* handle, mHandles )
+ for( auto& handle : mHandles )
{
- handle->draw( painter, scale );
+ handle.draw( painter, scale );
}
painter->restore();
diff --git a/model/ModelObject.h b/model/ModelObject.h
index c0270c4..cd4e093 100644
--- a/model/ModelObject.h
+++ b/model/ModelObject.h
@@ -24,7 +24,7 @@
#include "ColorNode.h"
#include "Distance.h"
-#include "Handles.h"
+#include "Handle.h"
#include "Outline.h"
#include "TextNode.h"
#include "Variables.h"
@@ -37,6 +37,9 @@
#include
#include
+#include
+#include
+
namespace glabels
{
@@ -61,22 +64,22 @@ namespace glabels
protected:
ModelObject();
- ModelObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio = false,
+ ModelObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio = false,
const QTransform& matrix = QTransform(),
- bool shadowState = false,
- const Distance& shadowX = 0,
- const Distance& shadowY = 0,
- double shadowOpacity = 1.0,
- const ColorNode& shadowColorNode = ColorNode() );
+ bool shadowState = false,
+ Distance shadowX = 0,
+ Distance shadowY = 0,
+ double shadowOpacity = 1.0,
+ const ColorNode& shadowColorNode = ColorNode() );
ModelObject( const ModelObject* object );
public:
- ~ModelObject() override;
+ virtual ~ModelObject() = default;
///////////////////////////////////////////////////////////////
@@ -114,28 +117,28 @@ namespace glabels
// x0 Property ( x coordinate of origin )
//
Distance x0() const;
- void setX0( const Distance& value );
+ void setX0( Distance value );
//
// y0 Property ( y coordinate of origin )
//
Distance y0() const;
- void setY0( const Distance& value );
+ void setY0( Distance value );
//
// w Property ( width of bounding box )
//
Distance w() const;
- void setW( const Distance& value );
+ void setW( Distance value );
//
// h Property ( height of bounding box )
//
Distance h() const;
- void setH( const Distance& value );
+ void setH( Distance value );
//
@@ -163,14 +166,14 @@ namespace glabels
// Shadow x Offset Property
//
Distance shadowX() const;
- void setShadowX( const Distance& value );
+ void setShadowX( Distance value );
//
// Shadow y Offset Property
//
Distance shadowY() const;
- void setShadowY( const Distance& value );
+ void setShadowY( Distance value );
//
@@ -295,7 +298,7 @@ namespace glabels
//
// Virtual Image Property: image
//
- virtual const QImage* image() const;
+ virtual const QImage& image() const;
virtual void setImage( const QImage& value );
virtual void setImage( const QString& name, const QImage& value );
@@ -303,7 +306,7 @@ namespace glabels
//
// Virtual Image Property: svg
//
- virtual QByteArray svg() const;
+ virtual const QByteArray& svg() const;
virtual void setSvg( const QString& name, const QByteArray& value );
@@ -315,7 +318,7 @@ namespace glabels
// Virtual Shape Property: lineWidth
//
virtual Distance lineWidth() const;
- virtual void setLineWidth( const Distance& value );
+ virtual void setLineWidth( Distance value );
//
@@ -392,43 +395,43 @@ namespace glabels
// Position and Size methods
///////////////////////////////////////////////////////////////
public:
- void setPosition( const Distance& x0, const Distance& y0 );
- void setPositionRelative( const Distance& dx, const Distance& dy );
+ void setPosition( Distance x0, Distance y0 );
+ void setPositionRelative( Distance dx, Distance dy );
Size size() const;
- void setSize( const Distance& w, const Distance& h );
- void setSize( const Size& size );
- void setSizeHonorAspect( const Distance& w, const Distance& h );
- void setWHonorAspect( const Distance& w );
- void setHHonorAspect( const Distance& h );
+ void setSize( Distance w, Distance h );
+ void setSize( Size size );
+ void setSizeHonorAspect( Distance w, Distance h );
+ void setWHonorAspect( Distance w );
+ void setHHonorAspect( Distance h );
Region getExtent();
void rotate( double thetaDegs );
void flipHoriz();
void flipVert();
- bool isLocatedAt( double scale, const Distance& x, const Distance& y ) const;
- Handle* handleAt( double scale, const Distance& x, const Distance& y ) const;
+ bool isLocatedAt( double scale, Distance x, Distance y ) const;
+ const Handle& handleAt( double scale, Distance x, Distance y ) const;
///////////////////////////////////////////////////////////////
// Drawing operations
///////////////////////////////////////////////////////////////
public:
- void draw( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const;
+ void draw( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const;
void drawSelectionHighlight( QPainter* painter, double scale ) const;
protected:
- virtual void drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const = 0;
+ virtual void drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const = 0;
- virtual void drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const = 0;
+ virtual void drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const = 0;
virtual QPainterPath hoverPath( double scale ) const = 0;
@@ -453,8 +456,9 @@ namespace glabels
double mShadowOpacity;
ColorNode mShadowColorNode;
- QList mHandles;
- Outline* mOutline;
+ Outline mOutline;
+
+ QList mHandles;
///////////////////////////////////////////////////////////////
diff --git a/model/ModelShapeObject.cpp b/model/ModelShapeObject.cpp
index 44fe308..e7f0287 100644
--- a/model/ModelShapeObject.cpp
+++ b/model/ModelShapeObject.cpp
@@ -34,16 +34,16 @@ namespace glabels
///
ModelShapeObject::ModelShapeObject()
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
mLineWidth = 1.0;
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
@@ -54,34 +54,42 @@ namespace glabels
///
/// Constructor
///
- ModelShapeObject::ModelShapeObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const Distance& lineWidth,
- const ColorNode& lineColorNode,
- const ColorNode& fillColorNode,
+ ModelShapeObject::ModelShapeObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ Distance lineWidth,
+ const ColorNode& lineColorNode,
+ const ColorNode& fillColorNode,
const QTransform& matrix,
- bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
- double shadowOpacity,
- const ColorNode& shadowColorNode )
- : ModelObject( x0, y0, w, h, lockAspectRatio,
+ bool shadowState,
+ Distance shadowX,
+ Distance shadowY,
+ double shadowOpacity,
+ const ColorNode& shadowColorNode )
+ : ModelObject( x0,
+ y0,
+ w,
+ h,
+ lockAspectRatio,
matrix,
- shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
+ shadowState,
+ shadowX,
+ shadowY,
+ shadowOpacity,
+ shadowColorNode )
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
mLineWidth = lineWidth;
mLineColorNode = lineColorNode;
@@ -100,21 +108,6 @@ namespace glabels
}
- ///
- /// Destructor
- ///
- ModelShapeObject::~ModelShapeObject()
- {
- delete mOutline;
-
- foreach( Handle* handle, mHandles )
- {
- delete handle;
- }
- mHandles.clear();
- }
-
-
///
/// Line Width Property Getter
///
@@ -127,7 +120,7 @@ namespace glabels
///
/// Line Width Property Setter
///
- void ModelShapeObject::setLineWidth( const Distance& value )
+ void ModelShapeObject::setLineWidth( Distance value )
{
if ( mLineWidth != value )
{
diff --git a/model/ModelShapeObject.h b/model/ModelShapeObject.h
index f8e3d5f..2cd5740 100644
--- a/model/ModelShapeObject.h
+++ b/model/ModelShapeObject.h
@@ -43,24 +43,24 @@ namespace glabels
protected:
ModelShapeObject();
- ModelShapeObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
- bool lockAspectRatio,
- const Distance& lineWidth,
- const ColorNode& lineColorNode,
- const ColorNode& fillColorNode,
+ ModelShapeObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
+ bool lockAspectRatio,
+ Distance lineWidth,
+ const ColorNode& lineColorNode,
+ const ColorNode& fillColorNode,
const QTransform& matrix,
- bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
- double shadowOpacity,
- const ColorNode& shadowColorNode );
+ bool shadowState,
+ Distance shadowX,
+ Distance shadowY,
+ double shadowOpacity,
+ const ColorNode& shadowColorNode );
ModelShapeObject( const ModelShapeObject* object );
public:
- ~ModelShapeObject() override;
+ virtual ~ModelShapeObject() = default;
///////////////////////////////////////////////////////////////
@@ -71,7 +71,7 @@ namespace glabels
// Shape Property: lineWidth
//
Distance lineWidth() const override;
- void setLineWidth( const Distance& value ) override;
+ void setLineWidth( Distance value ) override;
//
diff --git a/model/ModelTextObject.cpp b/model/ModelTextObject.cpp
index d175925..b3f61db 100644
--- a/model/ModelTextObject.cpp
+++ b/model/ModelTextObject.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "ModelTextObject.h"
#include "Size.h"
@@ -49,16 +50,16 @@ namespace glabels
///
ModelTextObject::ModelTextObject()
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
mText = "";
mFontFamily = "Sans";
@@ -78,10 +79,10 @@ namespace glabels
///
/// Constructor
///
- ModelTextObject::ModelTextObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
+ ModelTextObject::ModelTextObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
bool lockAspectRatio,
const QString& text,
const QString& fontFamily,
@@ -97,24 +98,32 @@ namespace glabels
bool textAutoShrink,
const QTransform& matrix,
bool shadowState,
- const Distance& shadowX,
- const Distance& shadowY,
+ Distance shadowX,
+ Distance shadowY,
double shadowOpacity,
const ColorNode& shadowColorNode )
- : ModelObject( x0, y0, w, h, lockAspectRatio,
+ : ModelObject( x0,
+ y0,
+ w,
+ h,
+ lockAspectRatio,
matrix,
- shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode )
+ shadowState,
+ shadowX,
+ shadowY,
+ shadowOpacity,
+ shadowColorNode )
{
- mOutline = new Outline( this );
+ mOutline.setOwner( this );
- mHandles << new HandleNorthWest( this );
- mHandles << new HandleNorth( this );
- mHandles << new HandleNorthEast( this );
- mHandles << new HandleEast( this );
- mHandles << new HandleSouthEast( this );
- mHandles << new HandleSouth( this );
- mHandles << new HandleSouthWest( this );
- mHandles << new HandleWest( this );
+ mHandles.push_back( Handle( this, Handle::NW ) );
+ mHandles.push_back( Handle( this, Handle::N ) );
+ mHandles.push_back( Handle( this, Handle::NE ) );
+ mHandles.push_back( Handle( this, Handle::E ) );
+ mHandles.push_back( Handle( this, Handle::SE ) );
+ mHandles.push_back( Handle( this, Handle::S ) );
+ mHandles.push_back( Handle( this, Handle::SW ) );
+ mHandles.push_back( Handle( this, Handle::W ) );
mText = text;
mFontFamily = fontFamily;
@@ -161,13 +170,8 @@ namespace glabels
///
ModelTextObject::~ModelTextObject()
{
- delete mOutline;
-
- foreach( Handle* handle, mHandles )
- {
- delete handle;
- }
- mHandles.clear();
+ qDeleteAll( mEditorLayouts );
+ mEditorLayouts.clear();
}
@@ -484,21 +488,21 @@ namespace glabels
QRectF boundingRect;
for ( int i = 0; i < document.blockCount(); i++ )
{
- QTextLayout* layout = new QTextLayout( document.findBlockByNumber(i).text() );
+ QTextLayout layout( document.findBlockByNumber(i).text() );
- layout->setFont( font );
- layout->setTextOption( textOption );
- layout->setCacheEnabled(true);
+ layout.setFont( font );
+ layout.setTextOption( textOption );
+ layout.setCacheEnabled(true);
- layout->beginLayout();
- for ( QTextLine l = layout->createLine(); l.isValid(); l = layout->createLine() )
+ layout.beginLayout();
+ for ( QTextLine l = layout.createLine(); l.isValid(); l = layout.createLine() )
{
l.setPosition( QPointF( x, y ) );
y += dy;
}
- layout->endLayout();
+ layout.endLayout();
- boundingRect = layout->boundingRect().united( boundingRect );
+ boundingRect = layout.boundingRect().united( boundingRect );
}
return Size( boundingRect.width() + 2*marginPts, boundingRect.height() + 2*marginPts );
@@ -517,10 +521,10 @@ namespace glabels
///
/// Draw shadow of object
///
- void ModelTextObject::drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelTextObject::drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QColor textColor = mTextColorNode.color( record, variables );
@@ -544,10 +548,10 @@ namespace glabels
///
/// Draw object itself
///
- void ModelTextObject::drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const
+ void ModelTextObject::drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const
{
QColor textColor = mTextColorNode.color( record, variables );
@@ -697,10 +701,10 @@ namespace glabels
/// Draw text in final printout or preview
///
void
- ModelTextObject::drawText( QPainter* painter,
- const QColor& color,
- merge::Record* record,
- Variables* variables ) const
+ ModelTextObject::drawText( QPainter* painter,
+ const QColor& color,
+ const merge::Record& record,
+ const Variables& variables ) const
{
painter->save();
@@ -794,7 +798,8 @@ namespace glabels
/// Determine auto shrink font size
///
double
- ModelTextObject::autoShrinkFontSize( merge::Record* record, Variables* variables ) const
+ ModelTextObject::autoShrinkFontSize( const merge::Record& record,
+ const Variables& variables ) const
{
QFont font;
font.setFamily( mFontFamily );
diff --git a/model/ModelTextObject.h b/model/ModelTextObject.h
index 1dc5cd8..514f8eb 100644
--- a/model/ModelTextObject.h
+++ b/model/ModelTextObject.h
@@ -46,10 +46,10 @@ namespace glabels
public:
ModelTextObject();
- ModelTextObject( const Distance& x0,
- const Distance& y0,
- const Distance& w,
- const Distance& h,
+ ModelTextObject( Distance x0,
+ Distance y0,
+ Distance w,
+ Distance h,
bool lockAspectRatio,
const QString& text,
const QString& fontFamily,
@@ -65,14 +65,14 @@ namespace glabels
bool textAutoShrink,
const QTransform& matrix = QTransform(),
bool shadowState = false,
- const Distance& shadowX = 0,
- const Distance& shadowY = 0,
+ Distance shadowX = 0,
+ Distance shadowY = 0,
double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() );
ModelTextObject( const ModelTextObject* object );
- ~ModelTextObject() override;
+ virtual ~ModelTextObject();
///////////////////////////////////////////////////////////////
@@ -186,15 +186,15 @@ namespace glabels
// Drawing operations
///////////////////////////////////////////////////////////////
protected:
- void drawShadow( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawShadow( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
- void drawObject( QPainter* painter,
- bool inEditor,
- merge::Record* record,
- Variables* variables ) const override;
+ void drawObject( QPainter* painter,
+ bool inEditor,
+ const merge::Record& record,
+ const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override;
@@ -209,13 +209,13 @@ namespace glabels
void drawTextInEditor( QPainter* painter,
const QColor& color ) const;
- void drawText( QPainter* painter,
- const QColor& color,
- merge::Record* record,
- Variables* variables ) const;
+ void drawText( QPainter* painter,
+ const QColor& color,
+ const merge::Record& record,
+ const Variables& variables ) const;
- double autoShrinkFontSize( merge::Record* record,
- Variables* variables ) const;
+ double autoShrinkFontSize( const merge::Record& record,
+ const Variables& variables ) const;
///////////////////////////////////////////////////////////////
diff --git a/model/Outline.cpp b/model/Outline.cpp
index 481e949..171e037 100644
--- a/model/Outline.cpp
+++ b/model/Outline.cpp
@@ -45,11 +45,12 @@ namespace glabels
///
- /// Outline Constructor
+ /// Set owner and enable outline
///
- Outline::Outline( ModelObject* owner )
- : mOwner(owner)
+ void Outline::setOwner( ModelObject* owner )
{
+ mOwner = owner;
+
mDashes << dashSize << dashSize;
mPen1.setColor( outlineColor1 );
@@ -68,32 +69,11 @@ namespace glabels
///
- /// Outline Copy constructor
+ /// Is enabled? (I.e. not all objects have an outline (e.g. line objects))
///
- Outline::Outline( const Outline* outline, ModelObject* newOwner )
- : mOwner(newOwner)
+ bool Outline::isEnabled() const
{
- mDashes = outline->mDashes;
- mPen1 = outline->mPen1;
- mPen2 = outline->mPen2;
- }
-
-
- ///
- /// Outline Destructor
- ///
- Outline::~Outline()
- {
- // empty
- }
-
-
- ///
- /// Clone Outline
- ///
- Outline* Outline::clone( ModelObject* newOwner ) const
- {
- return new Outline( this, newOwner );
+ return mOwner;
}
@@ -102,17 +82,20 @@ namespace glabels
///
void Outline::draw( QPainter* painter ) const
{
- painter->save();
+ if ( mOwner )
+ {
+ painter->save();
- painter->setBrush( Qt::NoBrush );
+ painter->setBrush( Qt::NoBrush );
- painter->setPen( mPen1 );
- painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
+ painter->setPen( mPen1 );
+ painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
- painter->setPen( mPen2 );
- painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
+ painter->setPen( mPen2 );
+ painter->drawRect( QRectF( 0, 0, mOwner->w().pt(), mOwner->h().pt() ) );
- painter->restore();
+ painter->restore();
+ }
}
@@ -121,16 +104,19 @@ namespace glabels
///
QPainterPath Outline::hoverPath( double scale ) const
{
- double s = 1 / scale;
-
QPainterPath path;
- path.addRect( -s*slopPixels, -s*slopPixels,
- mOwner->w().pt()+s*2*slopPixels, mOwner->h().pt()+s*2*slopPixels );
- path.closeSubpath();
- path.addRect( s*slopPixels, s*slopPixels,
- mOwner->w().pt()-s*2*slopPixels, mOwner->h().pt()-s*2*slopPixels );
-
+ if ( mOwner )
+ {
+ double s = 1 / scale;
+
+ path.addRect( -s*slopPixels, -s*slopPixels,
+ mOwner->w().pt()+s*2*slopPixels, mOwner->h().pt()+s*2*slopPixels );
+ path.closeSubpath();
+ path.addRect( s*slopPixels, s*slopPixels,
+ mOwner->w().pt()-s*2*slopPixels, mOwner->h().pt()-s*2*slopPixels );
+ }
+
return path;
}
diff --git a/model/Outline.h b/model/Outline.h
index b3c1e5e..750ebbd 100644
--- a/model/Outline.h
+++ b/model/Outline.h
@@ -25,6 +25,8 @@
#include
#include
+#include
+
namespace glabels
{
@@ -36,7 +38,7 @@ namespace glabels
///
- /// Outline Base Class
+ /// Outline Class
///
class Outline
{
@@ -44,15 +46,15 @@ namespace glabels
// Lifecycle Methods
////////////////////////////
public:
- Outline( ModelObject* owner );
- Outline( const Outline* outline, ModelObject* newOwner );
- virtual ~Outline();
+ Outline() = default;
+ ~Outline() = default;
+
-
////////////////////////////
- // Duplication
+ // Ownership
////////////////////////////
- Outline* clone( ModelObject* newOwner ) const;
+ void setOwner( ModelObject* owner );
+ bool isEnabled() const;
////////////////////////////
@@ -67,7 +69,7 @@ namespace glabels
// Private Data
////////////////////////////
private:
- ModelObject* mOwner;
+ ModelObject* mOwner{ nullptr };
QVector mDashes;
QPen mPen1;
diff --git a/model/PageRenderer.cpp b/model/PageRenderer.cpp
index f1092aa..bc961dd 100644
--- a/model/PageRenderer.cpp
+++ b/model/PageRenderer.cpp
@@ -62,7 +62,6 @@ namespace glabels
connect( mModel, SIGNAL(changed()), this, SLOT(onModelChanged()) );
onModelChanged();
- mVariables = mModel->variables();
}
@@ -168,7 +167,7 @@ namespace glabels
{
if ( mModel )
{
- return QRectF( 0, 0, mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() );
+ return QRectF( 0, 0, mModel->tmplate().pageWidth().pt(), mModel->tmplate().pageHeight().pt() );
}
else
{
@@ -232,7 +231,7 @@ namespace glabels
///
void PageRenderer::print( QPrinter* printer ) const
{
- QSizeF pageSize( mModel->tmplate()->pageWidth().pt(), mModel->tmplate()->pageHeight().pt() );
+ QSizeF pageSize( mModel->tmplate().pageWidth().pt(), mModel->tmplate().pageHeight().pt() );
printer->setPageSize( QPageSize(pageSize, QPageSize::Point) );
printer->setFullPage( true );
printer->setPageMargins( QMarginsF(0, 0, 0, 0), QPageLayout::Point );
@@ -298,7 +297,8 @@ namespace glabels
int iCopy = 0;
int iItem = mStartItem;
int iCurrentPage = 0;
- mVariables->resetVariables();
+
+ Variables variables( mModel->constVariables() );
while ( (iCopy < mNCopies) && (iCurrentPage <= iPage) )
{
@@ -313,7 +313,7 @@ namespace glabels
painter->save();
clipLabel( painter );
- printLabel( painter, nullptr, mVariables );
+ printLabel( painter, merge::NullRecord(), variables );
painter->restore(); // From before clip
@@ -328,11 +328,11 @@ namespace glabels
iCurrentPage = iItem / mNItemsPerPage;
// User variable book keeping
- mVariables->incrementVariablesOnItem();
- mVariables->incrementVariablesOnCopy();
+ variables.incrementVariablesOnItem();
+ variables.incrementVariablesOnCopy();
if ( (iItem % mNItemsPerPage) == 0 /* starting a new page */ )
{
- mVariables->incrementVariablesOnPage();
+ variables.incrementVariablesOnPage();
}
}
}
@@ -346,7 +346,7 @@ namespace glabels
int iItem = mStartItem;
int iCurrentPage = 0;
- const QList records = mMerge->selectedRecords();
+ auto records = mMerge->selectedRecords();
int iRecord = 0;
int nRecords = records.size();
@@ -355,7 +355,7 @@ namespace glabels
return;
}
- mVariables->resetVariables();
+ Variables variables( mModel->constVariables() );
while ( (iCopy < mNCopies) && (iCurrentPage <= iPage) )
{
@@ -370,7 +370,7 @@ namespace glabels
painter->save();
clipLabel( painter );
- printLabel( painter, records[iRecord], mVariables );
+ printLabel( painter, records[iRecord], variables );
painter->restore(); // From before clip
@@ -400,14 +400,14 @@ namespace glabels
iCurrentPage = iItem / mNItemsPerPage;
// User variable book keeping
- mVariables->incrementVariablesOnItem();
+ variables.incrementVariablesOnItem();
if ( iRecord == 0 )
{
- mVariables->incrementVariablesOnCopy();
+ variables.incrementVariablesOnCopy();
}
if ( (iItem % mNItemsPerPage) == 0 /* starting a new page */ )
{
- mVariables->incrementVariablesOnPage();
+ variables.incrementVariablesOnPage();
}
}
}
@@ -421,7 +421,7 @@ namespace glabels
int iItem = mStartItem;
int iCurrentPage = 0;
- const QList records = mMerge->selectedRecords();
+ auto records = mMerge->selectedRecords();
int iRecord = 0;
int nRecords = records.size();
@@ -430,7 +430,7 @@ namespace glabels
return;
}
- mVariables->resetVariables();
+ Variables variables( mModel->constVariables() );
while ( (iRecord < nRecords) && (iCurrentPage <= iPage) )
{
@@ -445,7 +445,7 @@ namespace glabels
painter->save();
clipLabel( painter );
- printLabel( painter, records[iRecord], mVariables );
+ printLabel( painter, records[iRecord], variables );
painter->restore(); // From before clip
@@ -475,15 +475,15 @@ namespace glabels
iCurrentPage = iItem / mNItemsPerPage;
// User variable book keeping
- mVariables->incrementVariablesOnItem();
- mVariables->incrementVariablesOnCopy();
+ variables.incrementVariablesOnItem();
+ variables.incrementVariablesOnCopy();
if ( iCopy == 0 )
{
- mVariables->resetOnCopyVariables();
+ variables.resetOnCopyVariables();
}
if ( (iItem % mNItemsPerPage) == 0 /* starting a new page */ )
{
- mVariables->incrementVariablesOnPage();
+ variables.incrementVariablesOnPage();
}
}
}
@@ -501,7 +501,7 @@ namespace glabels
Distance w = mModel->frame()->w();
Distance h = mModel->frame()->h();
- foreach ( const Layout& layout, mModel->frame()->layouts() )
+ for ( auto& layout : mModel->frame()->layouts() )
{
Distance xMin = layout.x0();
Distance yMin = layout.y0();
@@ -516,8 +516,8 @@ namespace glabels
Distance y1 = max( yMin-tickOffset, Distance::pt(0) );
Distance y2 = max( y1-tickLength, Distance::pt(0) );
- Distance y3 = min( yMax+tickOffset, mModel->tmplate()->pageHeight() );
- Distance y4 = min( y3+tickLength, mModel->tmplate()->pageHeight() );
+ Distance y3 = min( yMax+tickOffset, mModel->tmplate().pageHeight() );
+ Distance y4 = min( y3+tickLength, mModel->tmplate().pageHeight() );
painter->drawLine( x1.pt(), y1.pt(), x1.pt(), y2.pt() );
painter->drawLine( x2.pt(), y1.pt(), x2.pt(), y2.pt() );
@@ -533,8 +533,8 @@ namespace glabels
Distance x1 = max( xMin-tickOffset, Distance::pt(0) );
Distance x2 = max( x1-tickLength, Distance::pt(0) );
- Distance x3 = min( xMax+tickOffset, mModel->tmplate()->pageWidth() );
- Distance x4 = min( x3+tickLength, mModel->tmplate()->pageWidth() );
+ Distance x3 = min( xMax+tickOffset, mModel->tmplate().pageWidth() );
+ Distance x4 = min( x3+tickLength, mModel->tmplate().pageWidth() );
painter->drawLine( x1.pt(), y1.pt(), x2.pt(), y1.pt() );
painter->drawLine( x1.pt(), y2.pt(), x2.pt(), y2.pt() );
@@ -570,9 +570,9 @@ namespace glabels
}
- void PageRenderer::printLabel( QPainter* painter,
- merge::Record* record,
- Variables* variables ) const
+ void PageRenderer::printLabel( QPainter* painter,
+ const merge::Record& record,
+ Variables& variables ) const
{
painter->save();
diff --git a/model/PageRenderer.h b/model/PageRenderer.h
index eb30d9c..b1e35bd 100644
--- a/model/PageRenderer.h
+++ b/model/PageRenderer.h
@@ -104,7 +104,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, Variables* variables ) const;
+ void printLabel( QPainter* painter, const merge::Record& record, Variables& variables ) const;
/////////////////////////////////
@@ -113,8 +113,7 @@ namespace glabels
private:
const Model* mModel{ nullptr };
const merge::Merge* mMerge{ nullptr };
- Variables* mVariables{ nullptr };
-
+
int mNCopies{ 0 };
int mStartItem{ 0 };
int mLastItem{ 0 };
diff --git a/model/Paper.cpp b/model/Paper.cpp
index 5aa87f3..deb9a50 100644
--- a/model/Paper.cpp
+++ b/model/Paper.cpp
@@ -26,12 +26,16 @@ namespace glabels
namespace model
{
- Paper::Paper( const QString& id,
- const QString& name,
- const Distance& width,
- const Distance& height,
- const QString& pwgSize )
- : mId(id), mName(name), mWidth(width), mHeight(height), mPwgSize(pwgSize)
+ Paper::Paper( const QString& id,
+ const QString& name,
+ Distance width,
+ Distance height,
+ const QString& pwgSize )
+ : mId(id),
+ mName(name),
+ mWidth(width),
+ mHeight(height),
+ mPwgSize(pwgSize)
{
// empty
}
diff --git a/model/Paper.h b/model/Paper.h
index 9d95ac3..b10a3ad 100644
--- a/model/Paper.h
+++ b/model/Paper.h
@@ -35,11 +35,13 @@ namespace glabels
class Paper
{
public:
- Paper( const QString& id,
- const QString& name,
- const Distance& width,
- const Distance& height,
- const QString& pwgSize );
+ Paper() = default;
+ Paper( const QString& id,
+ const QString& name,
+ Distance width,
+ Distance height,
+ const QString& pwgSize );
+ ~Paper() = default;
QString id() const;
QString name() const;
diff --git a/model/ParserState.cpp b/model/ParserState.cpp
index 34cd3b0..725eef0 100644
--- a/model/ParserState.cpp
+++ b/model/ParserState.cpp
@@ -73,7 +73,7 @@ namespace glabels
qsizetype
ParserState::charsLeft() const
{
- return mString->size() - mPos;
+ return std::max( mString->size() - mPos, qsizetype(0) );
}
diff --git a/model/ParserState.h b/model/ParserState.h
index da75ad0..d1c15d5 100644
--- a/model/ParserState.h
+++ b/model/ParserState.h
@@ -47,7 +47,7 @@ namespace glabels
private:
- const QString* mString;
+ const QString* mString{ nullptr };
qsizetype mPos{ 0 };
};
diff --git a/model/RawText.cpp b/model/RawText.cpp
index 9cd9d5d..0cec7d2 100644
--- a/model/RawText.cpp
+++ b/model/RawText.cpp
@@ -23,6 +23,7 @@
#include "ParserState.h"
+#include
#include
@@ -70,7 +71,7 @@ namespace glabels
///
/// Expand all place holders
///
- QString RawText::expand( merge::Record* record, Variables* variables ) const
+ QString RawText::expand( const merge::Record& record, const Variables& variables ) const
{
QString text;
diff --git a/model/RawText.h b/model/RawText.h
index d1a73d3..e9da78f 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, Variables* variables ) const;
+ QString expand( const merge::Record& record, const Variables& variables ) const;
bool hasPlaceHolders() const;
bool isEmpty() const;
@@ -71,7 +71,7 @@ namespace glabels
struct Token
{
- bool isField;
+ bool isField{ false };
QString text;
SubstitutionField field;
};
diff --git a/model/Region.cpp b/model/Region.cpp
index d5ec1d9..c3d242f 100644
--- a/model/Region.cpp
+++ b/model/Region.cpp
@@ -29,7 +29,11 @@ namespace glabels
///
/// Constructor
///
- Region::Region() : mX1(0), mY1(0), mX2(0), mY2(0)
+ Region::Region()
+ : mX1(0),
+ mY1(0),
+ mX2(0),
+ mY2(0)
{
// empty
}
@@ -38,9 +42,14 @@ namespace glabels
///
/// Constructor
///
- Region::Region( const Distance& x1, const Distance& y1,
- const Distance& x2, const Distance& y2 )
- : mX1(x1), mY1(y1), mX2(x2), mY2(y2)
+ Region::Region( Distance x1,
+ Distance y1,
+ Distance x2,
+ Distance y2 )
+ : mX1(x1),
+ mY1(y1),
+ mX2(x2),
+ mY2(y2)
{
// empty
}
@@ -58,7 +67,7 @@ namespace glabels
///
/// Set x1
///
- void Region::setX1( const Distance& value )
+ void Region::setX1( Distance value )
{
mX1 = value;
}
@@ -76,7 +85,7 @@ namespace glabels
///
/// Set y1
///
- void Region::setY1( const Distance& value )
+ void Region::setY1( Distance value )
{
mY1 = value;
}
@@ -94,7 +103,7 @@ namespace glabels
///
/// Set x2
///
- void Region::setX2( const Distance& value )
+ void Region::setX2( Distance value )
{
mX2 = value;
}
@@ -112,7 +121,7 @@ namespace glabels
///
/// Set y2
///
- void Region::setY2( const Distance& value )
+ void Region::setY2( Distance value )
{
mY2 = value;
}
diff --git a/model/Region.h b/model/Region.h
index 16d0c11..af2be20 100644
--- a/model/Region.h
+++ b/model/Region.h
@@ -43,8 +43,10 @@ namespace glabels
/////////////////////////////////
public:
Region();
- Region( const Distance& x1, const Distance& y1,
- const Distance& x2, const Distance& y2 );
+ Region( Distance x1,
+ Distance y1,
+ Distance x2,
+ Distance y2 );
/////////////////////////////////
@@ -55,21 +57,21 @@ namespace glabels
// X1 Property
//
Distance x1() const;
- void setX1( const Distance& value );
+ void setX1( Distance value );
//
// Y1 Property
//
Distance y1() const;
- void setY1( const Distance& value );
+ void setY1( Distance value );
//
// X2 Property
//
Distance x2() const;
- void setX2( const Distance& value );
+ void setX2( Distance value );
@@ -77,7 +79,7 @@ namespace glabels
// Y2 Property
//
Distance y2() const;
- void setY2( const Distance& value );
+ void setY2( Distance value );
/////////////////////////////////
diff --git a/model/Settings.cpp b/model/Settings.cpp
index 07098c7..3e09113 100644
--- a/model/Settings.cpp
+++ b/model/Settings.cpp
@@ -21,6 +21,8 @@
#include "Settings.h"
+#include "Version.h"
+
#include
#include
#include
@@ -35,20 +37,19 @@ namespace glabels
//
// Static data
//
- Settings* Settings::mInstance = nullptr;
+ std::unique_ptr Settings::mInstance;
- Settings::Settings()
- {
- // empty
- }
-
void Settings::init()
{
- if ( mInstance == nullptr )
+ // Note: init() hould be called after
+ // - QCoreApplication::setOrganizationName(), and
+ // - QCoreApplication::setApplicationName()
+
+ if ( !mInstance )
{
- mInstance = new Settings();
+ mInstance.reset( new Settings() );
}
}
@@ -56,8 +57,7 @@ namespace glabels
Settings* Settings::instance()
{
init();
-
- return mInstance;
+ return mInstance.get();
}
@@ -82,7 +82,7 @@ namespace glabels
}
- void Settings::setUnits( const Units& units )
+ void Settings::setUnits( Units units )
{
QString idString = units.toIdString();
diff --git a/model/Settings.h b/model/Settings.h
index be2c5e4..e14c80c 100644
--- a/model/Settings.h
+++ b/model/Settings.h
@@ -23,11 +23,14 @@
#include "Distance.h"
+#include "Units.h"
#include
#include
#include
+#include
+
namespace glabels
{
@@ -50,7 +53,7 @@ namespace glabels
// Life Cycle
/////////////////////////////////
private:
- Settings();
+ Settings() = default;
public:
static void init();
@@ -69,7 +72,7 @@ namespace glabels
/////////////////////////////////
public:
static Units units();
- static void setUnits( const Units& units );
+ static void setUnits( Units units );
static PageSizeFamily preferedPageSizeFamily();
static void setPreferedPageSizeFamily( PageSizeFamily preferedPageSizeFamily );
@@ -111,7 +114,7 @@ namespace glabels
private:
- static Settings* mInstance;
+ static std::unique_ptr mInstance;
static const int mMaxRecentFiles{5};
};
diff --git a/model/Size.cpp b/model/Size.cpp
index e6097ef..5d4d3e7 100644
--- a/model/Size.cpp
+++ b/model/Size.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "Size.h"
@@ -38,7 +39,9 @@ namespace glabels
///
/// Constructor
///
- Size::Size( const Distance& w, const Distance& h ) : mW(w), mH(h)
+ Size::Size( Distance w, Distance h )
+ : mW(w),
+ mH(h)
{
// empty
}
@@ -56,7 +59,7 @@ namespace glabels
///
/// Set w
///
- void Size::setW( const Distance& value )
+ void Size::setW( Distance value )
{
mW = value;
}
@@ -74,7 +77,7 @@ namespace glabels
///
/// Set h
///
- void Size::setH( const Distance& value )
+ void Size::setH( Distance value )
{
mH = value;
}
diff --git a/model/Size.h b/model/Size.h
index cb4a5df..8c59046 100644
--- a/model/Size.h
+++ b/model/Size.h
@@ -43,7 +43,7 @@ namespace glabels
/////////////////////////////////
public:
Size();
- Size( const Distance& w, const Distance& h );
+ Size( Distance w, Distance h );
/////////////////////////////////
@@ -54,14 +54,14 @@ namespace glabels
// w Property
//
Distance w() const;
- void setW( const Distance& value );
+ void setW( Distance value );
//
// H Property
//
Distance h() const;
- void setH( const Distance& value );
+ void setH( Distance value );
/////////////////////////////////
diff --git a/model/SubstitutionField.cpp b/model/SubstitutionField.cpp
index 206fb24..7311920 100644
--- a/model/SubstitutionField.cpp
+++ b/model/SubstitutionField.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "SubstitutionField.h"
#include
@@ -42,25 +43,22 @@ namespace glabels
}
- QString SubstitutionField::evaluate( const merge::Record* record,
- const Variables* variables ) const
+ QString SubstitutionField::evaluate( const merge::Record& record,
+ const Variables& variables ) const
{
QString value = mDefaultValue;
- bool haveRecordField = record &&
- record->contains(mFieldName) &&
- !record->value(mFieldName).isEmpty();
- bool haveVariable = variables &&
- variables->contains(mFieldName) &&
- !(*variables)[mFieldName].value().isEmpty();
+ bool haveRecordField = record.contains(mFieldName) &&
+ !record.value(mFieldName).isEmpty();
+ bool haveVariable = variables.contains(mFieldName) && !variables[mFieldName].value().isEmpty();
if ( haveRecordField )
{
- value = record->value(mFieldName);
+ value = record.value(mFieldName);
}
else if ( haveVariable )
{
- value = (*variables)[mFieldName].value();
+ value = variables[mFieldName].value();
}
if ( !mFormatType.isNull() )
diff --git a/model/SubstitutionField.h b/model/SubstitutionField.h
index 6ef3b8b..38d65bf 100644
--- a/model/SubstitutionField.h
+++ b/model/SubstitutionField.h
@@ -41,7 +41,7 @@ namespace glabels
SubstitutionField();
SubstitutionField( const QString& string );
- QString evaluate( const merge::Record* record, const Variables* variables ) const;
+ QString evaluate( const merge::Record& record, const Variables& variables ) const;
QString fieldName() const;
QString defaultValue() const;
@@ -70,9 +70,9 @@ namespace glabels
QString mDefaultValue;
QString mFormat;
- QChar mFormatType;
+ QChar mFormatType{};
- bool mNewLine;
+ bool mNewLine{ false };
};
}
diff --git a/model/Template.cpp b/model/Template.cpp
index 28dfe18..0f5b3b1 100644
--- a/model/Template.cpp
+++ b/model/Template.cpp
@@ -33,14 +33,15 @@ namespace glabels
namespace model
{
- Template::Template( const QString& brand,
- const QString& part,
- const QString& description,
- const QString& paperId,
- const Distance& pageWidth,
- const Distance& pageHeight,
- const Distance& rollWidth,
- bool isUserDefined )
+ Template::Template( const QString& brand,
+ const QString& part,
+ const QString& description,
+ const QString& paperId,
+ Distance pageWidth,
+ Distance pageHeight,
+ Distance rollWidth,
+ const QString& fileName,
+ bool isUserDefined )
: mBrand(brand),
mPart(part),
mDescription(description),
@@ -48,15 +49,16 @@ namespace glabels
mPageWidth(pageWidth),
mPageHeight(pageHeight),
mRollWidth(rollWidth),
+ mFileName(fileName),
mIsUserDefined(isUserDefined)
{
- mName.append( brand ).append( " " ).append( part );
+ mName = brandPartToName( brand, part );
if ( Db::isPaperIdKnown( paperId ) )
{
- const Paper* paper = Db::lookupPaperFromId( paperId );
- mIsSizeIso = paper->isSizeIso();
- mIsSizeUs = paper->isSizeUs();
+ auto paper = Db::lookupPaperFromId( paperId );
+ mIsSizeIso = paper.isSizeIso();
+ mIsSizeUs = paper.isSizeUs();
}
mIsRoll = (paperId == "roll");
@@ -65,70 +67,61 @@ namespace glabels
Template::Template( const Template& other )
{
- mBrand = other.mBrand;
- mPart = other.mPart;
- mDescription = other.mDescription;
- mPaperId = other.mPaperId;
- mPageWidth = other.mPageWidth;
- mPageHeight = other.mPageHeight;
- mRollWidth = other.mRollWidth;
- mIsSizeIso = other.mIsSizeIso;
- mIsSizeUs = other.mIsSizeUs;
- mIsRoll = other.mIsRoll;
- mEquivPart = other.mEquivPart;
- mName = other.mName;
- mProductUrl = other.mProductUrl;
+ mBrand = other.mBrand;
+ mPart = other.mPart;
+ mDescription = other.mDescription;
+ mPaperId = other.mPaperId;
+ mPageWidth = other.mPageWidth;
+ mPageHeight = other.mPageHeight;
+ mRollWidth = other.mRollWidth;
+ mIsSizeIso = other.mIsSizeIso;
+ mIsSizeUs = other.mIsSizeUs;
+ mIsRoll = other.mIsRoll;
+ mEquivPart = other.mEquivPart;
+ mName = other.mName;
+ mProductUrl = other.mProductUrl;
+ mFileName = other.mFileName;
+ mIsUserDefined = other.mIsUserDefined;
- foreach ( Frame* frame, other.mFrames )
+ if ( other.mFrame )
{
- addFrame( frame->dup() );
+ mFrame = other.mFrame->clone();
}
- foreach ( QString categoryId, other.mCategoryIds )
+ for ( auto& categoryId : other.mCategoryIds )
{
addCategory( categoryId );
}
}
- Template::~Template()
- {
- while ( !mFrames.isEmpty() )
- {
- delete mFrames.takeFirst();
- }
- }
-
-
Template& Template::operator=( const Template& other )
{
if ( this != &other )
{
- mBrand = other.mBrand;
- mPart = other.mPart;
- mDescription = other.mDescription;
- mPaperId = other.mPaperId;
- mPageWidth = other.mPageWidth;
- mPageHeight = other.mPageHeight;
- mRollWidth = other.mRollWidth;
- mIsSizeIso = other.mIsSizeIso;
- mIsSizeUs = other.mIsSizeUs;
- mIsRoll = other.mIsRoll;
- mEquivPart = other.mEquivPart;
- mName = other.mName;
- mProductUrl = other.mProductUrl;
+ mBrand = other.mBrand;
+ mPart = other.mPart;
+ mDescription = other.mDescription;
+ mPaperId = other.mPaperId;
+ mPageWidth = other.mPageWidth;
+ mPageHeight = other.mPageHeight;
+ mRollWidth = other.mRollWidth;
+ mIsSizeIso = other.mIsSizeIso;
+ mIsSizeUs = other.mIsSizeUs;
+ mIsRoll = other.mIsRoll;
+ mEquivPart = other.mEquivPart;
+ mName = other.mName;
+ mProductUrl = other.mProductUrl;
+ mFileName = other.mFileName;
+ mIsUserDefined = other.mIsUserDefined;
- while ( !mFrames.isEmpty() )
+ if ( other.mFrame )
{
- delete mFrames.takeFirst();
- }
- foreach ( Frame* frame, other.mFrames )
- {
- addFrame( frame->dup() );
+ mFrame = other.mFrame->clone();
}
mCategoryIds.clear();
- foreach ( QString categoryId, other.mCategoryIds )
+ for ( auto& categoryId : other.mCategoryIds )
{
addCategory( categoryId );
}
@@ -138,29 +131,19 @@ namespace glabels
}
- // Generic full page template
- Template* Template::fullPage( const QString& paperId )
- {
- // TODO
- return nullptr;
- }
-
-
// From equivalent part number
- Template* Template::fromEquiv( const QString& brand,
- const QString& part,
- const QString& equivPart )
+ Template Template::fromEquiv( const QString& brand,
+ const QString& part,
+ const QString& equivPart )
{
- const Template* other = Db::lookupTemplateFromBrandPart( brand, equivPart );
- if ( other != nullptr )
+ if ( Db::isTemplateKnown( brand, equivPart ) )
{
- Template* tmplate = new Template( *other );
+ auto tmplate = Db::lookupTemplateFromBrandPart( brand, equivPart );
- tmplate->mPart = part;
- tmplate->mEquivPart = equivPart;
+ tmplate.mPart = part;
+ tmplate.mEquivPart = equivPart;
- tmplate->mName = "";
- tmplate->mName.append( brand ).append( " " ).append( part );
+ tmplate.mName = brandPartToName( brand, part );
return tmplate;
}
@@ -169,11 +152,24 @@ namespace glabels
qWarning() << "Error: cannot create equivalent template for "
<< brand << ", " << equivPart
<< ". Forward references not supported.";
- return nullptr;
+ return Template();
}
}
+ QString Template::brandPartToName( const QString& brand,
+ const QString& part )
+ {
+ return QString( "%1 %2" ).arg( brand ).arg( part );
+ }
+
+
+ bool Template::isNull() const
+ {
+ return mBrand.isEmpty() || mPart.isEmpty();
+ }
+
+
QString Template::brand() const
{
return mBrand;
@@ -192,7 +188,7 @@ namespace glabels
}
- QString Template::paperDescription( const Units& units ) const
+ QString Template::paperDescription( Units units ) const
{
if ( mPaperId == "other" )
{
@@ -231,8 +227,7 @@ namespace glabels
Distance Template::pageHeight() const
{
// Adjust height if continuous tape
- const model::Frame* frame = mFrames.constFirst();
- if ( const auto* frameContinuous = dynamic_cast(frame) )
+ if ( const auto* frameContinuous = dynamic_cast( mFrame.get() ) )
{
return frameContinuous->h();
}
@@ -273,12 +268,30 @@ namespace glabels
}
+ QString Template::fileName() const
+ {
+ return mFileName;
+ }
+
+
+ void Template::setFileName( const QString& value )
+ {
+ mFileName = value;
+ }
+
+
bool Template::isUserDefined() const
{
return mIsUserDefined;
}
+ void Template::setIsUserDefined( bool isUserDefined )
+ {
+ mIsUserDefined = isUserDefined;
+ }
+
+
QString Template::equivPart() const
{
return mEquivPart;
@@ -309,9 +322,9 @@ namespace glabels
}
- const QList& Template::frames() const
+ const Frame* Template::frame( const QString& id ) const
{
- return mFrames;
+ return mFrame.get();
}
@@ -321,9 +334,9 @@ namespace glabels
}
- void Template::addFrame( Frame* frame )
+ void Template::addFrame( const Frame& frame )
{
- mFrames << frame;
+ mFrame = frame.clone();
}
@@ -335,7 +348,7 @@ namespace glabels
bool Template::hasCategory( const QString& categoryId ) const
{
- foreach ( QString testCategoryId, mCategoryIds )
+ for ( auto& testCategoryId : mCategoryIds )
{
if ( categoryId == testCategoryId )
{
@@ -347,29 +360,29 @@ namespace glabels
}
- bool Template::isSimilarTo( const Template* other ) const
+ bool Template::isSimilarTo( const Template& other ) const
{
// Does page size match?
- if ( (mPaperId != other->mPaperId) ||
- (mPageWidth != other->mPageWidth ) ||
- (mPageHeight != other->mPageHeight ) )
+ if ( (mPaperId != other.mPaperId) ||
+ (mPageWidth != other.mPageWidth ) ||
+ (mPageHeight != other.mPageHeight ) )
{
return false;
}
// Are frames similar
- Frame* frame1 = mFrames.first();
- Frame* frame2 = other->mFrames.first();
- if ( !frame1->isSimilarTo( frame2 ) )
+ auto& frame1 = mFrame;
+ auto& frame2 = other.mFrame;
+ if ( !frame1->isSimilarTo( *frame2 ) )
{
return false;
}
// Are they layed out similarly?
- foreach ( const Layout& layout1, frame1->layouts() )
+ for ( auto& layout1 : frame1->layouts() )
{
bool matchFound = false;
- foreach ( const Layout& layout2, frame2->layouts() )
+ for ( auto& layout2 : frame2->layouts() )
{
if ( layout1.isSimilarTo( layout2 ) )
{
@@ -387,6 +400,18 @@ namespace glabels
}
+ bool Template::setH( Distance h )
+ {
+ if ( mFrame )
+ {
+ return mFrame->setH( h );
+ }
+ else
+ {
+ return false;
+ }
+ }
+
}
}
@@ -405,7 +430,7 @@ QDebug operator<<( QDebug dbg, const glabels::model::Template& tmplate )
<< tmplate.isSizeUs() << ","
<< tmplate.isSizeOther() << ","
<< tmplate.isRoll() << ","
- << *tmplate.frames().constFirst() << ","
+ << *tmplate.frame() << ","
<< " }";
return dbg;
}
diff --git a/model/Template.h b/model/Template.h
index 3decf5b..fdade2b 100644
--- a/model/Template.h
+++ b/model/Template.h
@@ -45,35 +45,37 @@ namespace glabels
Template() = default;
- Template( const QString& brand,
- const QString& part,
- const QString& description,
- const QString& paperId,
- const Distance& pageWidth,
- const Distance& pageHeight,
- const Distance& rollWidth = 0,
- bool isUserDefined = false );
+ Template( const QString& brand,
+ const QString& part,
+ const QString& description,
+ const QString& paperId,
+ Distance pageWidth,
+ Distance pageHeight,
+ Distance rollWidth = 0,
+ const QString& fileName = "",
+ bool isUserDefined = false );
Template( const Template& other );
- ~Template();
+ ~Template() = default;
Template& operator=( const Template& other );
- // Generic full page template
- static Template* fullPage( const QString& paperId );
-
// From equivalent part number
- static Template* fromEquiv( const QString& brand,
- const QString& part,
- const QString& equivPart );
+ static Template fromEquiv( const QString& brand,
+ const QString& part,
+ const QString& equivPart );
+ static QString brandPartToName( const QString& brand,
+ const QString& part );
+
+ bool isNull() const;
QString brand() const;
QString part() const;
QString description() const;
- QString paperDescription( const Units& units ) const;
+ QString paperDescription( Units units ) const;
QString paperId() const;
Distance pageWidth() const;
Distance pageHeight() const;
@@ -83,7 +85,11 @@ namespace glabels
bool isSizeOther() const;
bool isRoll() const;
+ QString fileName() const;
+ void setFileName( const QString& fileName );
+
bool isUserDefined() const;
+ void setIsUserDefined( bool isUserDefined );
QString equivPart() const;
void setEquivPart( const QString& value );
@@ -94,39 +100,42 @@ namespace glabels
QString name() const;
void addCategory( const QString& categoryId );
- void addFrame( Frame* frame );
+ void addFrame( const Frame& frame );
- const QList& frames() const;
+ const Frame* frame( const QString& id = "0" ) const;
bool operator==( const Template& other ) const;
bool hasCategory( const QString& categoryId ) const;
- bool isSimilarTo( const Template* other ) const;
+ bool isSimilarTo( const Template& other ) const;
+
+ bool setH( Distance h );
private:
- QString mBrand;
- QString mPart;
- QString mDescription;
+ QString mBrand;
+ QString mPart;
+ QString mDescription;
- QString mPaperId;
- Distance mPageWidth;
- Distance mPageHeight;
- Distance mRollWidth;
+ QString mPaperId;
+ Distance mPageWidth;
+ Distance mPageHeight;
+ Distance mRollWidth;
- bool mIsSizeIso{ false };
- bool mIsSizeUs{ false };
- bool mIsRoll{ false };
+ bool mIsSizeIso{ false };
+ bool mIsSizeUs{ false };
+ bool mIsRoll{ false };
- bool mIsUserDefined{ false };
+ QString mFileName;
+ bool mIsUserDefined{ false };
- QString mEquivPart;
- QString mName;
+ QString mEquivPart;
+ QString mName;
QString mProductUrl;
QStringList mCategoryIds;
- QList mFrames;
+ std::unique_ptr mFrame; // TODO: support multiple frames mapped by ID
};
}
diff --git a/model/TextNode.cpp b/model/TextNode.cpp
index 9adf314..fab8754 100644
--- a/model/TextNode.cpp
+++ b/model/TextNode.cpp
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see .
*/
+
#include "TextNode.h"
@@ -105,25 +106,25 @@ namespace glabels
///
/// Get text, expand if necessary
///
- QString TextNode::text( const merge::Record* record,
- const Variables* variables ) const
+ QString TextNode::text( const merge::Record& record,
+ const Variables& variables ) const
{
QString value("");
- bool haveRecordField = mIsField && record &&
- record->contains(mData) &&
- !record->value(mData).isEmpty();
- bool haveVariable = mIsField && variables &&
- variables->contains(mData) &&
- !(*variables)[mData].value().isEmpty();
+ bool haveRecordField = mIsField &&
+ record.contains(mData) &&
+ !record.value(mData).isEmpty();
+ bool haveVariable = mIsField &&
+ variables.contains(mData) &&
+ !variables[mData].value().isEmpty();
if ( haveRecordField )
{
- value = record->value(mData);
+ value = record.value(mData);
}
else if ( haveVariable )
{
- value = (*variables)[mData].value();
+ value = variables[mData].value();
}
else if ( !mIsField )
{
diff --git a/model/TextNode.h b/model/TextNode.h
index f67dcf9..e545c26 100644
--- a/model/TextNode.h
+++ b/model/TextNode.h
@@ -77,8 +77,8 @@ namespace glabels
/////////////////////////////////
// Misc. Methods
/////////////////////////////////
- QString text( const merge::Record* record,
- const Variables* variables ) const;
+ QString text( const merge::Record& record,
+ const Variables& variables ) const;
/////////////////////////////////
diff --git a/model/Variables.cpp b/model/Variables.cpp
index 7c338fc..401da56 100644
--- a/model/Variables.cpp
+++ b/model/Variables.cpp
@@ -30,18 +30,22 @@ namespace glabels
///
/// Copy constructor
///
- Variables::Variables( const Variables* variables )
- : QMap(*variables)
+ Variables::Variables( const Variables& other )
+ : QMap(other)
{
}
///
- /// Clone
+ /// Copy contents from other
///
- Variables* Variables::clone() const
+ void Variables::copy( const Variables& other )
{
- return new Variables( this );
+ clear();
+ for ( const auto& v : other )
+ {
+ insert( v.name(), v );
+ }
}
diff --git a/model/Variables.h b/model/Variables.h
index 4ef50f1..0244c3f 100644
--- a/model/Variables.h
+++ b/model/Variables.h
@@ -46,13 +46,13 @@ namespace glabels
/////////////////////////////////
public:
Variables() = default;
- Variables( const Variables* variables );
+ Variables( const Variables& other );
/////////////////////////////////
- // Object duplication
+ // Copy from other object
/////////////////////////////////
- Variables* clone() const;
+ void copy( const Variables& other );
/////////////////////////////////
diff --git a/model/Vendor.cpp b/model/Vendor.cpp
index d787cd7..9849190 100644
--- a/model/Vendor.cpp
+++ b/model/Vendor.cpp
@@ -26,7 +26,9 @@ namespace glabels
namespace model
{
- Vendor::Vendor( const QString &name, const QString &url ) : mName(name), mUrl(url)
+ Vendor::Vendor( const QString &name, const QString &url )
+ : mName(name),
+ mUrl(url)
{
// empty
}
diff --git a/model/Vendor.h b/model/Vendor.h
index 416862f..ad606e5 100644
--- a/model/Vendor.h
+++ b/model/Vendor.h
@@ -33,7 +33,9 @@ namespace glabels
class Vendor
{
public:
+ Vendor() = default;
Vendor( const QString &name, const QString &url );
+ ~Vendor() = default;
QString name() const;
QString url() const;
diff --git a/model/Version.h.in b/model/Version.h.in
index a61fdb1..6a33e99 100644
--- a/model/Version.h.in
+++ b/model/Version.h.in
@@ -29,6 +29,10 @@ namespace glabels
namespace Version
{
+ const QString ORGANIZATION_NAME = "@ORGANIZATION_NAME@";
+ const QString ORGANIZATION_DOMAIN = "@ORGANIZATION_DOMAIN@";
+ const QString APPLICATION_NAME = "@APPLICATION_NAME@";
+
const QString WEBSITE = "http://@WEBSITE@";
const QString BUG_WEBSITE = "@BUG_WEBSITE@";
diff --git a/model/XmlCategoryParser.cpp b/model/XmlCategoryParser.cpp
index bb59654..af6118e 100644
--- a/model/XmlCategoryParser.cpp
+++ b/model/XmlCategoryParser.cpp
@@ -18,10 +18,9 @@
* along with gLabels-qt. If not, see .
*/
+
#include "XmlCategoryParser.h"
-#include "Category.h"
-#include "Db.h"
#include "XmlUtil.h"
#include
@@ -35,7 +34,7 @@ namespace glabels
namespace model
{
- bool XmlCategoryParser::readFile( const QString &fileName )
+ QList XmlCategoryParser::readFile( const QString &fileName )
{
QFile file( fileName );
@@ -43,7 +42,7 @@ namespace glabels
{
qWarning() << "Error: Cannot read file " << fileName
<< ": " << file.errorString();
- return false;
+ return QList(); // Empty list
}
@@ -57,28 +56,29 @@ namespace glabels
qWarning() << "Error: Parse error at line " << errorLine
<< "column " << errorColumn
<< ": " << errorString;
- return false;
+ return QList(); // Empty list
}
QDomElement root = doc.documentElement();
if ( root.tagName() != "Glabels-categories" )
{
qWarning() << "Error: Not a Glabels-categories file.";
- return false;
+ return QList(); // Empty list
}
- parseRootNode( root );
- return true;
+ return parseRootNode( root );
}
- void XmlCategoryParser::parseRootNode( const QDomElement &node )
+ QList XmlCategoryParser::parseRootNode( const QDomElement &node )
{
+ QList list;
+
for ( QDomNode child = node.firstChild(); !child.isNull(); child = child.nextSibling() )
{
if ( child.toElement().tagName() == "Category" )
{
- parseCategoryNode( child.toElement() );
+ list.push_back( parseCategoryNode( child.toElement() ) );
}
else if ( !child.isComment() )
{
@@ -87,19 +87,17 @@ namespace glabels
<< ", Ignored.";
}
}
+
+ return list;
}
- void XmlCategoryParser::parseCategoryNode( const QDomElement &node )
+ Category XmlCategoryParser::parseCategoryNode( const QDomElement &node )
{
QString id = XmlUtil::getStringAttr( node, "id", "" );
QString name = XmlUtil::getI18nAttr( node, "name", "" );
- auto *category = new Category( id, name );
- if ( category != nullptr )
- {
- Db::registerCategory( category );
- }
+ return Category( id, name );
}
diff --git a/model/XmlCategoryParser.h b/model/XmlCategoryParser.h
index e64a70d..4a3dc5b 100644
--- a/model/XmlCategoryParser.h
+++ b/model/XmlCategoryParser.h
@@ -22,7 +22,10 @@
#define model_XmlCategoryParser_h
+#include "Category.h"
+
#include
+#include
#include