Pointer cleanup (#242)

- Made greater use of smart pointers, eliminating many instances of manual memory management
- Do not use pointers at all for many non-polymorphic classes
- Assorted other code cleanup
This commit is contained in:
Jaye Evins
2025-10-31 16:11:28 -04:00
committed by GitHub
parent fd10d88be5
commit 8c8e447336
159 changed files with 3364 additions and 4045 deletions
+5
View File
@@ -139,3 +139,8 @@ jobs:
if: startsWith( matrix.os, 'macos-' ) if: startsWith( matrix.os, 'macos-' )
working-directory: ${{ steps.strings.outputs.build-output-dir }} working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: ctest --build-config ${{ matrix.build_type }} run: ctest --build-config ${{ matrix.build_type }}
# - name: Tmate
# uses: mxschmitt/action-tmate@v3
# if: failure()
+4
View File
@@ -14,6 +14,10 @@ set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/"
#======================================= #=======================================
# Version Information # Version Information
#======================================= #=======================================
set (ORGANIZATION_NAME "glabels.org")
set (ORGANIZATION_DOMAIN "glabels.org")
set (APPLICATION_NAME "glabels-qt")
set (WEBSITE "glabels.org") set (WEBSITE "glabels.org")
set (BUG_WEBSITE "https://github.com/j-evins/glabels-qt/issues") set (BUG_WEBSITE "https://github.com/j-evins/glabels-qt/issues")
+19 -58
View File
@@ -18,9 +18,8 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Merge.h"
#include "Record.h" #include "Merge.h"
namespace glabels namespace glabels
@@ -31,25 +30,11 @@ namespace glabels
/// ///
/// Constructor /// 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; mSource = source;
// Clear out any old records // Clear out any old records
foreach ( Record* record, mRecordList )
{
delete record;
}
mRecordList.clear(); mRecordList.clear();
open(); 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(); close();
@@ -99,32 +80,12 @@ namespace glabels
/// ///
/// Get record list /// Get record list
/// ///
const QList<Record*>& Merge::recordList( ) const const QList<Record>& Merge::recordList( ) const
{ {
return mRecordList; 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 /// Select/unselect i'th record
/// ///
@@ -132,7 +93,7 @@ namespace glabels
{ {
if ( (i >= 0) && (i < mRecordList.size()) ) if ( (i >= 0) && (i < mRecordList.size()) )
{ {
mRecordList[i]->setSelected( state ); mRecordList[i].setSelected( state );
emit selectionChanged(); emit selectionChanged();
} }
} }
@@ -143,9 +104,9 @@ namespace glabels
/// ///
void Merge::selectAll() void Merge::selectAll()
{ {
foreach ( Record* record, mRecordList ) for ( auto& record : mRecordList )
{ {
record->setSelected( true ); record.setSelected( true );
} }
emit selectionChanged(); emit selectionChanged();
} }
@@ -156,9 +117,9 @@ namespace glabels
/// ///
void Merge::unselectAll() void Merge::unselectAll()
{ {
foreach ( Record* record, mRecordList ) for ( auto& record : mRecordList )
{ {
record->setSelected( false ); record.setSelected( false );
} }
emit selectionChanged(); emit selectionChanged();
} }
@@ -171,9 +132,9 @@ namespace glabels
{ {
int count = 0; int count = 0;
foreach ( Record* record, mRecordList ) for ( const auto& record : mRecordList )
{ {
if ( record->isSelected() ) if ( record.isSelected() )
{ {
count++; count++;
} }
@@ -186,13 +147,13 @@ namespace glabels
/// ///
/// Return list of selected records /// Return list of selected records
/// ///
const QList<Record*> Merge::selectedRecords() const const QList<Record> Merge::selectedRecords() const
{ {
QList<Record*> list; QList<Record> list;
foreach ( Record* record, mRecordList ) for ( const auto& record : mRecordList )
{ {
if ( record->isSelected() ) if ( record.isSelected() )
{ {
list.append( record ); list.append( record );
} }
+9 -9
View File
@@ -22,6 +22,8 @@
#define merge_Merge_h #define merge_Merge_h
#include "Record.h"
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
@@ -52,7 +54,7 @@ namespace glabels
Merge() = default; Merge() = default;
Merge( const Merge* merge ); Merge( const Merge* merge );
public: public:
~Merge() override; virtual ~Merge() = default;
///////////////////////////////// /////////////////////////////////
@@ -69,21 +71,19 @@ namespace glabels
QString source() const; QString source() const;
void setSource( const QString& source ); void setSource( const QString& source );
const QList<Record*>& recordList( ) const; const QList<Record>& recordList( ) const;
///////////////////////////////// /////////////////////////////////
// Selection methods // Selection methods
///////////////////////////////// /////////////////////////////////
public: public:
void select( Record* record );
void unselect( Record* record );
void setSelected( int i, bool state = true ); void setSelected( int i, bool state = true );
void selectAll(); void selectAll();
void unselectAll(); void unselectAll();
int nSelectedRecords() const; int nSelectedRecords() const;
const QList<Record*> selectedRecords() const; const QList<Record> selectedRecords() const;
///////////////////////////////// /////////////////////////////////
@@ -95,7 +95,7 @@ namespace glabels
protected: protected:
virtual void open() = 0; virtual void open() = 0;
virtual void close() = 0; virtual void close() = 0;
virtual Record* readNextRecord() = 0; virtual Record readNextRecord() = 0;
///////////////////////////////// /////////////////////////////////
@@ -110,10 +110,10 @@ namespace glabels
// Private data // Private data
///////////////////////////////// /////////////////////////////////
protected: protected:
QString mId; QString mId;
private: private:
QString mSource; QString mSource;
QList<Record*> mRecordList; QList<Record> mRecordList;
}; };
} }
+2 -2
View File
@@ -108,9 +108,9 @@ namespace glabels
/// ///
/// Read next record /// Read next record
/// ///
Record* None::readNextRecord() Record None::readNextRecord()
{ {
return nullptr; return NullRecord();
} }
} // namespace merge } // namespace merge
+2 -2
View File
@@ -41,7 +41,7 @@ namespace glabels
public: public:
None(); None();
None( const None* merge ); None( const None* merge );
~None() override = default; virtual ~None() = default;
///////////////////////////////// /////////////////////////////////
@@ -67,7 +67,7 @@ namespace glabels
protected: protected:
void open() override; void open() override;
void close() override; void close() override;
Record* readNextRecord() override; Record readNextRecord() override;
}; };
-26
View File
@@ -26,32 +26,6 @@ namespace glabels
namespace merge namespace merge
{ {
///
/// Constructor
///
Record::Record() : mSelected( true )
{
}
///
/// Constructor
///
Record::Record( const Record* record )
: QMap<QString,QString>(*record), mSelected(record->mSelected)
{
}
///
/// Clone
///
Record* Record::clone() const
{
return new Record( this );
}
/// ///
/// Is record selected? /// Is record selected?
/// ///
+3 -15
View File
@@ -37,20 +37,6 @@ namespace glabels
class Record : public QMap<QString,QString> class Record : public QMap<QString,QString>
{ {
/////////////////////////////////
// Life Cycle
/////////////////////////////////
public:
Record();
Record( const Record* record );
/////////////////////////////////
// Object duplication
/////////////////////////////////
Record* clone() const;
///////////////////////////////// /////////////////////////////////
// Properties // Properties
///////////////////////////////// /////////////////////////////////
@@ -63,10 +49,12 @@ namespace glabels
// Private data // Private data
///////////////////////////////// /////////////////////////////////
private: private:
bool mSelected; bool mSelected{ true };
}; };
using NullRecord = const Record;
} }
} }
+15 -8
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Text.h" #include "Text.h"
#include "Record.h" #include "Record.h"
@@ -34,7 +35,10 @@ namespace glabels
/// Constructor /// Constructor
/// ///
Text::Text( QChar delimiter, bool line1HasKeys ) 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 ) Text::Text( const Text* merge )
: Merge( merge ), : Merge( merge ),
mDelimeter(merge->mDelimeter), mLine1HasKeys(merge->mLine1HasKeys), mDelimeter(merge->mDelimeter),
mKeys(merge->mKeys), mNFieldsMax(merge->mNFieldsMax) mLine1HasKeys(merge->mLine1HasKeys),
mKeys(merge->mKeys),
mNFieldsMax(merge->mNFieldsMax)
{ {
} }
@@ -115,24 +121,25 @@ namespace glabels
/// ///
/// Read next record /// Read next record
/// ///
Record* Text::readNextRecord() Record Text::readNextRecord()
{ {
QStringList values = parseLine(); QStringList values = parseLine();
if ( !values.isEmpty() ) if ( !values.isEmpty() )
{ {
auto* record = new Record(); Record record;
int iField = 0; int iField = 0;
foreach ( QString value, values ) for ( const auto& value : values )
{ {
(*record)[ keyFromIndex(iField) ] = value; record[ keyFromIndex(iField) ] = value;
iField++; iField++;
} }
mNFieldsMax = std::max( mNFieldsMax, iField ); mNFieldsMax = std::max( mNFieldsMax, iField );
return record; return record;
} }
return nullptr;
return NullRecord();
} }
+3 -2
View File
@@ -21,6 +21,7 @@
#ifndef merge_Text_h #ifndef merge_Text_h
#define merge_Text_h #define merge_Text_h
#include "Merge.h" #include "Merge.h"
#include <QFile> #include <QFile>
@@ -43,7 +44,7 @@ namespace glabels
protected: protected:
Text( QChar delimiter, bool line1HasKeys ); Text( QChar delimiter, bool line1HasKeys );
Text( const Text* merge ); Text( const Text* merge );
~Text() override = default; virtual ~Text() = default;
///////////////////////////////// /////////////////////////////////
@@ -55,7 +56,7 @@ namespace glabels
protected: protected:
void open() override; void open() override;
void close() override; void close() override;
Record* readNextRecord() override; Record readNextRecord() override;
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -42,7 +42,7 @@ namespace glabels
private: private:
TextColon(); TextColon();
TextColon( const TextColon* merge ); TextColon( const TextColon* merge );
~TextColon() override = default; virtual ~TextColon() = default;
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -42,7 +42,7 @@ namespace glabels
private: private:
TextColonKeys(); TextColonKeys();
TextColonKeys( const TextColonKeys* merge ); TextColonKeys( const TextColonKeys* merge );
~TextColonKeys() override = default; virtual ~TextColonKeys() = default;
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -42,7 +42,7 @@ namespace glabels
private: private:
TextCsv(); TextCsv();
TextCsv( const TextCsv* merge ); TextCsv( const TextCsv* merge );
~TextCsv() override = default; virtual ~TextCsv() = default;
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -42,7 +42,7 @@ namespace glabels
private: private:
TextCsvKeys(); TextCsvKeys();
TextCsvKeys( const TextCsvKeys* merge ); TextCsvKeys( const TextCsvKeys* merge );
~TextCsvKeys() override = default; virtual ~TextCsvKeys() = default;
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -42,7 +42,7 @@ namespace glabels
private: private:
TextSemicolon(); TextSemicolon();
TextSemicolon( const TextSemicolon* merge ); TextSemicolon( const TextSemicolon* merge );
~TextSemicolon() override = default; virtual ~TextSemicolon() = default;
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -42,7 +42,7 @@ namespace glabels
private: private:
TextSemicolonKeys(); TextSemicolonKeys();
TextSemicolonKeys( const TextSemicolonKeys* merge ); TextSemicolonKeys( const TextSemicolonKeys* merge );
~TextSemicolonKeys() override = default; virtual ~TextSemicolonKeys() = default;
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -42,7 +42,7 @@ namespace glabels
private: private:
TextTsv(); TextTsv();
TextTsv( const TextTsv* merge ); TextTsv( const TextTsv* merge );
~TextTsv() override = default; virtual ~TextTsv() = default;
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -42,7 +42,7 @@ namespace glabels
private: private:
TextTsvKeys(); TextTsvKeys();
TextTsvKeys( const TextTsvKeys* merge ); TextTsvKeys( const TextTsvKeys* merge );
~TextTsvKeys() override = default; virtual ~TextTsvKeys() = default;
///////////////////////////////// /////////////////////////////////
+1 -2
View File
@@ -22,7 +22,6 @@
#include "model/Db.h" #include "model/Db.h"
#include "model/Model.h" #include "model/Model.h"
#include "model/PageRenderer.h" #include "model/PageRenderer.h"
#include "model/Settings.h"
#include "model/Version.h" #include "model/Version.h"
#include "model/XmlLabelParser.h" #include "model/XmlLabelParser.h"
@@ -188,7 +187,7 @@ int main( int argc, char **argv )
glabels::model::Model *model = glabels::model::XmlLabelParser::readFile( filename ); glabels::model::Model *model = glabels::model::XmlLabelParser::readFile( filename );
if ( model ) if ( model )
{ {
model->variables()->setVariables( variableDefinitions ); model->variables().setVariables( variableDefinitions );
QPrinter printer( QPrinter::HighResolution ); QPrinter printer( QPrinter::HighResolution );
printer.setColorMode( QPrinter::Color ); printer.setColorMode( QPrinter::Color );
+1 -1
View File
@@ -129,7 +129,7 @@ namespace glabels
void ColorButton::setKeys( const merge::Merge* merge, void ColorButton::setKeys( const merge::Merge* merge,
const model::Variables* variables ) const model::Variables& variables )
{ {
mDialog->setKeys( merge, variables ); mDialog->setKeys( merge, variables );
} }
+1 -1
View File
@@ -69,7 +69,7 @@ namespace glabels
model::ColorNode colorNode(); model::ColorNode colorNode();
void setKeys( const merge::Merge* merge, void setKeys( const merge::Merge* merge,
const model::Variables* variables ); const model::Variables& variables );
///////////////////////////////// /////////////////////////////////
+1 -1
View File
@@ -197,7 +197,7 @@ namespace glabels
void ColorPaletteDialog::setKeys( const merge::Merge* merge, void ColorPaletteDialog::setKeys( const merge::Merge* merge,
const model::Variables* variables ) const model::Variables& variables )
{ {
if (mFieldButton) if (mFieldButton)
{ {
+1 -1
View File
@@ -67,7 +67,7 @@ namespace glabels
void setColorNode( const model::ColorNode& colorNode ); void setColorNode( const model::ColorNode& colorNode );
void setKeys( const merge::Merge* merge, void setKeys( const merge::Merge* merge,
const model::Variables* variables ); const model::Variables& variables );
///////////////////////////////// /////////////////////////////////
+4 -4
View File
@@ -44,7 +44,7 @@ namespace glabels
/// Set Keys /// Set Keys
/// ///
void FieldButton::setKeys( const merge::Merge* merge, void FieldButton::setKeys( const merge::Merge* merge,
const model::Variables* variables ) const model::Variables& variables )
{ {
// Clear old keys // Clear old keys
mMenu.clear(); mMenu.clear();
@@ -64,18 +64,18 @@ namespace glabels
// Add variable keys, if any // Add variable keys, if any
mMenu.addSection( tr("Variables") ); mMenu.addSection( tr("Variables") );
for ( auto& key : variables->keys() ) for ( auto& key : variables.keys() )
{ {
auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) ); auto* action = mMenu.addAction( QString( "${%1}" ).arg( key ) );
action->setData( key ); action->setData( key );
} }
if ( variables->keys().empty() ) if ( variables.keys().empty() )
{ {
auto* action = mMenu.addAction( "None" ); auto* action = mMenu.addAction( "None" );
action->setEnabled( false ); action->setEnabled( false );
} }
setEnabled( !merge->keys().empty() || !variables->keys().empty() ); setEnabled( !merge->keys().empty() || !variables.keys().empty() );
} }
+1 -1
View File
@@ -60,7 +60,7 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
public: public:
void setKeys( const merge::Merge* merge, void setKeys( const merge::Merge* merge,
const model::Variables* variables ); const model::Variables& variables );
///////////////////////////////// /////////////////////////////////
+3 -3
View File
@@ -52,14 +52,14 @@ namespace glabels
SelectProductDialog dialog; SelectProductDialog dialog;
dialog.exec(); dialog.exec();
const model::Template* tmplate = dialog.tmplate(); auto tmplate = dialog.tmplate();
if ( tmplate ) if ( !tmplate.isNull() )
{ {
auto* model = new model::Model(); auto* model = new model::Model();
model->setTmplate( tmplate ); model->setTmplate( tmplate );
// Intelligently decide to rotate label by default // 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->setRotate( frame->h() > frame->w() );
model->clearModified(); model->clearModified();
+23 -23
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "LabelEditor.h" #include "LabelEditor.h"
#include "Cursors.h" #include "Cursors.h"
@@ -38,10 +39,10 @@
#include "model/Markup.h" #include "model/Markup.h"
#include "model/Settings.h" #include "model/Settings.h"
#include <QDebug>
#include <QMimeData> #include <QMimeData>
#include <QMouseEvent> #include <QMouseEvent>
#include <QtMath> #include <QtMath>
#include <QtDebug>
namespace glabels namespace glabels
@@ -95,12 +96,12 @@ namespace glabels
mState = IdleState; mState = IdleState;
mSelectRegionVisible = false; mSelectRegionVisible = false;
mResizeObject = nullptr; mResizeObject = nullptr;
mResizeHandle = nullptr; mResizeHandleLocation = model::Handle::NULL_HANDLE;
mResizeHonorAspect = false; mResizeHonorAspect = false;
mCreateObjectType = Box; mCreateObjectType = Box;
mCreateObject = nullptr; mCreateObject = nullptr;
setMouseTracking( true ); setMouseTracking( true );
setFocusPolicy(Qt::StrongFocus); setFocusPolicy(Qt::StrongFocus);
@@ -459,15 +460,15 @@ namespace glabels
case IdleState: case IdleState:
{ {
model::ModelObject* object = nullptr; model::ModelObject* object = nullptr;
model::Handle* handle = nullptr; auto& handle = mModel->handleAt( mScale, xWorld, yWorld );
if ( mModel->isSelectionAtomic() &&
(handle = mModel->handleAt( mScale, xWorld, yWorld )) != nullptr ) if ( mModel->isSelectionAtomic() && !handle.isNull() )
{ {
// //
// Start an object resize // Start an object resize
// //
mResizeObject = handle->owner(); mResizeObject = handle.owner();
mResizeHandle = handle; mResizeHandleLocation = handle.location();
mResizeHonorAspect = event->modifiers() & Qt::ControlModifier; mResizeHonorAspect = event->modifiers() & Qt::ControlModifier;
if ( mResizeObject->lockAspectRatio() ) if ( mResizeObject->lockAspectRatio() )
{ {
@@ -632,7 +633,7 @@ namespace glabels
case IdleState: case IdleState:
if ( mModel->isSelectionAtomic() && if ( mModel->isSelectionAtomic() &&
mModel->handleAt( mScale, xWorld, yWorld ) ) !mModel->handleAt( mScale, xWorld, yWorld ).isNull() )
{ {
setCursor( Qt::CrossCursor ); setCursor( Qt::CrossCursor );
} }
@@ -796,11 +797,10 @@ namespace glabels
/// Handle resize motion /// Handle resize motion
/// ///
void void
LabelEditor::handleResizeMotion( const model::Distance& xWorld, LabelEditor::handleResizeMotion( model::Distance xWorld,
const model::Distance& yWorld ) model::Distance yWorld )
{ {
QPointF p( xWorld.pt(), yWorld.pt() ); QPointF p( xWorld.pt(), yWorld.pt() );
model::Handle::Location location = mResizeHandle->location();
/* /*
* Change point to object relative coordinates * Change point to object relative coordinates
@@ -824,7 +824,7 @@ namespace glabels
* Calculate new size * Calculate new size
*/ */
double w, h; double w, h;
switch ( location ) switch ( mResizeHandleLocation )
{ {
case model::Handle::NW: case model::Handle::NW:
w = std::max( x2 - p.x(), 0.0 ); w = std::max( x2 - p.x(), 0.0 );
@@ -879,11 +879,11 @@ namespace glabels
/* /*
* Set size * Set size
*/ */
if ( !(location == model::Handle::P1) && !(location == model::Handle::P2) ) if ( !(mResizeHandleLocation == model::Handle::P1) && !(mResizeHandleLocation == model::Handle::P2) )
{ {
if ( mResizeHonorAspect ) if ( mResizeHonorAspect )
{ {
switch ( location ) switch ( mResizeHandleLocation )
{ {
case model::Handle::E: case model::Handle::E:
case model::Handle::W: case model::Handle::W:
@@ -908,7 +908,7 @@ namespace glabels
/* /*
* Adjust origin, if needed. * Adjust origin, if needed.
*/ */
switch ( location ) switch ( mResizeHandleLocation )
{ {
case model::Handle::NW: case model::Handle::NW:
x0 += x2 - mResizeObject->w().pt(); x0 += x2 - mResizeObject->w().pt();
@@ -1227,9 +1227,9 @@ namespace glabels
painter->translate( -mModel->frame()->w().pt(), 0 ); 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(); painter->restore();
@@ -1243,7 +1243,7 @@ namespace glabels
void void
LabelEditor::drawObjectsLayer( QPainter* painter ) LabelEditor::drawObjectsLayer( QPainter* painter )
{ {
mModel->draw( painter, true, nullptr, nullptr ); mModel->draw( painter, true, merge::NullRecord(), model::Variables() );
} }
+6 -6
View File
@@ -22,7 +22,7 @@
#define LabelEditor_h #define LabelEditor_h
#include "model/Handles.h" #include "model/Handle.h"
#include "model/Model.h" #include "model/Model.h"
#include "model/ModelObject.h" #include "model/ModelObject.h"
#include "model/Region.h" #include "model/Region.h"
@@ -135,8 +135,8 @@ namespace glabels
// Private methods // Private methods
///////////////////////////////////// /////////////////////////////////////
private: private:
void handleResizeMotion( const model::Distance& xWorld, void handleResizeMotion( model::Distance xWorld,
const model::Distance& yWorld ); model::Distance yWorld );
void drawBgLayer( QPainter* painter ); void drawBgLayer( QPainter* painter );
void drawGridLayer( QPainter* painter ); void drawGridLayer( QPainter* painter );
@@ -205,9 +205,9 @@ namespace glabels
model::Distance mMoveLastY; model::Distance mMoveLastY;
/* ArrowResize state */ /* ArrowResize state */
model::ModelObject* mResizeObject; model::ModelObject* mResizeObject;
model::Handle* mResizeHandle; model::Handle::Location mResizeHandleLocation;
bool mResizeHonorAspect; bool mResizeHonorAspect;
/* CreateDrag state */ /* CreateDrag state */
CreateType mCreateObjectType; CreateType mCreateObjectType;
+17 -36
View File
@@ -29,7 +29,6 @@
#include "PrintView.h" #include "PrintView.h"
#include "PropertiesView.h" #include "PropertiesView.h"
#include "StartupView.h" #include "StartupView.h"
#include "UndoRedoModel.h"
#include "VariablesView.h" #include "VariablesView.h"
#include "model/Db.h" #include "model/Db.h"
@@ -63,7 +62,7 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
MainWindow::MainWindow() : mModel(nullptr), mUndoRedoModel(nullptr) MainWindow::MainWindow()
{ {
setWindowIcon( QIcon::fromTheme( "glabels" ) ); 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 /// Get model accessor
/// ///
model::Model* MainWindow::model() const model::Model* MainWindow::model() const
{ {
return mModel; return mModel.get();
} }
@@ -236,15 +217,15 @@ namespace glabels
/// ///
void MainWindow::setModel( model::Model* model ) void MainWindow::setModel( model::Model* model )
{ {
mModel = model; // Ownership passes to us mModel.reset( model );
mUndoRedoModel = new UndoRedoModel( mModel ); mUndoRedoModel = std::make_unique<UndoRedoModel>( mModel.get() );
mPropertiesView->setModel( mModel, mUndoRedoModel ); mPropertiesView->setModel( mModel.get(), mUndoRedoModel.get() );
mLabelEditor->setModel( mModel, mUndoRedoModel ); mLabelEditor->setModel( mModel.get(), mUndoRedoModel.get() );
mObjectEditor->setModel( mModel, mUndoRedoModel ); mObjectEditor->setModel( mModel.get(), mUndoRedoModel.get() );
mMergeView->setModel( mModel, mUndoRedoModel ); mMergeView->setModel( mModel.get(), mUndoRedoModel.get() );
mVariablesView->setModel( mModel, mUndoRedoModel ); mVariablesView->setModel( mModel.get(), mUndoRedoModel.get() );
mPrintView->setModel( mModel ); mPrintView->setModel( mModel.get() );
mEditorButton->setChecked( true ); mEditorButton->setChecked( true );
mPages->setCurrentIndex( EDITOR_PAGE_INDEX ); mPages->setCurrentIndex( EDITOR_PAGE_INDEX );
@@ -253,11 +234,11 @@ namespace glabels
setTitle(); setTitle();
connect( mLabelEditor, SIGNAL(contextMenuActivate(model::Point)), this, SLOT(onContextMenuActivate(model::Point)) ); connect( mLabelEditor, SIGNAL(contextMenuActivate(model::Point)), this, SLOT(onContextMenuActivate(model::Point)) );
connect( mModel, SIGNAL(nameChanged()), this, SLOT(onNameChanged()) ); connect( mModel.get(), SIGNAL(nameChanged()), this, SLOT(onNameChanged()) );
connect( mModel, SIGNAL(modifiedChanged()), this, SLOT(onModifiedChanged()) ); connect( mModel.get(), SIGNAL(modifiedChanged()), this, SLOT(onModifiedChanged()) );
connect( mModel, SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()) ); connect( mModel.get(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()) );
connect( mModel, SIGNAL(changed()), this, SLOT(onLabelChanged()) ); connect( mModel.get(), SIGNAL(changed()), this, SLOT(onLabelChanged()) );
connect( mUndoRedoModel, SIGNAL(changed()), this, SLOT(onUndoRedoChanged()) ); connect( mUndoRedoModel.get(), SIGNAL(changed()), this, SLOT(onUndoRedoChanged()) );
} }
@@ -266,7 +247,7 @@ namespace glabels
/// ///
bool MainWindow::isEmpty() const bool MainWindow::isEmpty() const
{ {
return mModel == nullptr; return !mModel;
} }
@@ -1032,7 +1013,7 @@ namespace glabels
/// ///
void MainWindow::setTitle() void MainWindow::setTitle()
{ {
if ( mModel == nullptr ) if ( !mModel )
{ {
setWindowTitle( "gLabels" ); setWindowTitle( "gLabels" );
} }
+15 -5
View File
@@ -21,6 +21,9 @@
#ifndef MainWindow_h #ifndef MainWindow_h
#define MainWindow_h #define MainWindow_h
#include "UndoRedoModel.h"
#include <model/Model.h> #include <model/Model.h>
#include <QAction> #include <QAction>
@@ -35,6 +38,8 @@
#include <QToolBar> #include <QToolBar>
#include <QToolButton> #include <QToolButton>
#include <memory>
namespace glabels namespace glabels
{ {
@@ -46,7 +51,6 @@ namespace glabels
class PrintView; class PrintView;
class PropertiesView; class PropertiesView;
class StartupView; class StartupView;
class UndoRedoModel;
class VariablesView; class VariablesView;
@@ -63,7 +67,7 @@ namespace glabels
///////////////////////////////////// /////////////////////////////////////
public: public:
MainWindow(); MainWindow();
~MainWindow() override; virtual ~MainWindow() = default;
///////////////////////////////////// /////////////////////////////////////
@@ -194,8 +198,17 @@ namespace glabels
///////////////////////////////////// /////////////////////////////////////
// Private Data // Private Data
// owned and managed by us
///////////////////////////////////// /////////////////////////////////////
private: private:
std::unique_ptr<model::Model> mModel;
std::unique_ptr<UndoRedoModel> mUndoRedoModel;
/////////////////////////////////////
// Private Data
// owned by QMainWindow
/////////////////////////////////////
QMenu* fileMenu; QMenu* fileMenu;
QMenu* fileRecentMenu; QMenu* fileRecentMenu;
QMenu* editMenu; QMenu* editMenu;
@@ -219,9 +232,6 @@ namespace glabels
QToolBar* fileToolBar; QToolBar* fileToolBar;
QToolBar* editorToolBar; QToolBar* editorToolBar;
model::Model* mModel;
UndoRedoModel* mUndoRedoModel;
QToolBar* mContents; QToolBar* mContents;
QToolButton* mWelcomeButton; QToolButton* mWelcomeButton;
QToolButton* mEditorButton; QToolButton* mEditorButton;
+13 -21
View File
@@ -18,15 +18,16 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "MergeView.h" #include "MergeView.h"
#include "merge/Factory.h" #include "merge/Factory.h"
#include "model/FileUtil.h" #include "model/FileUtil.h"
#include <QDebug>
#include <QFileDialog> #include <QFileDialog>
#include <QFileInfo> #include <QFileInfo>
#include <QtDebug>
namespace glabels namespace glabels
@@ -48,15 +49,6 @@ namespace glabels
} }
///
/// Destructor
///
MergeView::~MergeView()
{
// empty
}
/// ///
/// Set Model /// Set Model
/// ///
@@ -144,13 +136,13 @@ namespace glabels
{ {
mBlock = true; // Don't recurse mBlock = true; // Don't recurse
const QList<merge::Record*>& records = mModel->merge()->recordList(); auto& records = mModel->merge()->recordList();
int iRow = 0; int iRow = 0;
foreach ( merge::Record* record, records ) for ( auto& record : records )
{ {
QTableWidgetItem* item = recordsTable->item( iRow, 0 ); QTableWidgetItem* item = recordsTable->item( iRow, 0 );
item->setCheckState( record->isSelected() ? Qt::Checked : Qt::Unchecked ); item->setCheckState( record.isSelected() ? Qt::Checked : Qt::Unchecked );
iRow++; iRow++;
} }
@@ -274,33 +266,33 @@ namespace glabels
{ {
mBlock = true; mBlock = true;
const QList<merge::Record*>& records = merge->recordList(); auto& records = merge->recordList();
recordsTable->setRowCount( records.size() ); recordsTable->setRowCount( records.size() );
int iRow = 0; int iRow = 0;
foreach ( merge::Record* record, records ) for ( auto record : records )
{ {
// First column for primary field // First column for primary field
auto* item = new QTableWidgetItem(); 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->setText( text );
} }
item->setFlags( Qt::ItemIsEnabled | Qt::ItemIsUserCheckable ); 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->setItem( iRow, 0, item );
recordsTable->resizeColumnToContents( 0 ); recordsTable->resizeColumnToContents( 0 );
// Starting on 2nd column, 1 column per field, skip primary field // Starting on 2nd column, 1 column per field, skip primary field
int iCol = 1; int iCol = 1;
foreach ( QString key, mKeys ) for ( auto& key : mKeys )
{ {
if ( key != mPrimaryKey ) 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 ); auto* item = new QTableWidgetItem( text );
item->setFlags( Qt::ItemIsEnabled ); item->setFlags( Qt::ItemIsEnabled );
recordsTable->setItem( iRow, iCol, item ); recordsTable->setItem( iRow, iCol, item );
+1 -1
View File
@@ -49,7 +49,7 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
public: public:
MergeView( QWidget *parent = nullptr ); MergeView( QWidget *parent = nullptr );
~MergeView() override; virtual ~MergeView() = default;
///////////////////////////////// /////////////////////////////////
+14 -16
View File
@@ -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 ) : QPixmap( width, height )
{ {
draw( tmplate, 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 ); fill( Qt::transparent );
@@ -66,11 +66,11 @@ namespace glabels
painter.setRenderHint( QPainter::Antialiasing, true ); painter.setRenderHint( QPainter::Antialiasing, true );
// For "Roll" templates, allow extra room for tape width and continuation break lines // For "Roll" templates, allow extra room for tape width and continuation break lines
model::Distance drawWidth = tmplate->pageWidth(); model::Distance drawWidth = tmplate.pageWidth();
model::Distance drawHeight = tmplate->pageHeight(); model::Distance drawHeight = tmplate.pageHeight();
if ( tmplate->isRoll() ) if ( tmplate.isRoll() )
{ {
drawWidth = tmplate->rollWidth(); drawWidth = tmplate.rollWidth();
drawHeight *= 1.2; drawHeight *= 1.2;
} }
@@ -87,8 +87,8 @@ namespace glabels
} }
painter.scale( scale, scale ); painter.scale( scale, scale );
model::Distance xOffset = ( model::Distance::pt(width/scale) - tmplate->pageWidth() ) / 2; model::Distance xOffset = ( model::Distance::pt(width/scale) - tmplate.pageWidth() ) / 2;
model::Distance yOffset = ( model::Distance::pt(height/scale) - tmplate->pageHeight() ) / 2; model::Distance yOffset = ( model::Distance::pt(height/scale) - tmplate.pageHeight() ) / 2;
painter.translate( xOffset.pt(), yOffset.pt() ); painter.translate( xOffset.pt(), yOffset.pt() );
drawPaper( painter, tmplate, scale ); 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 ); QBrush brush( paperColor );
QPen pen( paperOutlineColor ); QPen pen( paperOutlineColor );
@@ -107,9 +107,9 @@ namespace glabels
painter.setBrush( brush ); painter.setBrush( brush );
painter.setPen( pen ); 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 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 ); QBrush brush( labelColor );
QPen pen( labelOutlineColor ); QPen pen( labelOutlineColor );
@@ -131,10 +131,8 @@ namespace glabels
painter.setBrush( brush ); painter.setBrush( brush );
painter.setPen( pen ); painter.setPen( pen );
model::Frame *frame = tmplate->frames().first(); auto frame = tmplate.frame();
QVector<model::Point> origins = frame->getOrigins(); for ( model::Point p0 : frame->getOrigins() )
foreach ( model::Point p0, origins )
{ {
drawLabelOutline( painter, frame, p0 ); drawLabelOutline( painter, frame, p0 );
} }
+4 -4
View File
@@ -39,13 +39,13 @@ namespace glabels
public: public:
MiniPreviewPixmap(); MiniPreviewPixmap();
MiniPreviewPixmap( const model::Template* tmplate, int width, int height ); MiniPreviewPixmap( const model::Template& tmplate, int width, int height );
private: private:
void draw( const model::Template* tmplate, int width, int height ); void draw( const model::Template& tmplate, int width, int height );
void drawPaper( QPainter& painter, const model::Template* tmplate, double scale ); void drawPaper( QPainter& painter, const model::Template& tmplate, double scale );
void drawLabelOutlines( 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 ); void drawLabelOutline( QPainter& painter, const model::Frame *frame, const model::Point& point0 );
}; };
+23 -15
View File
@@ -97,18 +97,18 @@ namespace glabels
auto tmplate = mModel->tmplate(); auto tmplate = mModel->tmplate();
// For "Roll" templates, allow extra room to draw continuation break lines. // 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; model::Distance drawOffset = 0;
if ( tmplate->isRoll() ) if ( tmplate.isRoll() )
{ {
drawHeight = 1.2 * tmplate->pageHeight(); drawHeight = 1.2 * tmplate.pageHeight();
drawOffset = 0.1 * tmplate->pageHeight(); drawOffset = 0.1 * tmplate.pageHeight();
} }
// Set scene up with a 5% margin around paper // 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 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; model::Distance h = 1.10 * drawHeight;
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() ); 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 ); QBrush brush( labelNumberColor );
model::Frame *frame = mModel->tmplate()->frames().first(); auto frame = mModel->tmplate().frame();
model::Distance w = frame->w(); model::Distance w = frame->w();
model::Distance h = frame->h(); model::Distance h = frame->h();
@@ -143,18 +147,20 @@ namespace glabels
mScene->addItem( labelNumberItem ); mScene->addItem( labelNumberItem );
} }
void Preview::drawLabelNumberOverlay() void Preview::drawLabelNumberOverlay()
{ {
model::Frame *frame = mModel->tmplate()->frames().first(); auto frame = mModel->tmplate().frame();
auto i = 0; auto i = 0;
foreach (model::Point origin, frame->getOrigins() ) for ( model::Point origin : frame->getOrigins() )
{ {
i++; i++;
drawLabelNumberOverlaySingle( origin.x(), origin.y(), frame->path(), i); drawLabelNumberOverlaySingle( origin.x(), origin.y(), frame->path(), i);
} }
} }
/// ///
/// Resize Event Handler /// Resize Event Handler
/// ///
@@ -181,9 +187,9 @@ namespace glabels
QAbstractGraphicsShapeItem* pageItem; QAbstractGraphicsShapeItem* pageItem;
auto tmplate = mModel->tmplate(); 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 else
{ {
@@ -202,9 +208,9 @@ namespace glabels
/// ///
void Preview::drawLabels() 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() ); drawLabel( origin.x(), origin.y(), frame->path() );
} }
@@ -214,7 +220,9 @@ namespace glabels
/// ///
/// Draw a Single Label at x,y /// 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 ); QBrush brush( labelColor );
QPen pen( labelOutlineColor ); QPen pen( labelOutlineColor );
+7 -2
View File
@@ -70,11 +70,16 @@ namespace glabels
private: private:
void drawPaper(); void drawPaper();
void drawLabels(); 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 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(); void drawLabelNumberOverlay();
+22 -31
View File
@@ -60,15 +60,6 @@ namespace glabels
} }
///
/// Destructor
///
PropertiesView::~PropertiesView()
{
// empty
}
/// ///
/// Set Model /// Set Model
/// ///
@@ -101,41 +92,41 @@ namespace glabels
/// ///
void PropertiesView::onLabelSizeChanged() void PropertiesView::onLabelSizeChanged()
{ {
auto* tmplate = mModel->tmplate(); auto tmplate = mModel->tmplate();
auto* frame = tmplate->frames().first(); auto frame = tmplate.frame();
bool isRotated = mModel->rotate(); bool isRotated = mModel->rotate();
preview->setTemplate( tmplate ); preview->setTemplate( tmplate );
preview->setShowArrow( true ); preview->setShowArrow( true );
preview->setRotate( isRotated ); preview->setRotate( isRotated );
const model::Vendor* vendor = model::Db::lookupVendorFromName( tmplate->brand() ); vendorLabel->setText( tmplate.brand() );
if ( (vendor != nullptr) && (vendor->url() != nullptr) ) if ( model::Db::isVendorNameKnown( tmplate.brand() ) )
{ {
QString markup = QString( "<a href='%1'>%2</a>" ).arg( vendor->url(), vendor->name() ); auto vendor = model::Db::lookupVendorFromName( tmplate.brand() );
vendorLabel->setText( markup ); if ( !vendor.url().isEmpty() )
} {
else QString markup = QString( "<a href='%1'>%2</a>" ).arg( vendor.url(), vendor.name() );
{ vendorLabel->setText( markup );
vendorLabel->setText( tmplate->brand() ); }
} }
if ( tmplate->productUrl() != nullptr ) if ( !tmplate.productUrl().isEmpty() )
{ {
QString markup = QString( "<a href='%1'>%2</a>" ).arg( tmplate->productUrl(), tmplate->part() ); QString markup = QString( "<a href='%1'>%2</a>" ).arg( tmplate.productUrl(), tmplate.part() );
partLabel->setText( markup ); partLabel->setText( markup );
} }
else else
{ {
partLabel->setText( tmplate->part() ); partLabel->setText( tmplate.part() );
} }
descriptionLabel->setText( tmplate->description() ); descriptionLabel->setText( tmplate.description() );
pageSizeLabel->setText( tmplate->paperDescription( mUnits ) ); pageSizeLabel->setText( tmplate.paperDescription( mUnits ) );
labelSizeLabel->setText( frame->sizeDescription( mUnits ) ); labelSizeLabel->setText( frame->sizeDescription( mUnits ) );
layoutLabel->setText( frame->layoutDescription() ); layoutLabel->setText( frame->layoutDescription() );
QStringList list = model::Db::getNameListOfSimilarTemplates( tmplate->name() ); QStringList list = model::Db::getNameListOfSimilarTemplates( tmplate.name() );
if ( list.isEmpty() ) if ( list.isEmpty() )
{ {
similarProductsGroupBox->hide(); similarProductsGroupBox->hide();
@@ -208,8 +199,8 @@ namespace glabels
/// ///
void PropertiesView::onOrientationActivated() void PropertiesView::onOrientationActivated()
{ {
const model::Template* tmplate = mModel->tmplate(); auto tmplate = mModel->tmplate();
const model::Frame* frame = tmplate->frames().first(); auto frame = tmplate.frame();
// Make sure index actually changed. // Make sure index actually changed.
int index = orientationCombo->currentIndex(); int index = orientationCombo->currentIndex();
@@ -243,15 +234,15 @@ namespace glabels
SelectProductDialog selectProductDialog( this ); SelectProductDialog selectProductDialog( this );
selectProductDialog.exec(); selectProductDialog.exec();
const model::Template* tmplate = selectProductDialog.tmplate(); auto tmplate = selectProductDialog.tmplate();
if ( tmplate ) if ( !tmplate.isNull() )
{ {
mUndoRedoModel->checkpoint( tr("Change Product") ); mUndoRedoModel->checkpoint( tr("Change Product") );
mModel->setTmplate( tmplate ); mModel->setTmplate( tmplate );
// Don't rotate circular or round labels // Don't rotate circular or round labels
const model::Frame *frame = tmplate->frames().first(); auto frame = tmplate.frame();
if ( frame->w() == frame->h() ) if ( frame->w() == frame->h() )
{ {
mModel->setRotate( false ); mModel->setRotate( false );
+1 -1
View File
@@ -48,7 +48,7 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
public: public:
PropertiesView( QWidget *parent = nullptr ); PropertiesView( QWidget *parent = nullptr );
~PropertiesView() override; virtual ~PropertiesView() = default;
///////////////////////////////// /////////////////////////////////
+5 -5
View File
@@ -29,16 +29,16 @@ namespace glabels
/// ///
/// Constructor /// 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."; qWarning() << "Not a \"Roll\" template type.";
} }
model::Distance x0 = (tmplate->pageWidth() - tmplate->rollWidth()) / 2.0; model::Distance x0 = (tmplate.pageWidth() - tmplate.rollWidth()) / 2.0;
model::Distance w = tmplate->rollWidth(); model::Distance w = tmplate.rollWidth();
model::Distance h = tmplate->pageHeight(); model::Distance h = tmplate.pageHeight();
model::Distance c = 0.07*h; model::Distance c = 0.07*h;
model::Distance b = 0.03*h; model::Distance b = 0.03*h;
+1 -1
View File
@@ -39,7 +39,7 @@ namespace glabels
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
RollTemplatePath( const model::Template* tmplate ); RollTemplatePath( const model::Template& tmplate );
}; };
+24 -24
View File
@@ -52,15 +52,15 @@ namespace glabels
categoriesCheckContainer->setEnabled( !model::Settings::searchAllCategories() ); categoriesCheckContainer->setEnabled( !model::Settings::searchAllCategories() );
mCategoryIdList = model::Settings::searchCategoryList(); mCategoryIdList = model::Settings::searchCategoryList();
QList<model::Category*> categories = model::Db::categories(); auto categories = model::Db::categories();
foreach ( model::Category *category, categories ) for ( auto& category : categories )
{ {
QCheckBox* check = new QCheckBox( category->name() ); QCheckBox* check = new QCheckBox( category.name() );
check->setChecked( mCategoryIdList.contains( category->id() ) ); check->setChecked( mCategoryIdList.contains( category.id() ) );
categoriesLayout->addWidget( check ); categoriesLayout->addWidget( check );
mCheckList.append( check ); mCheckList.append( check );
mCheckToCategoryMap[check] = category->id(); mCheckToCategoryMap[check] = category.id();
connect( check, SIGNAL(clicked()), this, SLOT(onCategoryCheckClicked()) ); connect( check, SIGNAL(clicked()), this, SLOT(onCategoryCheckClicked()) );
} }
@@ -78,7 +78,7 @@ namespace glabels
viewModeButton->setToolTip( tr( "Grid View" ) ); viewModeButton->setToolTip( tr( "Grid View" ) );
} }
QList<model::Template*> tmplates = model::Db::templates(); auto tmplates = model::Db::templates();
templatePicker->setTemplates( tmplates ); templatePicker->setTemplates( tmplates );
if ( model::Settings::recentTemplateList().count() > 0 ) if ( model::Settings::recentTemplateList().count() > 0 )
@@ -93,7 +93,7 @@ namespace glabels
/// ///
/// Get selected template /// Get selected template
/// ///
const model::Template* SelectProductDialog::tmplate() const model::Template SelectProductDialog::tmplate() const
{ {
if ( mHasSelection ) if ( mHasSelection )
{ {
@@ -101,7 +101,7 @@ namespace glabels
} }
else else
{ {
return nullptr; return model::Template();
} }
} }
@@ -229,41 +229,41 @@ namespace glabels
/// ///
void SelectProductDialog::onTemplatePickerSelectionChanged() void SelectProductDialog::onTemplatePickerSelectionChanged()
{ {
auto* tmplate = templatePicker->selectedTemplate(); auto tmplate = templatePicker->selectedTemplate();
if ( !tmplate ) if ( tmplate.isNull() )
{ {
productInfoWidget->setVisible( false ); productInfoWidget->setVisible( false );
selectButton->setEnabled( false ); selectButton->setEnabled( false );
return; return;
} }
auto* frame = tmplate->frames().first(); auto frame = tmplate.frame();
preview->setTemplate( tmplate ); preview->setTemplate( tmplate );
const model::Vendor* vendor = model::Db::lookupVendorFromName( tmplate->brand() ); vendorLabel->setText( tmplate.brand() );
if ( (vendor != nullptr) && (vendor->url() != nullptr) ) if ( model::Db::isVendorNameKnown( tmplate.brand() ) )
{ {
QString markup = QString( "<a href='%1'>%2</a>" ).arg( vendor->url(), vendor->name() ); auto vendor = model::Db::lookupVendorFromName( tmplate.brand() );
vendorLabel->setText( markup ); if ( !vendor.url().isEmpty() )
} {
else QString markup = QString( "<a href='%1'>%2</a>" ).arg( vendor.url(), vendor.name() );
{ vendorLabel->setText( markup );
vendorLabel->setText( tmplate->brand() ); }
} }
if ( tmplate->productUrl() != nullptr ) if ( !tmplate.productUrl().isEmpty() )
{ {
QString markup = QString( "<a href='%1'>%2</a>" ).arg( tmplate->productUrl(), tmplate->part() ); QString markup = QString( "<a href='%1'>%2</a>" ).arg( tmplate.productUrl(), tmplate.part() );
partLabel->setText( markup ); partLabel->setText( markup );
} }
else else
{ {
partLabel->setText( tmplate->part() ); partLabel->setText( tmplate.part() );
} }
descriptionLabel->setText( tmplate->description() ); descriptionLabel->setText( tmplate.description() );
pageSizeLabel->setText( tmplate->paperDescription( model::Settings::units() ) ); pageSizeLabel->setText( tmplate.paperDescription( model::Settings::units() ) );
labelSizeLabel->setText( frame->sizeDescription( model::Settings::units() ) ); labelSizeLabel->setText( frame->sizeDescription( model::Settings::units() ) );
layoutLabel->setText( frame->layoutDescription() ); layoutLabel->setText( frame->layoutDescription() );
+1 -1
View File
@@ -46,7 +46,7 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
// Accessors // Accessors
///////////////////////////////// /////////////////////////////////
const model::Template* tmplate() const; model::Template tmplate() const;
///////////////////////////////// /////////////////////////////////
+16 -16
View File
@@ -78,7 +78,7 @@ namespace glabels
/// ///
/// Template Property Setter /// Template Property Setter
/// ///
void SimplePreview::setTemplate( const model::Template *tmplate ) void SimplePreview::setTemplate( const model::Template& tmplate )
{ {
mTmplate = tmplate; mTmplate = tmplate;
update(); update();
@@ -121,21 +121,21 @@ namespace glabels
{ {
mScene->clear(); mScene->clear();
if ( mTmplate != nullptr ) if ( !mTmplate.isNull() )
{ {
// For "Roll" templates, allow extra room to draw continuation break lines. // 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; model::Distance drawOffset = 0;
if ( mTmplate->isRoll() ) if ( mTmplate.isRoll() )
{ {
drawHeight = 1.2 * mTmplate->pageHeight(); drawHeight = 1.2 * mTmplate.pageHeight();
drawOffset = 0.1 * mTmplate->pageHeight(); drawOffset = 0.1 * mTmplate.pageHeight();
} }
// Set scene up with a 5% margin around paper // 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 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; model::Distance h = 1.10 * drawHeight;
mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() ); mScene->setSceneRect( x.pt(), y.pt(), w.pt(), h.pt() );
@@ -167,9 +167,9 @@ namespace glabels
pen.setWidthF( paperOutlineWidthPixels ); pen.setWidthF( paperOutlineWidthPixels );
QAbstractGraphicsShapeItem* pageItem; 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 else
{ {
@@ -188,9 +188,9 @@ namespace glabels
/// ///
void SimplePreview::drawLabels() 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() ); drawLabel( origin.x(), origin.y(), frame->path() );
} }
@@ -200,9 +200,9 @@ namespace glabels
/// ///
/// Draw a Single Label at x,y /// Draw a Single Label at x,y
/// ///
void SimplePreview::drawLabel( const model::Distance& x, void SimplePreview::drawLabel( model::Distance x,
const model::Distance& y, model::Distance y,
const QPainterPath& path ) const QPainterPath& path )
{ {
QBrush brush( labelColor ); QBrush brush( labelColor );
QPen pen( labelOutlineColor ); QPen pen( labelOutlineColor );
@@ -223,7 +223,7 @@ namespace glabels
/// ///
void SimplePreview::drawArrow() void SimplePreview::drawArrow()
{ {
model::Frame *frame = mTmplate->frames().first(); auto frame = mTmplate.frame();
model::Distance w = frame->w(); model::Distance w = frame->w();
model::Distance h = frame->h(); model::Distance h = frame->h();
+8 -6
View File
@@ -51,7 +51,7 @@ namespace glabels
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
void setTemplate( const model::Template *tmplate ); void setTemplate( const model::Template& tmplate );
void setShowArrow( bool showArrow ); void setShowArrow( bool showArrow );
void setRotate( bool rotateFlag ); void setRotate( bool rotateFlag );
@@ -70,7 +70,9 @@ namespace glabels
void update(); void update();
void drawPaper(); void drawPaper();
void drawLabels(); 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(); void drawArrow();
@@ -78,11 +80,11 @@ namespace glabels
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
const model::Template* mTmplate { nullptr }; model::Template mTmplate;
bool mShowArrow { false }; bool mShowArrow { false };
bool mRotateFlag { false }; bool mRotateFlag { false };
QGraphicsScene* mScene { nullptr }; QGraphicsScene* mScene { nullptr };
}; };
+78 -58
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "TemplateDesigner.h" #include "TemplateDesigner.h"
#include "SelectProductDialog.h" #include "SelectProductDialog.h"
@@ -34,14 +35,16 @@
#include "model/PageRenderer.h" #include "model/PageRenderer.h"
#include "model/Settings.h" #include "model/Settings.h"
#include <QDebug>
#include <QMessageBox> #include <QMessageBox>
#include <QPrintDialog> #include <QPrintDialog>
#include <QPrinter> #include <QPrinter>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QtDebug>
#include <algorithm> #include <algorithm>
#include <iostream> #include <iostream>
#include <iterator>
namespace glabels namespace glabels
{ {
@@ -367,7 +370,7 @@ namespace glabels
/// ///
/// Build template from wizard pages /// Build template from wizard pages
/// ///
model::Template* TemplateDesigner::buildTemplate() model::Template TemplateDesigner::buildTemplate()
{ {
model::Units units = model::Settings::units(); model::Units units = model::Settings::units();
@@ -379,9 +382,8 @@ namespace glabels
model::Distance pageH( field( "pageSize.h" ).toDouble(), units ); model::Distance pageH( field( "pageSize.h" ).toDouble(), units );
model::Distance pageRollW( field( "pageSize.rollW" ).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() ) if ( field( "shape.rect" ).toBool() )
{ {
model::Distance w( field( "rect.w" ).toDouble(), units ); model::Distance w( field( "rect.w" ).toDouble(), units );
@@ -392,8 +394,10 @@ namespace glabels
model::Distance xMargin( field( "rect.xMargin" ).toDouble(), units ); model::Distance xMargin( field( "rect.xMargin" ).toDouble(), units );
model::Distance yMargin( field( "rect.yMargin" ).toDouble(), units ); model::Distance yMargin( field( "rect.yMargin" ).toDouble(), units );
frame = new model::FrameRect( w, h, r, xWaste, yWaste ); model::FrameRect frame( w, h, r, xWaste, yWaste );
frame->addMarkup( new model::MarkupMargin( xMargin, yMargin ) ); frame.addMarkup( model::MarkupMargin( xMargin, yMargin ) );
addLayouts( frame );
t.addFrame( frame );
} }
else if ( field( "shape.round" ).toBool() ) else if ( field( "shape.round" ).toBool() )
{ {
@@ -401,8 +405,10 @@ namespace glabels
model::Distance waste( field( "round.waste" ).toDouble(), units ); model::Distance waste( field( "round.waste" ).toDouble(), units );
model::Distance margin( field( "round.margin" ).toDouble(), units ); model::Distance margin( field( "round.margin" ).toDouble(), units );
frame = new model::FrameRound( r, waste ); model::FrameRound frame( r, waste );
frame->addMarkup( new model::MarkupMargin( margin ) ); frame.addMarkup( model::MarkupMargin( margin ) );
addLayouts( frame );
t.addFrame( frame );
} }
else if ( field( "shape.ellipse" ).toBool() ) else if ( field( "shape.ellipse" ).toBool() )
{ {
@@ -411,8 +417,10 @@ namespace glabels
model::Distance waste( field( "ellipse.waste" ).toDouble(), units ); model::Distance waste( field( "ellipse.waste" ).toDouble(), units );
model::Distance margin( field( "ellipse.margin" ).toDouble(), units ); model::Distance margin( field( "ellipse.margin" ).toDouble(), units );
frame = new model::FrameEllipse( w, h, waste ); model::FrameEllipse frame( w, h, waste );
frame->addMarkup( new model::MarkupMargin( margin ) ); frame.addMarkup( model::MarkupMargin( margin ) );
addLayouts( frame );
t.addFrame( frame );
} }
else else
{ {
@@ -423,10 +431,22 @@ namespace glabels
model::Distance waste( field( "cd.waste" ).toDouble(), units ); model::Distance waste( field( "cd.waste" ).toDouble(), units );
model::Distance margin( field( "cd.margin" ).toDouble(), units ); model::Distance margin( field( "cd.margin" ).toDouble(), units );
frame = new model::FrameCd( r1, r2, xClip, yClip, waste ); model::FrameCd frame( r1, r2, xClip, yClip, waste );
frame->addMarkup( new model::MarkupMargin( margin ) ); 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() ) if ( field( "nLayouts.one" ).toBool() )
{ {
@@ -437,7 +457,7 @@ namespace glabels
model::Distance dx( field( "oneLayout.dx" ).toDouble(), units ); model::Distance dx( field( "oneLayout.dx" ).toDouble(), units );
model::Distance dy( field( "oneLayout.dy" ).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 else
{ {
@@ -455,11 +475,9 @@ namespace glabels
model::Distance dx2( field( "twoLayout.dx2" ).toDouble(), units ); model::Distance dx2( field( "twoLayout.dx2" ).toDouble(), units );
model::Distance dy2( field( "twoLayout.dy2" ).toDouble(), units ); model::Distance dy2( field( "twoLayout.dy2" ).toDouble(), units );
frame->addLayout( model::Layout( nx1, ny1, x01, y01, dx1, dy1 ) ); frame.addLayout( model::Layout( nx1, ny1, x01, y01, dx1, dy1 ) );
frame->addLayout( model::Layout( nx2, ny2, x02, y02, dx2, dy2 ) ); frame.addLayout( model::Layout( nx2, ny2, x02, y02, dx2, dy2 ) );
} }
return t;
} }
@@ -498,22 +516,22 @@ namespace glabels
/// ///
/// Load wizard from template /// Load wizard from template
/// ///
void TemplateDesigner::loadFromTemplate( const model::Template* tmplate ) void TemplateDesigner::loadFromTemplate( const model::Template& tmplate )
{ {
mIsBasedOnCopy = true; mIsBasedOnCopy = true;
model::Units units = model::Settings::units(); model::Units units = model::Settings::units();
setField( "name.brand", tmplate->brand() ); setField( "name.brand", tmplate.brand() );
setField( "name.part", tmplate->part() + QString(" (%1)").arg( tr("Copy") ) ); setField( "name.part", tmplate.part() + QString(" (%1)").arg( tr("Copy") ) );
setField( "name.description", tmplate->description() ); setField( "name.description", tmplate.description() );
setField( "pageSize.pageSize", model::Db::lookupPaperNameFromId( tmplate->paperId() ) ); setField( "pageSize.pageSize", model::Db::lookupPaperNameFromId( tmplate.paperId() ) );
setField( "pageSize.w", tmplate->pageWidth().inUnits( units ) ); setField( "pageSize.w", tmplate.pageWidth().inUnits( units ) );
setField( "pageSize.h", tmplate->pageHeight().inUnits( units ) ); setField( "pageSize.h", tmplate.pageHeight().inUnits( units ) );
setField( "pageSize.rollW", tmplate->rollWidth().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<const model::FrameRect*>( frame ) ) if ( auto frameRect = dynamic_cast<const model::FrameRect*>( frame ) )
{ {
setField( "shape.rect", true ); setField( "shape.rect", true );
@@ -550,9 +568,9 @@ namespace glabels
setField( "cd.waste", frameCd->waste().inUnits( units ) ); setField( "cd.waste", frameCd->waste().inUnits( units ) );
} }
foreach( auto markup, frame->markups() ) for( auto& markup : frame->markups() )
{ {
if ( auto markupMargin = dynamic_cast<const model::MarkupMargin*>( markup ) ) if ( auto markupMargin = dynamic_cast<const model::MarkupMargin*>( markup.get() ) )
{ {
setField( "rect.xMargin", markupMargin->xSize().inUnits( units ) ); setField( "rect.xMargin", markupMargin->xSize().inUnits( units ) );
setField( "rect.yMargin", markupMargin->ySize().inUnits( units ) ); setField( "rect.yMargin", markupMargin->ySize().inUnits( units ) );
@@ -565,28 +583,30 @@ namespace glabels
auto layouts = frame->layouts(); auto layouts = frame->layouts();
if ( layouts.size() == 1 ) if ( layouts.size() == 1 )
{ {
setField( "oneLayout.nx", layouts[0].nx() ); setField( "oneLayout.nx", layouts.front().nx() );
setField( "oneLayout.ny", layouts[0].ny() ); setField( "oneLayout.ny", layouts.front().ny() );
setField( "oneLayout.x0", layouts[0].x0().inUnits( units ) ); setField( "oneLayout.x0", layouts.front().x0().inUnits( units ) );
setField( "oneLayout.y0", layouts[0].y0().inUnits( units ) ); setField( "oneLayout.y0", layouts.front().y0().inUnits( units ) );
setField( "oneLayout.dx", layouts[0].dx().inUnits( units ) ); setField( "oneLayout.dx", layouts.front().dx().inUnits( units ) );
setField( "oneLayout.dy", layouts[0].dy().inUnits( units ) ); setField( "oneLayout.dy", layouts.front().dy().inUnits( units ) );
} }
else if ( layouts.size() > 1 ) else if ( layouts.size() > 1 )
{ {
setField( "twoLayout.nx1", layouts[0].nx() ); auto it = layouts.begin();
setField( "twoLayout.ny1", layouts[0].ny() ); setField( "twoLayout.nx1", it->nx() );
setField( "twoLayout.x01", layouts[0].x0().inUnits( units ) ); setField( "twoLayout.ny1", it->ny() );
setField( "twoLayout.y01", layouts[0].y0().inUnits( units ) ); setField( "twoLayout.x01", it->x0().inUnits( units ) );
setField( "twoLayout.dx1", layouts[0].dx().inUnits( units ) ); setField( "twoLayout.y01", it->y0().inUnits( units ) );
setField( "twoLayout.dy1", layouts[0].dy().inUnits( units ) ); setField( "twoLayout.dx1", it->dx().inUnits( units ) );
setField( "twoLayout.dy1", it->dy().inUnits( units ) );
setField( "twoLayout.nx2", layouts[1].nx() ); std::advance( it, 1 );
setField( "twoLayout.ny2", layouts[1].ny() ); setField( "twoLayout.nx2", it->nx() );
setField( "twoLayout.x02", layouts[1].x0().inUnits( units ) ); setField( "twoLayout.ny2", it->ny() );
setField( "twoLayout.y02", layouts[1].y0().inUnits( units ) ); setField( "twoLayout.x02", it->x0().inUnits( units ) );
setField( "twoLayout.dx2", layouts[1].dx().inUnits( units ) ); setField( "twoLayout.y02", it->y0().inUnits( units ) );
setField( "twoLayout.dy2", layouts[1].dy().inUnits( units ) ); setField( "twoLayout.dx2", it->dx().inUnits( units ) );
setField( "twoLayout.dy2", it->dy().inUnits( units ) );
} }
} }
@@ -633,16 +653,16 @@ namespace glabels
SelectProductDialog dialog; SelectProductDialog dialog;
dialog.exec(); dialog.exec();
const model::Template* tmplate = dialog.tmplate(); auto tmplate = dialog.tmplate();
if ( tmplate ) if ( !tmplate.isNull() )
{ {
if ( auto td = dynamic_cast<TemplateDesigner*>( wizard() ) ) if ( auto td = dynamic_cast<TemplateDesigner*>( wizard() ) )
{ {
if ( dynamic_cast<model::FramePath*>(tmplate->frames().constFirst()) ) if ( dynamic_cast<const model::FramePath*>(tmplate.frame()) )
{ {
td->mIsTemplatePathBased = true; td->mIsTemplatePathBased = true;
} }
else if ( dynamic_cast<model::FrameContinuous*>(tmplate->frames().constFirst()) ) else if ( dynamic_cast<const model::FrameContinuous*>(tmplate.frame()) )
{ {
td->mIsTemplateContinuousBased = true; td->mIsTemplateContinuousBased = true;
} }
@@ -753,9 +773,9 @@ namespace glabels
if ( pageSizeCombo->currentText() != tr("Other") ) if ( pageSizeCombo->currentText() != tr("Other") )
{ {
const model::Paper* paper = model::Db::lookupPaperFromName( pageSizeCombo->currentText() ); auto paper = model::Db::lookupPaperFromName( pageSizeCombo->currentText() );
wSpin->setValue( paper->width().inUnits( model::Settings::units() ) ); wSpin->setValue( paper.width().inUnits( model::Settings::units() ) );
hSpin->setValue( paper->height().inUnits( model::Settings::units() ) ); hSpin->setValue( paper.height().inUnits( model::Settings::units() ) );
} }
registerField( "pageSize.pageSize", pageSizeCombo, "currentText" ); registerField( "pageSize.pageSize", pageSizeCombo, "currentText" );
@@ -789,9 +809,9 @@ namespace glabels
if ( !isOther && !isRoll ) if ( !isOther && !isRoll )
{ {
const model::Paper* paper = model::Db::lookupPaperFromName( pageSizeCombo->currentText() ); auto paper = model::Db::lookupPaperFromName( pageSizeCombo->currentText() );
wSpin->setValue( paper->width().inUnits( model::Settings::units() ) ); wSpin->setValue( paper.width().inUnits( model::Settings::units() ) );
hSpin->setValue( paper->height().inUnits( model::Settings::units() ) ); hSpin->setValue( paper.height().inUnits( model::Settings::units() ) );
} }
if ( !isRoll ) if ( !isRoll )
@@ -1553,7 +1573,7 @@ namespace glabels
// //
QString brand = field( "name.brand" ).toString(); QString brand = field( "name.brand" ).toString();
QString part = field( "name.part" ).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) ) if ( QFileInfo::exists(filename) )
{ {
+3 -2
View File
@@ -86,9 +86,10 @@ namespace glabels
double itemHeight(); double itemHeight();
double itemXWaste(); double itemXWaste();
double itemYWaste(); double itemYWaste();
model::Template* buildTemplate(); model::Template buildTemplate();
void addLayouts( model::Frame& frame );
void printTestSheet(); void printTestSheet();
void loadFromTemplate( const model::Template* tmplate ); void loadFromTemplate( const model::Template& tmplate );
bool isBasedOnCopy(); bool isBasedOnCopy();
+10 -10
View File
@@ -112,11 +112,11 @@ namespace glabels
/// ///
/// Set List of Templates to Pick From /// Set List of Templates to Pick From
/// ///
void TemplatePicker::setTemplates( const QList<model::Template*>& tmplates ) void TemplatePicker::setTemplates( const QList<model::Template>& tmplates )
{ {
auto mode = model::Settings::templatePickerMode(); auto mode = model::Settings::templatePickerMode();
foreach (model::Template *tmplate, tmplates) foreach (auto& tmplate, tmplates)
{ {
new TemplatePickerItem( tmplate, mode, this ); new TemplatePickerItem( tmplate, mode, this );
} }
@@ -186,12 +186,12 @@ namespace glabels
{ {
if (auto* tItem = dynamic_cast<TemplatePickerItem *>(item(i))) if (auto* tItem = dynamic_cast<TemplatePickerItem *>(item(i)))
{ {
bool nameMask = tItem->tmplate()->name().contains( searchString, Qt::CaseInsensitive ); bool nameMask = tItem->tmplate().name().contains( searchString, Qt::CaseInsensitive );
bool sizeMask = bool sizeMask =
(isoMask && tItem->tmplate()->isSizeIso()) || (isoMask && tItem->tmplate().isSizeIso()) ||
(usMask && tItem->tmplate()->isSizeUs()) || (usMask && tItem->tmplate().isSizeUs()) ||
(otherMask && tItem->tmplate()->isSizeOther()); (otherMask && tItem->tmplate().isSizeOther());
bool categoryMask; bool categoryMask;
if ( anyCategory ) if ( anyCategory )
@@ -203,7 +203,7 @@ namespace glabels
categoryMask = false; categoryMask = false;
foreach ( QString id, categoryIds ) 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; bool match = false;
foreach ( QString name, names ) foreach ( QString name, names )
{ {
if ( tItem->tmplate()->name() == name ) if ( tItem->tmplate().name() == name )
{ {
match = true; match = true;
break; break;
@@ -268,14 +268,14 @@ namespace glabels
/// ///
/// Get Currently Selected Template /// Get Currently Selected Template
/// ///
const model::Template* TemplatePicker::selectedTemplate() const model::Template TemplatePicker::selectedTemplate() const
{ {
if ( auto* tItem = selectedItem() ) if ( auto* tItem = selectedItem() )
{ {
return tItem->tmplate(); return tItem->tmplate();
} }
return nullptr; return model::Template();
} }
+3 -3
View File
@@ -51,7 +51,7 @@ namespace glabels
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
void setTemplates( const QList<model::Template*>& tmplates ); void setTemplates( const QList<model::Template>& tmplates );
void setMode( QListView::ViewMode mode ); void setMode( QListView::ViewMode mode );
QListView::ViewMode mode() const; QListView::ViewMode mode() const;
@@ -66,8 +66,8 @@ namespace glabels
void applyFilter( const QStringList& names ); void applyFilter( const QStringList& names );
const model::Template* selectedTemplate() const; model::Template selectedTemplate() const;
TemplatePickerItem* selectedItem() const; TemplatePickerItem* selectedItem() const;
}; };
+8 -8
View File
@@ -36,9 +36,9 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
TemplatePickerItem::TemplatePickerItem( model::Template* tmplate, TemplatePickerItem::TemplatePickerItem( const model::Template& tmplate,
QListView::ViewMode mode, QListView::ViewMode mode,
QListWidget* parent ) QListWidget* parent )
: QListWidgetItem( parent ) : QListWidgetItem( parent )
{ {
mTmplate = tmplate; mTmplate = tmplate;
@@ -55,18 +55,18 @@ namespace glabels
/// ///
void TemplatePickerItem::setMode( QListView::ViewMode mode ) void TemplatePickerItem::setMode( QListView::ViewMode mode )
{ {
auto* frame = mTmplate->frames().first(); auto frame = mTmplate.frame();
switch ( mode ) switch ( mode )
{ {
case QListView::IconMode: case QListView::IconMode:
setText( mTmplate->name() ); setText( mTmplate.name() );
break; break;
case QListView::ListMode: case QListView::ListMode:
setText( "<b>" + mTmplate->name() + "</b><br/>" + setText( "<b>" + mTmplate.name() + "</b><br/>" +
mTmplate->description() + "<br/>" + mTmplate.description() + "<br/>" +
frame->sizeDescription( model::Settings::units() ) + "<br/>" + frame->sizeDescription( model::Settings::units() ) + "<br/>" +
frame->layoutDescription() ); frame->layoutDescription() );
break; break;
@@ -82,7 +82,7 @@ namespace glabels
/// ///
/// Template Property Getter /// Template Property Getter
/// ///
const model::Template *TemplatePickerItem::tmplate() const model::Template TemplatePickerItem::tmplate() const
{ {
return mTmplate; return mTmplate;
} }
+5 -5
View File
@@ -44,9 +44,9 @@ namespace glabels
// Life Cycle // Life Cycle
///////////////////////////////// /////////////////////////////////
public: public:
TemplatePickerItem( model::Template* tmplate, TemplatePickerItem( const model::Template& tmplate,
QListView::ViewMode mode, QListView::ViewMode mode,
QListWidget* parent = nullptr ); QListWidget* parent = nullptr );
///////////////////////////////// /////////////////////////////////
@@ -60,14 +60,14 @@ namespace glabels
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
const model::Template *tmplate() const; model::Template tmplate() const;
///////////////////////////////// /////////////////////////////////
// Private Data // Private Data
///////////////////////////////// /////////////////////////////////
private: private:
model::Template *mTmplate; model::Template mTmplate;
}; };
-9
View File
@@ -38,15 +38,6 @@ namespace glabels
} }
///
/// Destructor
///
UndoRedoModel::~UndoRedoModel()
{
// empty
}
/// ///
/// Checkpoint /// Checkpoint
/// ///
+1 -1
View File
@@ -45,7 +45,7 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
public: public:
UndoRedoModel( model::Model* model ); UndoRedoModel( model::Model* model );
~UndoRedoModel() override; virtual ~UndoRedoModel() = default;
///////////////////////////////// /////////////////////////////////
+8 -17
View File
@@ -82,15 +82,6 @@ namespace glabels
} }
///
/// Destructor
///
VariablesView::~VariablesView()
{
// empty
}
/// ///
/// Set Model /// Set Model
/// ///
@@ -132,7 +123,7 @@ namespace glabels
if ( dialog.exec() == QDialog::Accepted ) if ( dialog.exec() == QDialog::Accepted )
{ {
mModel->variables()->addVariable( dialog.variable() ); mModel->variables().addVariable( dialog.variable() );
selectVariable( dialog.variable().name() ); selectVariable( dialog.variable().name() );
} }
} }
@@ -146,9 +137,9 @@ namespace glabels
int iRow = table->selectedItems()[0]->row(); int iRow = table->selectedItems()[0]->row();
QString name = table->item( iRow, I_COL_NAME )->text(); 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 ); EditVariableDialog dialog( this );
dialog.setVariable( v ); dialog.setVariable( v );
@@ -156,7 +147,7 @@ namespace glabels
if ( dialog.exec() == QDialog::Accepted ) if ( dialog.exec() == QDialog::Accepted )
{ {
mModel->variables()->replaceVariable( name, dialog.variable() ); mModel->variables().replaceVariable( name, dialog.variable() );
selectVariable( dialog.variable().name() ); selectVariable( dialog.variable().name() );
} }
} }
@@ -171,7 +162,7 @@ namespace glabels
int iRow = table->selectedItems()[0]->row(); int iRow = table->selectedItems()[0]->row();
QString name = table->item( iRow, I_COL_NAME )->text(); 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() void VariablesView::loadTable()
{ {
table->clearContents(); table->clearContents();
table->setRowCount( mModel->variables()->size() ); table->setRowCount( mModel->variables().size() );
int iRow = 0; int iRow = 0;
for( const auto& v : *mModel->variables() ) for( const auto& v : mModel->variables() )
{ {
auto* typeItem = new QTableWidgetItem( model::Variable::typeToI18nString(v.type()) ); auto* typeItem = new QTableWidgetItem( model::Variable::typeToI18nString(v.type()) );
typeItem->setFlags( typeItem->flags() ^ Qt::ItemIsEditable ); typeItem->setFlags( typeItem->flags() ^ Qt::ItemIsEditable );
@@ -237,7 +228,7 @@ namespace glabels
void VariablesView::selectVariable( const QString& name ) void VariablesView::selectVariable( const QString& name )
{ {
int iRow = 0; int iRow = 0;
for( const auto& v : *mModel->variables() ) for( const auto& v : mModel->variables() )
{ {
if ( v.name() == name ) if ( v.name() == name )
{ {
+1 -1
View File
@@ -47,7 +47,7 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
public: public:
VariablesView( QWidget *parent = nullptr ); VariablesView( QWidget *parent = nullptr );
~VariablesView() override; virtual ~VariablesView() = default;
///////////////////////////////// /////////////////////////////////
+3 -4
View File
@@ -23,7 +23,6 @@
#include "model/FileUtil.h" #include "model/FileUtil.h"
#include "model/Db.h" #include "model/Db.h"
#include "model/Model.h" #include "model/Model.h"
#include "model/Settings.h"
#include "model/Version.h" #include "model/Version.h"
#include "model/XmlLabelParser.h" #include "model/XmlLabelParser.h"
@@ -43,9 +42,9 @@ int main( int argc, char **argv )
{ {
QApplication app( argc, argv ); QApplication app( argc, argv );
QCoreApplication::setOrganizationName( "glabels.org" ); QCoreApplication::setOrganizationName( glabels::model::Version::ORGANIZATION_NAME );
QCoreApplication::setOrganizationDomain( "glabels.org" ); QCoreApplication::setOrganizationDomain( glabels::model::Version::ORGANIZATION_DOMAIN );
QCoreApplication::setApplicationName( "glabels-qt" ); QCoreApplication::setApplicationName( glabels::model::Version::APPLICATION_NAME );
QCoreApplication::setApplicationVersion( glabels::model::Version::LONG_STRING ); QCoreApplication::setApplicationVersion( glabels::model::Version::LONG_STRING );
QIcon::setThemeName( "glabels-flat" ); QIcon::setThemeName( "glabels-flat" );
+1 -1
View File
@@ -31,7 +31,7 @@ set (Model_sources
FramePath.cpp FramePath.cpp
FrameRect.cpp FrameRect.cpp
FrameRound.cpp FrameRound.cpp
Handles.cpp Handle.cpp
Layout.cpp Layout.cpp
Markup.cpp Markup.cpp
Model.cpp Model.cpp
+2 -1
View File
@@ -27,7 +27,8 @@ namespace glabels
{ {
Category::Category( const QString &id, const QString &name ) Category::Category( const QString &id, const QString &name )
: mId(id), mName(name) : mId(id),
mName(name)
{ {
// empty // empty
} }
+2
View File
@@ -34,7 +34,9 @@ namespace glabels
{ {
public: public:
Category() = default;
Category( const QString& id, const QString& name ); Category( const QString& id, const QString& name );
~Category() = default;
QString id() const; QString id() const;
QString name() const; QString name() const;
+11 -12
View File
@@ -18,9 +18,8 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ColorNode.h"
#include "merge/Record.h" #include "ColorNode.h"
namespace glabels namespace glabels
@@ -175,25 +174,25 @@ namespace glabels
/// ///
/// Get color, expand if necessary /// Get color, expand if necessary
/// ///
QColor ColorNode::color( const merge::Record* record, QColor ColorNode::color( const merge::Record& record,
const Variables* variables ) const const Variables& variables ) const
{ {
QColor value = QColor( 192, 192, 192, 128 ); QColor value = QColor( 192, 192, 192, 128 );
bool haveRecordField = mIsField && record && bool haveRecordField = mIsField &&
record->contains(mKey) && record.contains(mKey) &&
!record->value(mKey).isEmpty(); !record.value(mKey).isEmpty();
bool haveVariable = mIsField && variables && bool haveVariable = mIsField &&
variables->contains(mKey) && variables.contains(mKey) &&
!(*variables)[mKey].value().isEmpty(); !variables[mKey].value().isEmpty();
if ( haveRecordField ) if ( haveRecordField )
{ {
value = QColor( record->value(mKey) ); value = QColor( record.value(mKey) );
} }
else if ( haveVariable ) else if ( haveVariable )
{ {
value = QColor( (*variables)[mKey].value() ); value = QColor( variables[mKey].value() );
} }
else if ( !mIsField ) else if ( !mIsField )
{ {
+2 -2
View File
@@ -96,8 +96,8 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
public: public:
uint32_t rgba() const; uint32_t rgba() const;
QColor color( const merge::Record* record, QColor color( const merge::Record& record,
const Variables* variables ) const; const Variables& variables ) const;
///////////////////////////////// /////////////////////////////////
+4 -3
View File
@@ -43,13 +43,14 @@ namespace glabels
TextNode filenameNode = imageObject->filenameNode(); TextNode filenameNode = imageObject->filenameNode();
if ( !filenameNode.isField() ) 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 else
{ {
QByteArray svg = imageObject->svg(); auto& svg = imageObject->svg();
if ( !svg.isEmpty() ) if ( !svg.isEmpty() )
{ {
addSvg( filenameNode.data(), svg ); addSvg( filenameNode.data(), svg );
+303 -331
View File
@@ -30,7 +30,7 @@
#include "XmlTemplateCreator.h" #include "XmlTemplateCreator.h"
#include "XmlVendorParser.h" #include "XmlVendorParser.h"
#include <QtDebug> #include <QDebug>
#include <QtGlobal> #include <QtGlobal>
#include <algorithm> #include <algorithm>
@@ -48,9 +48,9 @@ namespace glabels
{ {
const QString empty = ""; 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 // Static data
// //
QList<Paper*> Db::mPapers; QList<Paper> Db::mPapers;
QStringList Db::mPaperIds; QMap<QString,Paper> Db::mPapersNameMap;
QStringList Db::mPaperNames; QMap<QString,Paper> Db::mPapersIdMap;
QList<Category*> Db::mCategories; QStringList Db::mPaperIds;
QStringList Db::mCategoryIds; QStringList Db::mPaperNames;
QStringList Db::mCategoryNames;
QList<Vendor*> Db::mVendors; QList<Category> Db::mCategories;
QStringList Db::mVendorNames; QMap<QString,Category> Db::mCategoriesNameMap;
QList<Template*> Db::mTemplates; QMap<QString,Category> Db::mCategoriesIdMap;
QStringList Db::mCategoryIds;
QStringList Db::mCategoryNames;
QList<Vendor> Db::mVendors;
QMap<QString,Vendor> Db::mVendorsNameMap;
QStringList Db::mVendorNames;
QList<Template> Db::mTemplates;
QMap<QString,Template> Db::mTemplatesNameMap;
QMap<QString,Template> Db::mUserTemplatesNameMap;
Db::Db() void Db::init()
{ {
readPapers(); readPapers();
readCategories(); readCategories();
@@ -78,20 +89,7 @@ namespace glabels
} }
void Db::init() const QList<Paper>& Db::papers()
{
instance();
}
Db* Db::instance()
{
static auto* db = new Db();
return db;
}
const QList<Paper*>& Db::papers()
{ {
return mPapers; return mPapers;
} }
@@ -109,7 +107,7 @@ namespace glabels
} }
const QList<Category*>& Db::categories() const QList<Category>& Db::categories()
{ {
return mCategories; return mCategories;
} }
@@ -127,7 +125,7 @@ namespace glabels
} }
const QList<Vendor*>& Db::vendors() const QList<Vendor>& Db::vendors()
{ {
return mVendors; return mVendors;
} }
@@ -139,383 +137,251 @@ namespace glabels
} }
const QList<Template*>& Db::templates() QList<Template> 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() ) ) if ( name.isEmpty() )
{
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() )
{ {
qWarning() << "NULL paper name."; 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 *it;
{
return paper;
}
} }
qWarning() << "Unknown paper name: " << name; 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."; qWarning() << "NULL paper id.";
return mPapers.first(); return Paper();
} }
foreach ( Paper *paper, mPapers ) auto it = mPapersIdMap.find( id );
if ( it != mPapersIdMap.end() )
{ {
if ( paper->id() == id ) return *it;
{
return paper;
}
} }
qWarning() << "Unknown paper ID: " << id; qWarning() << "Unknown paper ID: " << id;
return nullptr; return Paper();
} }
QString Db::lookupPaperIdFromName( const QString& name ) QString Db::lookupPaperIdFromName( const QString& name )
{ {
if ( !name.isNull() && !name.isEmpty() ) return lookupPaperFromName( name ).id();
{
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;
} }
QString Db::lookupPaperNameFromId( const QString& id ) QString Db::lookupPaperNameFromId( const QString& id )
{ {
if ( !id.isNull() && !id.isEmpty() ) return lookupPaperFromId( id ).name();
{
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;
} }
bool Db::isPaperIdKnown( const QString& id ) bool Db::isPaperIdKnown( const QString& id )
{ {
foreach ( Paper *paper, mPapers ) return mPapersIdMap.contains( id );
{
if ( paper->id() == id )
{
return true;
}
}
return false;
} }
void Db::registerCategory( Category *category ) const Category Db::lookupCategoryFromName( const QString& name )
{ {
if ( !isCategoryIdKnown( category->id() ) ) if ( name.isEmpty() )
{
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() )
{ {
qWarning() << "NULL category name."; 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 *it;
{
return category;
}
} }
qWarning() << "Unknown category name: \"%s\"." << name; 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."; qWarning() << "NULL category id.";
return mCategories.first(); return Category();
} }
foreach ( Category *category, mCategories ) auto it = mCategoriesIdMap.find( id );
if ( it != mCategoriesIdMap.end() )
{ {
if ( category->id() == id ) return *it;
{
return category;
}
} }
qWarning() << "Unknown category ID: " << id; qWarning() << "Unknown category ID: \"%s\"." << id;
return nullptr; return Category();
} }
QString Db::lookupCategoryIdFromName( const QString& name ) QString Db::lookupCategoryIdFromName( const QString& name )
{ {
if ( !name.isNull() && !name.isEmpty() ) return lookupCategoryFromName( name ).id();
{
const Category *category = lookupCategoryFromName( name );
if ( category != nullptr )
{
return category->id();
}
}
qWarning() << "Unknown category name: " << name;
return empty;
} }
QString Db::lookupCategoryNameFromId( const QString& id ) QString Db::lookupCategoryNameFromId( const QString& id )
{ {
if ( !id.isNull() && !id.isEmpty() ) return lookupCategoryFromId( id ).name();
{
const Category *category = lookupCategoryFromId( id );
if ( category != nullptr )
{
return category->name();
}
}
qWarning() << "Unknown category id: " << id;
return empty;
} }
bool Db::isCategoryIdKnown( const QString& id ) bool Db::isCategoryIdKnown( const QString& id )
{ {
foreach ( Category *category, mCategories ) return mCategoriesIdMap.contains( id );
{
if ( category->id() == id )
{
return true;
}
}
return false;
} }
void Db::registerVendor( Vendor *vendor ) const Vendor Db::lookupVendorFromName( const QString& name )
{ {
if ( !isVendorNameKnown( vendor->name() ) ) if ( name.isEmpty() )
{
mVendors << vendor;
mVendorNames << vendor->name();
}
else
{
qWarning() << "Duplicate vendor name: " << vendor->name();
}
}
const Vendor *Db::lookupVendorFromName( const QString& name )
{
if ( name.isNull() || name.isEmpty() )
{ {
qWarning() << "NULL vendor name."; 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 *it;
{
return vendor;
}
} }
qWarning() << "Unknown vendor name: " << name; qWarning() << "Unknown vendor name: " << name;
return nullptr; return Vendor();
} }
QString Db::lookupVendorUrlFromName( const QString& name ) QString Db::lookupVendorUrlFromName( const QString& name )
{ {
if ( !name.isNull() && !name.isEmpty() ) return lookupVendorFromName( name ).url();
{
const Vendor *vendor = lookupVendorFromName( name );
if ( vendor != nullptr )
{
return vendor->url();
}
}
qWarning() << "Unknown vendor name: " << name;
return empty;
} }
bool Db::isVendorNameKnown( const QString& name ) bool Db::isVendorNameKnown( const QString& name )
{ {
foreach ( Vendor *vendor, mVendors ) return mVendorsNameMap.contains( name );
{
if ( vendor->name() == name )
{
return true;
}
}
return false;
} }
void Db::registerTemplate( Template *tmplate ) const Template Db::lookupTemplateFromName( const QString& name )
{ {
if ( !isTemplateKnown( tmplate->brand(), tmplate->part() ) ) if ( name.isEmpty() )
{
mTemplates << tmplate;
}
else
{
qWarning() << "Duplicate template name: " << tmplate->name();
}
}
const Template *Db::lookupTemplateFromName( const QString& name )
{
if ( name.isNull() || name.isEmpty() )
{ {
qWarning() << "NULL template name."; 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 *it;
{ }
return tmplate;
} auto it2 = mUserTemplatesNameMap.find( name );
if ( it2 != mUserTemplatesNameMap.end() )
{
return *it2;
} }
qWarning() << "Unknown template name: " << name; 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."; 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 *it;
{ }
return tmplate;
} auto it2 = mUserTemplatesNameMap.find( name );
if ( it2 != mUserTemplatesNameMap.end() )
{
return *it2;
} }
qWarning() << "Unknown template brand, part: " << brand << ", " << part; 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 ) bool Db::isTemplateKnown( const QString& brand, const QString& part )
{ {
foreach ( Template *tmplate, mTemplates ) auto name = Template::brandPartToName( brand, part );
{ return mTemplatesNameMap.contains( name ) || mUserTemplatesNameMap.contains( name );
if ( (tmplate->brand() == brand) && (tmplate->part() == part) )
{
return true;
}
}
return false;
} }
bool Db::isSystemTemplateKnown( const QString& brand, const QString& part ) bool Db::isSystemTemplateKnown( const QString& brand, const QString& part )
{ {
foreach ( Template *tmplate, mTemplates ) auto name = Template::brandPartToName( brand, part );
{ return mTemplatesNameMap.contains( name );
if ( (tmplate->brand() == brand) && }
(tmplate->part() == part) &&
!tmplate->isUserDefined() )
{
return true;
}
}
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; QStringList list;
const Template *tmplate1 = lookupTemplateFromName( name ); auto tmplate1 = lookupTemplateFromName( name );
if ( tmplate1 == nullptr ) if ( tmplate1.isNull() )
{ {
qWarning() << "Unknown template name: " << name; qWarning() << "Unknown template name: " << name;
return list; 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"; QString fileName = brand + "_" + part + ".template";
return FileUtil::userTemplatesDir().filePath( filename ); 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 // Write file
if ( XmlTemplateCreator().writeTemplate( tmplate, filename ) ) if ( XmlTemplateCreator().writeTemplate( tmplate, fileName ) )
{ {
// Add template to list of registered templates // Add template to list of registered templates
registerTemplate( tmplate ); mUserTemplatesNameMap[ tmplate.name() ] = tmplate;
Settings::addToRecentTemplateList( tmplate->name() ); mUserTemplatesNameMap[ tmplate.name() ].setFileName( fileName );
mUserTemplatesNameMap[ tmplate.name() ].setIsUserDefined( true );
Settings::addToRecentTemplateList( tmplate.name() );
} }
else else
{ {
qWarning() << "Problem writing user template" << filename; qWarning() << "Problem writing user template" << fileName;
} }
} }
void Db::deleteUserTemplateByBrandPart( const QString& brand, const QString& part ) void Db::deleteUserTemplateByBrandPart( const QString& brand, const QString& part )
{ {
Template* tmplate; auto tmplate = lookupUserTemplateFromBrandPart( brand, part );
foreach ( Template *candidate, mTemplates ) if ( !tmplate.isNull() && tmplate.isUserDefined() )
{ {
if ( candidate->isUserDefined() && mUserTemplatesNameMap.remove( Template::brandPartToName( brand, part ) );
(candidate->brand() == brand) && (candidate->part() == part) )
{ QFile( tmplate.fileName() ).remove();
tmplate = candidate;
break;
}
} }
else
if ( tmplate )
{ {
mTemplates.removeOne( tmplate ); qWarning() << "Not a user defined template:" << tmplate.name();
delete tmplate;
QString filename = userTemplateFilename( brand, part );
QFile( filename ).remove();
} }
} }
@@ -598,14 +466,14 @@ namespace glabels
{ {
qDebug() << "KNOWN PAPERS:"; qDebug() << "KNOWN PAPERS:";
foreach ( Paper *paper, mPapers ) for ( auto& paper : mPapers )
{ {
qDebug() << "paper " qDebug() << "paper "
<< "id=" << paper->id() << ", " << "id=" << paper.id() << ", "
<< "name=" << paper->name() << ", " << "name=" << paper.name() << ", "
<< "width=" << paper->width().pt() << "pts, " << "width=" << paper.width().pt() << "pts, "
<< "height=" << paper->height().pt() << "pts, " << "height=" << paper.height().pt() << "pts, "
<< "pwg_size=" << paper->pwgSize(); << "pwg_size=" << paper.pwgSize();
} }
qDebug(); qDebug();
@@ -616,11 +484,11 @@ namespace glabels
{ {
qDebug() << "KNOWN CATEGORIES:"; qDebug() << "KNOWN CATEGORIES:";
foreach ( Category *category, mCategories ) for ( auto& category : mCategories )
{ {
qDebug() << "category " qDebug() << "category "
<< "id=" << category->id() << ", " << "id=" << category.id() << ", "
<< "name=" << category->name(); << "name=" << category.name();
} }
qDebug(); qDebug();
@@ -631,11 +499,11 @@ namespace glabels
{ {
qDebug() << "KNOWN VENDORS:"; qDebug() << "KNOWN VENDORS:";
foreach ( Vendor *vendor, mVendors ) for ( auto& vendor : mVendors )
{ {
qDebug() << "vendor " qDebug() << "vendor "
<< "name='" << vendor->name() << ", " << "name='" << vendor.name() << ", "
<< "url='" << vendor->url(); << "url='" << vendor.url();
} }
qDebug(); qDebug();
@@ -646,12 +514,12 @@ namespace glabels
{ {
qDebug() << "KNOWN TEMPLATES:"; qDebug() << "KNOWN TEMPLATES:";
foreach ( Template *tmplate, mTemplates ) for ( auto& tmplate : mTemplates )
{ {
qDebug() << "template " qDebug() << "template "
<< "brand=" << tmplate->brand() << ", " << "brand=" << tmplate.brand() << ", "
<< "part=" << tmplate->part() << ", " << "part=" << tmplate.part() << ", "
<< "description=" << tmplate->description(); << "description=" << tmplate.description();
} }
qDebug(); qDebug();
@@ -668,16 +536,37 @@ namespace glabels
{ {
XmlPaperParser parser; XmlPaperParser parser;
foreach ( QString fileName, dir.entryList( QDir::Files ) ) for ( auto fileName : dir.entryList( QDir::Files ) )
{ {
if ( fileName == "paper-sizes.xml" ) 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() void Db::readCategories()
{ {
readCategoriesFromDir( FileUtil::systemTemplatesDir() ); readCategoriesFromDir( FileUtil::systemTemplatesDir() );
@@ -688,16 +577,37 @@ namespace glabels
{ {
XmlCategoryParser parser; XmlCategoryParser parser;
foreach ( QString fileName, dir.entryList( QDir::Files ) ) for ( auto fileName : dir.entryList( QDir::Files ) )
{ {
if ( fileName == "categories.xml" ) 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() void Db::readVendors()
{ {
readVendorsFromDir( FileUtil::systemTemplatesDir() ); readVendorsFromDir( FileUtil::systemTemplatesDir() );
@@ -708,36 +618,98 @@ namespace glabels
{ {
XmlVendorParser parser; XmlVendorParser parser;
foreach ( QString fileName, dir.entryList( QDir::Files ) ) for ( auto fileName : dir.entryList( QDir::Files ) )
{ {
if ( fileName == "vendors.xml" ) 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() void Db::readTemplates()
{ {
readTemplatesFromDir( FileUtil::systemTemplatesDir(), false ); readTemplatesFromDir( FileUtil::systemTemplatesDir() );
readTemplatesFromDir( FileUtil::manualUserTemplatesDir(), false ); readTemplatesFromDir( FileUtil::manualUserTemplatesDir() );
readTemplatesFromDir( FileUtil::userTemplatesDir(), true );
std::stable_sort( mTemplates.begin(), mTemplates.end(), partNameLessThan ); 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; QStringList filters;
filters << "*-templates.xml" << "*.template"; filters << "*-templates.xml" << "*.template";
XmlTemplateParser parser; 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 );
}
} }
} }
+43 -35
View File
@@ -27,7 +27,6 @@
#include "Template.h" #include "Template.h"
#include "Vendor.h" #include "Vendor.h"
#include <QCoreApplication>
#include <QDir> #include <QDir>
#include <QList> #include <QList>
#include <QString> #include <QString>
@@ -40,60 +39,55 @@ namespace glabels
class Db class Db
{ {
Q_DECLARE_TR_FUNCTIONS(Db)
private:
Db();
public: public:
Db() = delete;
static void init(); static void init();
static Db* instance();
static const QList<Paper*>& papers(); static const QList<Paper>& papers();
static const QStringList& paperIds(); static const QStringList& paperIds();
static const QStringList& paperNames(); static const QStringList& paperNames();
static const QList<Category*>& categories(); static const QList<Category>& categories();
static const QStringList& categoryIds(); static const QStringList& categoryIds();
static const QStringList& categoryNames(); static const QStringList& categoryNames();
static const QList<Vendor*>& vendors(); static const QList<Vendor>& vendors();
static const QStringList& vendorNames(); static const QStringList& vendorNames();
static const QList<Template*>& templates(); static QList<Template> templates();
static void registerPaper( Paper *paper ); static const Paper lookupPaperFromName( const QString& name );
static const Paper *lookupPaperFromName( const QString& name ); static const Paper lookupPaperFromId( const QString& id );
static const Paper *lookupPaperFromId( const QString& id );
static QString lookupPaperIdFromName( const QString& name ); static QString lookupPaperIdFromName( const QString& name );
static QString lookupPaperNameFromId( const QString& id ); static QString lookupPaperNameFromId( const QString& id );
static bool isPaperIdKnown( const QString& id ); static bool isPaperIdKnown( const QString& id );
static void registerCategory( Category *category ); static const Category lookupCategoryFromName( const QString& name );
static const Category *lookupCategoryFromName( const QString& name ); static const Category lookupCategoryFromId( const QString& id );
static const Category *lookupCategoryFromId( const QString& id );
static QString lookupCategoryIdFromName( const QString& name ); static QString lookupCategoryIdFromName( const QString& name );
static QString lookupCategoryNameFromId( const QString& id ); static QString lookupCategoryNameFromId( const QString& id );
static bool isCategoryIdKnown( 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 QString lookupVendorUrlFromName( const QString& name );
static bool isVendorNameKnown( const QString& id ); static bool isVendorNameKnown( const QString& id );
static void registerTemplate( Template *tmplate ); static const Template lookupTemplateFromName( const QString& name );
static const Template *lookupTemplateFromName( const QString& name ); static const Template lookupTemplateFromBrandPart( const QString& brand,
static const Template *lookupTemplateFromBrandPart( const QString& brand, const QString& part );
const QString& part ); static const Template lookupUserTemplateFromBrandPart( const QString& brand,
const QString& part );
static bool isTemplateKnown( 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 isSystemTemplateKnown( const QString& brand, const QString& part );
static bool isUserTemplateKnown( const QString& brand, const QString& part );
static QStringList getNameListOfSimilarTemplates( const QString& name ); static QStringList getNameListOfSimilarTemplates( const QString& name );
static QString userTemplateFilename( const QString& brand, const QString& part ); static QString userTemplateFileName( const QString& brand, const QString& part );
static void registerUserTemplate( Template *tmplate ); static void registerUserTemplate( const Template &tmplate );
static void deleteUserTemplateByBrandPart( const QString& brand, static void deleteUserTemplateByBrandPart( const QString& brand,
const QString& part ); const QString& part );
@@ -108,30 +102,44 @@ namespace glabels
static void readPapers(); static void readPapers();
static void readPapersFromDir( const QDir& dir ); static void readPapersFromDir( const QDir& dir );
static void registerPaper( const Paper& paper );
static void readCategories(); static void readCategories();
static void readCategoriesFromDir( const QDir& dir ); static void readCategoriesFromDir( const QDir& dir );
static void registerCategory( const Category& category );
static void readVendors(); static void readVendors();
static void readVendorsFromDir( const QDir& dir ); static void readVendorsFromDir( const QDir& dir );
static void registerVendor( const Vendor& vendor );
static void readTemplates(); 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: private:
static QList<Paper*> mPapers; static QList<Paper> mPapers;
static QStringList mPaperIds; static QMap<QString,Paper> mPapersNameMap;
static QStringList mPaperNames; static QMap<QString,Paper> mPapersIdMap;
static QStringList mPaperIds;
static QStringList mPaperNames;
static QList<Category*> mCategories; static QList<Category> mCategories;
static QStringList mCategoryIds; static QMap<QString,Category> mCategoriesNameMap;
static QStringList mCategoryNames; static QMap<QString,Category> mCategoriesIdMap;
static QStringList mCategoryIds;
static QStringList mCategoryNames;
static QList<Vendor*> mVendors; static QList<Vendor> mVendors;
static QStringList mVendorNames; static QMap<QString,Vendor> mVendorsNameMap;
static QStringList mVendorNames;
static QList<Template*> mTemplates; static QList<Template> mTemplates;
static QMap<QString,Template> mTemplatesNameMap;
static QMap<QString,Template> mUserTemplatesNameMap;
}; };
+4 -4
View File
@@ -56,7 +56,7 @@ namespace glabels
} }
Distance::Distance( double d, const Units& units ) Distance::Distance( double d, Units units )
{ {
switch (units.toEnum()) switch (units.toEnum())
{ {
@@ -128,7 +128,7 @@ namespace glabels
} }
double Distance::inUnits( const Units& units ) const double Distance::inUnits( Units units ) const
{ {
double d; 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(); 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); QDebugStateSaver saver(dbg);
+40 -40
View File
@@ -41,7 +41,7 @@ namespace glabels
public: public:
Distance(); Distance();
Distance( double d, Units::Enum unitsEnum = Units::PT ); 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 ); Distance( double d, const QString& unitsId );
static Distance pt( double dPts ); static Distance pt( double dPts );
@@ -57,38 +57,38 @@ namespace glabels
double mm() const; double mm() const;
double cm() const; double cm() const;
double pc() const; double pc() const;
double inUnits( const Units& units ) const; double inUnits( Units units ) const;
double inUnits( Units::Enum unitsEnum ) const; double inUnits( Units::Enum unitsEnum ) const;
double inUnits( const QString& unitsId ) 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( Units::Enum unitsEnum ) const;
QString toString( const QString& unitsId ) const; QString toString( const QString& unitsId ) const;
Distance& operator+=( const Distance& d ); Distance& operator+=( Distance d );
Distance& operator-=( const Distance& d ); Distance& operator-=( Distance d );
Distance& operator*=( double f ); Distance& operator*=( double f );
Distance operator-(); Distance operator-();
friend inline Distance operator+( const Distance& d1, const Distance& d2 ); friend inline Distance operator+( Distance d1, Distance d2 );
friend inline Distance operator-( const Distance& d1, const Distance& d2 ); friend inline Distance operator-( Distance d1, Distance d2 );
friend inline Distance operator*( double x, const Distance& d ); friend inline Distance operator*( double x, Distance d );
friend inline Distance operator*( const Distance& d, double x ); friend inline Distance operator*( Distance d, double x );
friend inline double operator/( const Distance& d1, const Distance& d2 ); friend inline double operator/( Distance d1, Distance d2 );
friend inline Distance operator/( const Distance& d, double x ); friend inline Distance operator/( Distance d, double x );
friend inline bool operator<( const Distance& d1, const Distance& d2 ); friend inline bool operator<( Distance d1, Distance d2 );
friend inline bool operator<=( const Distance& d1, const Distance& d2 ); friend inline bool operator<=( Distance d1, Distance d2 );
friend inline bool operator>( const Distance& d1, const Distance& d2 ); friend inline bool operator>( Distance d1, Distance d2 );
friend inline bool operator>=( const Distance& d1, const Distance& d2 ); friend inline bool operator>=( Distance d1, Distance d2 );
friend inline bool operator==( const Distance& d1, const Distance& d2 ); friend inline bool operator==( Distance d1, Distance d2 );
friend inline bool operator!=( const Distance& d1, const Distance& d2 ); friend inline bool operator!=( Distance d1, Distance d2 );
friend inline Distance fabs( const Distance& d ); friend inline Distance fabs( Distance d );
friend inline Distance min( const Distance& d1, const Distance& d2 ); friend inline Distance min( Distance d1, Distance d2 );
friend inline Distance max( const Distance& d1, const Distance& d2 ); friend inline Distance max( Distance d1, Distance d2 );
friend inline Distance fmod( const Distance& d1, const Distance& d2 ); friend inline Distance fmod( Distance d1, Distance d2 );
private: private:
@@ -101,7 +101,7 @@ namespace glabels
// Debugging support // 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; mDPts += d.mDPts;
return *this; return *this;
} }
inline Distance& Distance::operator-=( const Distance& d ) inline Distance& Distance::operator-=( Distance d )
{ {
mDPts -= d.mDPts; mDPts -= d.mDPts;
return *this; 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 ); 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 ); 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 ); 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 ); 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; 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 ); 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; 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; 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; 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; 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; 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; return d1.mDPts != d2.mDPts;
} }
inline Distance fabs( const Distance& d ) inline Distance fabs( Distance d )
{ {
return Distance::pt( qFabs( d.mDPts ) ); 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; 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; 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 ) ); return Distance::pt( std::fmod( d1.mDPts, d2.mDPts ) );
} }
+20 -63
View File
@@ -18,15 +18,11 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Frame.h" #include "Frame.h"
#include "FrameCd.h" #include <QDebug>
#include "FrameContinuous.h"
#include "FrameEllipse.h"
#include "FramePath.h"
#include "FrameRect.h"
#include "FrameRound.h"
#include "Markup.h"
#include <algorithm> #include <algorithm>
@@ -37,7 +33,9 @@ namespace glabels
{ {
Frame::Frame( const QString& id ) Frame::Frame( const QString& id )
: mId(id), mNLabels(0), mLayoutDescription("") : mId(id),
mNLabels(0),
mLayoutDescription("")
{ {
// empty // empty
} }
@@ -48,23 +46,14 @@ namespace glabels
mId = other.mId; mId = other.mId;
mNLabels = 0; mNLabels = 0;
foreach ( const Layout& layout, other.mLayouts ) for ( const auto& layout : other.mLayouts )
{ {
addLayout( layout ); addLayout( layout );
} }
foreach ( Markup *markup, other.mMarkups ) for ( const auto& markup : other.mMarkups )
{ {
addMarkup( markup->dup() ); mMarkups.push_back( markup->clone() );
}
}
Frame::~Frame()
{
while ( !mMarkups.isEmpty() )
{
delete mMarkups.takeFirst();
} }
} }
@@ -87,13 +76,13 @@ namespace glabels
} }
const QList<Layout>& Frame::layouts() const const std::list<Layout>& Frame::layouts() const
{ {
return mLayouts; return mLayouts;
} }
const QList<Markup*>& Frame::markups() const const std::list<std::unique_ptr<Markup>>& Frame::markups() const
{ {
return mMarkups; return mMarkups;
} }
@@ -104,7 +93,7 @@ namespace glabels
QVector<Point> origins( nLabels() ); QVector<Point> origins( nLabels() );
int i = 0; int i = 0;
foreach ( const Layout& layout, mLayouts ) for ( auto& layout : mLayouts )
{ {
for ( int iy = 0; iy < layout.ny(); iy++ ) for ( int iy = 0; iy < layout.ny(); iy++ )
{ {
@@ -123,7 +112,7 @@ namespace glabels
void Frame::addLayout( const Layout& layout ) void Frame::addLayout( const Layout& layout )
{ {
mLayouts << layout; mLayouts.push_back( layout );
// Update total number of labels // Update total number of labels
mNLabels += layout.nx() * layout.ny(); 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 // Default implementation does nothing
return false;
} }
} }
@@ -164,42 +154,9 @@ namespace glabels
QDebug operator<<( QDebug dbg, const glabels::model::Frame& frame ) QDebug operator<<( QDebug dbg, const glabels::model::Frame& frame )
{ {
if ( auto* frameCd = dynamic_cast<const glabels::model::FrameCd*>(&frame) ) QDebugStateSaver saver(dbg);
{
dbg << *frameCd;
return dbg;
}
else if ( auto* frameContinuous = dynamic_cast<const glabels::model::FrameContinuous*>(&frame) )
{
dbg << *frameContinuous;
return dbg;
}
else if ( auto* frameEllipse = dynamic_cast<const glabels::model::FrameEllipse*>(&frame) )
{
dbg << *frameEllipse;
return dbg;
}
else if ( auto* framePath = dynamic_cast<const glabels::model::FramePath*>(&frame) )
{
dbg << *framePath;
return dbg;
}
else if ( auto* frameRect = dynamic_cast<const glabels::model::FrameRect*>(&frame) )
{
dbg << *frameRect;
return dbg;
}
else if ( auto* frameRound = dynamic_cast<const glabels::model::FrameRound*>(&frame) )
{
dbg << *frameRound;
return dbg;
}
else
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "UNKNOWN FRAME"; frame.print( dbg );
return dbg; return dbg;
}
} }
+18 -17
View File
@@ -24,25 +24,23 @@
#include "Distance.h" #include "Distance.h"
#include "Layout.h" #include "Layout.h"
#include "Markup.h"
#include "Point.h" #include "Point.h"
#include <QCoreApplication> #include <QCoreApplication>
#include <QDebug> #include <QDebug>
#include <QList>
#include <QPainterPath> #include <QPainterPath>
#include <QString> #include <QString>
#include <QVector> #include <QVector>
#include <list>
namespace glabels namespace glabels
{ {
namespace model namespace model
{ {
// Forward references
class Markup;
class Frame class Frame
{ {
Q_DECLARE_TR_FUNCTIONS(Frame) Q_DECLARE_TR_FUNCTIONS(Frame)
@@ -52,32 +50,35 @@ namespace glabels
Frame( const Frame& other ); Frame( const Frame& other );
public: public:
virtual ~Frame(); virtual ~Frame() = default;
virtual Frame* dup() const = 0;
virtual std::unique_ptr<Frame> clone() const = 0;
QString id() const; QString id() const;
int nLabels() const; int nLabels() const;
QString layoutDescription() const; QString layoutDescription() const;
const QList<Layout>& layouts() const; const std::list<Layout>& layouts() const;
const QList<Markup*>& markups() const; const std::list<std::unique_ptr<Markup>>& markups() const;
QVector<Point> getOrigins() const; QVector<Point> getOrigins() const;
void addLayout( const Layout& layout ); void addLayout( const Layout& layout );
void addMarkup( Markup* markup ); void addMarkup( const Markup& markup );
virtual Distance w() const = 0; virtual Distance w() const = 0;
virtual Distance h() 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 QString sizeDescription( Units units ) const = 0;
virtual bool isSimilarTo( Frame* other ) const = 0; virtual bool isSimilarTo( const Frame& other ) const = 0;
virtual const QPainterPath& path() const = 0; virtual const QPainterPath& path() const = 0;
virtual const QPainterPath& clipPath() const = 0; virtual const QPainterPath& clipPath() const = 0;
virtual QPainterPath marginPath( const Distance& xSize, virtual QPainterPath marginPath( Distance xSize, Distance ySize ) const = 0;
const Distance& ySize ) const = 0;
// Debugging support
virtual void print( QDebug& dbg ) const = 0;
private: private:
@@ -85,8 +86,8 @@ namespace glabels
int mNLabels; int mNLabels;
QString mLayoutDescription; QString mLayoutDescription;
QList<Layout> mLayouts; std::list<Layout> mLayouts;
QList<Markup*> mMarkups; std::list<std::unique_ptr<Markup>> mMarkups;
}; };
} }
+46 -32
View File
@@ -18,12 +18,13 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "FrameCd.h" #include "FrameCd.h"
#include "Constants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
#include <QtDebug> #include <QDebug>
namespace glabels namespace glabels
@@ -31,13 +32,18 @@ namespace glabels
namespace model namespace model
{ {
FrameCd::FrameCd( const Distance& r1, FrameCd::FrameCd( Distance r1,
const Distance& r2, Distance r2,
const Distance& w, Distance w,
const Distance& h, Distance h,
const Distance& waste, Distance waste,
const QString& id ) const QString& id )
: Frame(id), mR1(r1), mR2(r2), mW(w), mH(h), mWaste(waste) : Frame(id),
mR1(r1),
mR2(r2),
mW(w),
mH(h),
mWaste(waste)
{ {
Distance wReal = (mW == 0) ? 2*mR1 : mW; Distance wReal = (mW == 0) ? 2*mR1 : mW;
Distance hReal = (mH == 0) ? 2*mR1 : mH; Distance hReal = (mH == 0) ? 2*mR1 : mH;
@@ -93,9 +99,9 @@ namespace glabels
} }
Frame* FrameCd::dup() const std::unique_ptr<Frame> FrameCd::clone() const
{ {
return new FrameCd( *this ); return std::make_unique<FrameCd>( *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 ) 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<FrameCd*>(other) ) if ( auto *otherCd = dynamic_cast<const FrameCd*>(&other) )
{ {
if ( (fabs( mW - otherCd->mW ) <= EPSILON) && if ( (fabs( mW - otherCd->mW ) <= EPSILON) &&
(fabs( mH - otherCd->mH ) <= EPSILON) && (fabs( mH - otherCd->mH ) <= EPSILON) &&
@@ -173,8 +179,7 @@ namespace glabels
} }
QPainterPath FrameCd::marginPath( const Distance& xSize, QPainterPath FrameCd::marginPath( Distance xSize, Distance ySize ) const
const Distance& ySize ) const
{ {
// Note: ignore ySize, assume xSize == ySize // Note: ignore ySize, assume xSize == ySize
Distance size = xSize; Distance size = xSize;
@@ -207,24 +212,33 @@ namespace glabels
return path; 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;
}
+13 -15
View File
@@ -35,16 +35,16 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameCd) Q_DECLARE_TR_FUNCTIONS(FrameCd)
public: public:
FrameCd( const Distance& r1, FrameCd( Distance r1,
const Distance& r2, Distance r2,
const Distance& w, Distance w,
const Distance& h, Distance h,
const Distance& waste, Distance waste,
const QString& id = "0" ); const QString& id = "0" );
FrameCd( const FrameCd &other ) = default; FrameCd( const FrameCd &other ) = default;
Frame *dup() const override; std::unique_ptr<Frame> clone() const override;
Distance r1() const; Distance r1() const;
Distance r2() const; Distance r2() const;
@@ -53,13 +53,15 @@ namespace glabels
Distance w() const override; Distance w() const override;
Distance h() 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& path() const override;
const QPainterPath& clipPath() const override; const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize, QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
const Distance& ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
@@ -78,8 +80,4 @@ namespace glabels
} }
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameCd& frame );
#endif // model_FrameCd_h #endif // model_FrameCd_h
+48 -33
View File
@@ -18,31 +18,39 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "FrameContinuous.h" #include "FrameContinuous.h"
#include "Constants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
#include <QDebug>
namespace glabels namespace glabels
{ {
namespace model namespace model
{ {
FrameContinuous::FrameContinuous( const Distance& w, FrameContinuous::FrameContinuous( Distance w,
const Distance& hMin, Distance hMin,
const Distance& hMax, Distance hMax,
const Distance& hDefault, Distance hDefault,
const QString& id ) const QString& id )
: Frame(id), mW(w), mHMin(hMin), mHMax(hMax), mHDefault(hDefault), mH(hDefault) : Frame(id),
mW(w),
mHMin(hMin),
mHMax(hMax),
mHDefault(hDefault),
mH(hDefault)
{ {
mPath.addRect( 0, 0, mW.pt(), mH.pt() ); mPath.addRect( 0, 0, mW.pt(), mH.pt() );
} }
Frame* FrameContinuous::dup() const std::unique_ptr<Frame> FrameContinuous::clone() const
{ {
return new FrameContinuous( *this ); return std::make_unique<FrameContinuous>( *this );
} }
@@ -76,15 +84,16 @@ namespace glabels
} }
void FrameContinuous::setH( const Distance& h ) bool FrameContinuous::setH( Distance h )
{ {
mH = h; mH = h;
mPath = QPainterPath(); // clear path mPath = QPainterPath(); // clear path
mPath.addRect( 0, 0, mW.pt(), mH.pt() ); 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 ) 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<FrameContinuous*>(other) ) if ( auto *otherContinuous = dynamic_cast<const FrameContinuous*>(&other) )
{ {
if ( fabs( mW - otherContinuous->mW ) <= EPSILON ) if ( fabs( mW - otherContinuous->mW ) <= EPSILON )
{ {
@@ -124,8 +133,7 @@ namespace glabels
} }
QPainterPath FrameContinuous::marginPath( const Distance& xSize, QPainterPath FrameContinuous::marginPath( Distance xSize, Distance ySize ) const
const Distance& ySize ) const
{ {
Distance w = mW - 2*xSize; Distance w = mW - 2*xSize;
Distance h = mH - 2*ySize; 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;
}
+13 -15
View File
@@ -35,15 +35,15 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameContinuous) Q_DECLARE_TR_FUNCTIONS(FrameContinuous)
public: public:
FrameContinuous( const Distance& w, FrameContinuous( Distance w,
const Distance& hMin, Distance hMin,
const Distance& hMax, Distance hMax,
const Distance& hDefault, Distance hDefault,
const QString& id = "0" ); const QString& id = "0" );
FrameContinuous( const FrameContinuous& other ) = default; FrameContinuous( const FrameContinuous& other ) = default;
Frame* dup() const override; std::unique_ptr<Frame> clone() const override;
Distance w() const override; Distance w() const override;
Distance h() const override; Distance h() const override;
@@ -52,16 +52,18 @@ namespace glabels
Distance hMax() const; Distance hMax() const;
Distance hDefault() 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& path() const override;
const QPainterPath& clipPath() const override; const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize, QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
const Distance& ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
@@ -78,8 +80,4 @@ namespace glabels
} }
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameContinuous& frame );
#endif // model_FrameContinuous_h #endif // model_FrameContinuous_h
+42 -29
View File
@@ -18,31 +18,37 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "FrameEllipse.h" #include "FrameEllipse.h"
#include "Constants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
#include <QDebug>
namespace glabels namespace glabels
{ {
namespace model namespace model
{ {
FrameEllipse::FrameEllipse( const Distance& w, FrameEllipse::FrameEllipse( Distance w,
const Distance& h, Distance h,
const Distance& waste, Distance waste,
const QString& id ) const QString& id )
: Frame(id), mW(w), mH(h), mWaste(waste) : Frame(id),
mW(w),
mH(h),
mWaste(waste)
{ {
mPath.addEllipse( 0, 0, mW.pt(), mH.pt() ); mPath.addEllipse( 0, 0, mW.pt(), mH.pt() );
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), (mW+2*mWaste).pt(), (mH+2*mWaste).pt() ); mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), (mW+2*mWaste).pt(), (mH+2*mWaste).pt() );
} }
Frame* FrameEllipse::dup() const std::unique_ptr<Frame> FrameEllipse::clone() const
{ {
return new FrameEllipse( *this ); return std::make_unique<FrameEllipse>( *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 ) 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<FrameEllipse*>(other) ) if ( auto* otherEllipse = dynamic_cast<const FrameEllipse*>(&other) )
{ {
if ( (fabs( mW - otherEllipse->mW ) <= EPSILON) && if ( (fabs( mW - otherEllipse->mW ) <= EPSILON) &&
(fabs( mH - otherEllipse->mH ) <= EPSILON) ) (fabs( mH - otherEllipse->mH ) <= EPSILON) )
@@ -108,8 +114,7 @@ namespace glabels
} }
QPainterPath FrameEllipse::marginPath( const Distance& xSize, QPainterPath FrameEllipse::marginPath( Distance xSize, Distance ySize ) const
const Distance& ySize ) const
{ {
// Note: ignore ySize, assume xSize == ySize // Note: ignore ySize, assume xSize == ySize
Distance size = xSize; Distance size = xSize;
@@ -123,22 +128,30 @@ namespace glabels
return path; 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;
}
+11 -13
View File
@@ -35,27 +35,29 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameEllipse) Q_DECLARE_TR_FUNCTIONS(FrameEllipse)
public: public:
FrameEllipse( const Distance& w, FrameEllipse( Distance w,
const Distance& h, Distance h,
const Distance& waste, Distance waste,
const QString& id = "0" ); const QString& id = "0" );
FrameEllipse( const FrameEllipse& other ) = default; FrameEllipse( const FrameEllipse& other ) = default;
Frame* dup() const override; std::unique_ptr<Frame> clone() const override;
Distance waste() const; Distance waste() const;
Distance w() const override; Distance w() const override;
Distance h() 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& path() const override;
const QPainterPath& clipPath() const override; const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize, QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
const Distance& ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
@@ -72,8 +74,4 @@ namespace glabels
} }
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameEllipse& frame );
#endif // model_FrameEllipse_h #endif // model_FrameEllipse_h
+41 -28
View File
@@ -18,11 +18,14 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "FramePath.h" #include "FramePath.h"
#include "Constants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
#include <QDebug>
namespace glabels namespace glabels
{ {
@@ -30,11 +33,15 @@ namespace glabels
{ {
FramePath::FramePath( const QPainterPath& path, FramePath::FramePath( const QPainterPath& path,
const Distance& xWaste, Distance xWaste,
const Distance& yWaste, Distance yWaste,
const Units& originalUnits, Units originalUnits,
const QString& id ) 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(); QRectF r = path.boundingRect();
@@ -46,9 +53,9 @@ namespace glabels
} }
Frame* FramePath::dup() const std::unique_ptr<Frame> FramePath::clone() const
{ {
return new FramePath( *this ); return std::make_unique<FramePath>( *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 ) 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<FramePath*>(other) ) if ( auto *otherPath = dynamic_cast<const FramePath*>(&other) )
{ {
if ( mPath == otherPath->mPath ) if ( mPath == otherPath->mPath )
{ {
@@ -125,29 +132,35 @@ namespace glabels
} }
QPainterPath FramePath::marginPath( const Distance& xSize, QPainterPath FramePath::marginPath( Distance xSize, Distance ySize ) const
const Distance& ySize ) const
{ {
return mPath; // No margin 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;
}
+10 -12
View File
@@ -36,14 +36,14 @@ namespace glabels
public: public:
FramePath( const QPainterPath& path, FramePath( const QPainterPath& path,
const Distance& xWaste, Distance xWaste,
const Distance& yWaste, Distance yWaste,
const Units& originalUnits, Units originalUnits,
const QString& id = "0" ); const QString& id = "0" );
FramePath( const FramePath& other ) = default; FramePath( const FramePath& other ) = default;
Frame* dup() const override; std::unique_ptr<Frame> clone() const override;
Distance xWaste() const; Distance xWaste() const;
Distance yWaste() const; Distance yWaste() const;
@@ -53,14 +53,16 @@ namespace glabels
Distance w() const override; Distance w() const override;
Distance h() 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& path() const override;
const QPainterPath& clipPath() const override; const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize, QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
const Distance& ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
@@ -79,8 +81,4 @@ namespace glabels
} }
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FramePath& frame );
#endif // model_FramePath_h #endif // model_FramePath_h
+47 -33
View File
@@ -18,24 +18,32 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "FrameRect.h" #include "FrameRect.h"
#include "Constants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
#include <QDebug>
namespace glabels namespace glabels
{ {
namespace model namespace model
{ {
FrameRect::FrameRect( const Distance& w, FrameRect::FrameRect( Distance w,
const Distance& h, Distance h,
const Distance& r, Distance r,
const Distance& xWaste, Distance xWaste,
const Distance& yWaste, Distance yWaste,
const QString& id ) const QString& id )
: Frame(id), mW(w), mH(h), mR(r), mXWaste(xWaste), mYWaste(yWaste) : Frame(id),
mW(w),
mH(h),
mR(r),
mXWaste(xWaste),
mYWaste(yWaste)
{ {
mPath.addRoundedRect( 0, 0, mW.pt(), mH.pt(), mR.pt(), mR.pt() ); 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<Frame> FrameRect::clone() const
{ {
return new FrameRect( *this ); return std::make_unique<FrameRect>( *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 ) 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<FrameRect*>(other) ) if ( auto *otherRect = dynamic_cast<const FrameRect*>(&other) )
{ {
if ( (fabs( mW - otherRect->mW ) <= EPSILON) && if ( (fabs( mW - otherRect->mW ) <= EPSILON) &&
(fabs( mH - otherRect->mH ) <= EPSILON) ) (fabs( mH - otherRect->mH ) <= EPSILON) )
@@ -125,8 +133,7 @@ namespace glabels
} }
QPainterPath FrameRect::marginPath( const Distance& xSize, QPainterPath FrameRect::marginPath( Distance xSize, Distance ySize ) const
const Distance& ySize ) const
{ {
Distance w = mW - 2*xSize; Distance w = mW - 2*xSize;
Distance h = mH - 2*ySize; 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;
}
+13 -15
View File
@@ -35,16 +35,16 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameRect) Q_DECLARE_TR_FUNCTIONS(FrameRect)
public: public:
FrameRect( const Distance& w, FrameRect( Distance w,
const Distance& h, Distance h,
const Distance& r, Distance r,
const Distance& xWaste, Distance xWaste,
const Distance& yWaste, Distance yWaste,
const QString& id = "0" ); const QString& id = "0" );
FrameRect( const FrameRect& other ) = default; FrameRect( const FrameRect& other ) = default;
Frame* dup() const override; std::unique_ptr<Frame> clone() const override;
Distance r() const; Distance r() const;
Distance xWaste() const; Distance xWaste() const;
@@ -53,14 +53,16 @@ namespace glabels
Distance w() const override; Distance w() const override;
Distance h() 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& path() const override;
const QPainterPath& clipPath() const override; const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize, QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
const Distance& ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
@@ -79,8 +81,4 @@ namespace glabels
} }
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameRect& frame );
#endif // model_FrameRect_h #endif // model_FrameRect_h
+39 -26
View File
@@ -18,21 +18,26 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "FrameRound.h" #include "FrameRound.h"
#include "Constants.h" #include "Constants.h"
#include "StrUtil.h" #include "StrUtil.h"
#include <QDebug>
namespace glabels namespace glabels
{ {
namespace model namespace model
{ {
FrameRound::FrameRound( const Distance& r, FrameRound::FrameRound( Distance r,
const Distance& waste, Distance waste,
const QString& id ) const QString& id )
: Frame(id), mR(r), mWaste(waste) : Frame(id),
mR(r),
mWaste(waste)
{ {
mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() ); mPath.addEllipse( 0, 0, 2*mR.pt(), 2*mR.pt() );
mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(), mClipPath.addEllipse( -mWaste.pt(), -mWaste.pt(),
@@ -40,9 +45,9 @@ namespace glabels
} }
Frame* FrameRound::dup() const std::unique_ptr<Frame> FrameRound::clone() const
{ {
return new FrameRound( *this ); return std::make_unique<FrameRound>( *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 ) 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<FrameRound*>(other) ) if ( auto *otherRound = dynamic_cast<const FrameRound*>(&other) )
{ {
if ( fabs( mR - otherRound->mR ) <= EPSILON ) if ( fabs( mR - otherRound->mR ) <= EPSILON )
{ {
@@ -111,8 +116,7 @@ namespace glabels
} }
QPainterPath FrameRound::marginPath( const Distance& xSize, QPainterPath FrameRound::marginPath( Distance xSize, Distance ySize ) const
const Distance& ySize ) const
{ {
// Note: ignore ySize, assume xSize == ySize // Note: ignore ySize, assume xSize == ySize
Distance size = xSize; Distance size = xSize;
@@ -125,21 +129,30 @@ namespace glabels
return path; 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;
}
+10 -12
View File
@@ -35,13 +35,13 @@ namespace glabels
Q_DECLARE_TR_FUNCTIONS(FrameRound) Q_DECLARE_TR_FUNCTIONS(FrameRound)
public: public:
FrameRound( const Distance& r, FrameRound( Distance r,
const Distance& waste, Distance waste,
const QString& id = "0" ); const QString& id = "0" );
FrameRound( const FrameRound &other ) = default; FrameRound( const FrameRound &other ) = default;
Frame *dup() const override; std::unique_ptr<Frame> clone() const override;
Distance r() const; Distance r() const;
Distance waste() const; Distance waste() const;
@@ -49,13 +49,15 @@ namespace glabels
Distance w() const override; Distance w() const override;
Distance h() 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& path() const override;
const QPainterPath& clipPath() const override; const QPainterPath& clipPath() const override;
QPainterPath marginPath( const Distance& xSize, QPainterPath marginPath( Distance xSize, Distance ySize ) const override;
const Distance& ySize ) const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
@@ -71,8 +73,4 @@ namespace glabels
} }
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::FrameRound& frame );
#endif // model_FrameRound_h #endif // model_FrameRound_h
+225
View File
@@ -0,0 +1,225 @@
/* Handles.cpp
*
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Handle.h"
#include "ModelObject.h"
#include <QColor>
#include <QDebug>
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;
}
}
}
+101
View File
@@ -0,0 +1,101 @@
/* Handles.h
*
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef model_Handles_h
#define model_Handles_h
#include "Distance.h"
#include <QPainter>
#include <QPainterPath>
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
-591
View File
@@ -1,591 +0,0 @@
/* Handles.cpp
*
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Handles.h"
#include "ModelObject.h"
#include <QColor>
#include <QtDebug>
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() );
}
}
}
-339
View File
@@ -1,339 +0,0 @@
/* Handles.h
*
* Copyright (C) 2013 Jaye Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef model_Handles_h
#define model_Handles_h
#include "Distance.h"
#include <QPainter>
#include <QPainterPath>
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
+12 -15
View File
@@ -30,21 +30,18 @@ namespace glabels
namespace model namespace model
{ {
Layout::Layout( int nx, Layout::Layout( int nx,
int ny, int ny,
const Distance& x0, Distance x0,
const Distance& y0, Distance y0,
const Distance& dx, Distance dx,
const Distance& dy ) Distance dy )
: mNx(nx), mNy(ny), mX0(x0), mY0(y0), mDx(dx), mDy(dy) : mNx(nx),
{ mNy(ny),
// empty mX0(x0),
} mY0(y0),
mDx(dx),
mDy(dy)
Layout::Layout( const Layout& other )
: mNx(other.mNx), mNy(other.mNy), mX0(other.mX0), mY0(other.mY0),
mDx(other.mDx), mDy(other.mDy)
{ {
// empty // empty
} }
+7 -7
View File
@@ -36,14 +36,14 @@ namespace glabels
{ {
public: public:
Layout( int nx, Layout( int nx,
int ny, int ny,
const Distance& x0, Distance x0,
const Distance& y0, Distance y0,
const Distance& dx, Distance dx,
const Distance& dy ); Distance dy );
Layout( const Layout &other ); Layout( const Layout& other ) = default;
int nx() const; int nx() const;
int ny() const; int ny() const;
+111 -38
View File
@@ -18,44 +18,49 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Markup.h" #include "Markup.h"
#include "Frame.h"
namespace glabels namespace glabels
{ {
namespace model 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 // Use cached path -- default does not depend on frame size
return mPath; return mPath;
} }
MarkupMargin::MarkupMargin( const Distance& size ) MarkupMargin::MarkupMargin( Distance size )
: mXSize(size), mYSize(size) : mXSize(size),
mYSize(size)
{ {
} }
MarkupMargin::MarkupMargin( const Distance& xSize, MarkupMargin::MarkupMargin( Distance xSize,
const Distance& ySize ) Distance ySize )
: mXSize(xSize), mYSize(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 // 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<Markup> MarkupMargin::clone() const
{ {
return new MarkupMargin( mXSize, mYSize ); return std::make_unique<MarkupMargin>( mXSize, mYSize );
} }
@@ -71,20 +76,31 @@ namespace glabels
} }
MarkupLine::MarkupLine( const Distance& x1, void MarkupMargin::print( QDebug& dbg ) const
const Distance& y1, {
const Distance& x2, dbg.nospace() << "MarkupMargin{ "
const Distance& y2 ) << mXSize << "," << mYSize
: mX1(x1), mY1(y1), mX2(x2), mY2(y2) << " }";
}
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.moveTo( x1.pt(), y1.pt() );
mPath.lineTo( x2.pt(), y2.pt() ); mPath.lineTo( x2.pt(), y2.pt() );
} }
Markup* MarkupLine::dup() const std::unique_ptr<Markup> MarkupLine::clone() const
{ {
return new MarkupLine( mX1, mY1, mX2, mY2 ); return std::make_unique<MarkupLine>( mX1, mY1, mX2, mY2 );
} }
@@ -112,20 +128,33 @@ namespace glabels
} }
MarkupRect::MarkupRect( const Distance& x1, void MarkupLine::print( QDebug& dbg ) const
const Distance& y1, {
const Distance& w, dbg.nospace() << "MarkupLine{ "
const Distance& h, << mX1 << "," << mY1 << ","
const Distance& r ) << mX2 << "," << mY2
: mX1(x1), mY1(y1), mW(w), mH(h), mR(r) << " }";
}
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() ); mPath.addRoundedRect( x1.pt(), y1.pt(), w.pt(), h.pt(), r.pt(), r.pt() );
} }
Markup* MarkupRect::dup() const std::unique_ptr<Markup> MarkupRect::clone() const
{ {
return new MarkupRect( mX1, mY1, mW, mH, mR ); return std::make_unique<MarkupRect>( mX1, mY1, mW, mH, mR );
} }
@@ -159,19 +188,32 @@ namespace glabels
} }
MarkupEllipse::MarkupEllipse( const Distance& x1, void MarkupRect::print( QDebug& dbg ) const
const Distance& y1, {
const Distance& w, dbg.nospace() << "MarkupRect{ "
const Distance& h ) << mX1 << "," << mY1 << ","
: mX1(x1), mY1(y1), mW(w), mH(h) << 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() ); mPath.addEllipse( x1.pt(), y1.pt(), w.pt(), h.pt() );
} }
Markup* MarkupEllipse::dup() const std::unique_ptr<Markup> MarkupEllipse::clone() const
{ {
return new MarkupEllipse( mX1, mY1, mW, mH ); return std::make_unique<MarkupEllipse>( mX1, mY1, mW, mH );
} }
@@ -199,17 +241,28 @@ namespace glabels
} }
MarkupCircle::MarkupCircle( const Distance& x0, void MarkupEllipse::print( QDebug& dbg ) const
const Distance& y0, {
const Distance& r ) dbg.nospace() << "MarkupEllipse{ "
: mX0(x0), mY0(y0), mR(r) << 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() ); mPath.addEllipse( (x0-r).pt(), (y0-r).pt(), 2*r.pt(), 2*r.pt() );
} }
Markup* MarkupCircle::dup() const std::unique_ptr<Markup> MarkupCircle::clone() const
{ {
return new MarkupCircle( mX0, mY0, mR ); return std::make_unique<MarkupCircle>( mX0, mY0, mR );
} }
@@ -230,5 +283,25 @@ namespace glabels
return mR; 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;
}
+54 -28
View File
@@ -22,24 +22,31 @@
#define model_Markup_h #define model_Markup_h
#include "Frame.h" #include "Distance.h"
#include <QPainterPath> #include <QPainterPath>
#include <memory>
namespace glabels namespace glabels
{ {
namespace model namespace model
{ {
class Frame; // Forward reference
class Markup class Markup
{ {
public: public:
virtual ~Markup() = default; virtual ~Markup() = default;
virtual Markup* dup() const = 0; virtual std::unique_ptr<Markup> 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: protected:
QPainterPath mPath; QPainterPath mPath;
@@ -49,17 +56,20 @@ namespace glabels
class MarkupMargin : public Markup class MarkupMargin : public Markup
{ {
public: public:
MarkupMargin( const Distance& size ); MarkupMargin( Distance size );
MarkupMargin( const Distance& xSize, MarkupMargin( Distance xSize,
const Distance& ySize ); Distance ySize );
QPainterPath path( const Frame* frame ) const override; QPainterPath path( const Frame& frame ) const override;
Distance xSize() const; Distance xSize() const;
Distance ySize() const; Distance ySize() const;
Markup* dup() const override; std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
Distance mXSize; Distance mXSize;
@@ -70,17 +80,20 @@ namespace glabels
class MarkupLine : public Markup class MarkupLine : public Markup
{ {
public: public:
MarkupLine( const Distance& x1, MarkupLine( Distance x1,
const Distance& y1, Distance y1,
const Distance& x2, Distance x2,
const Distance& y2 ); Distance y2 );
Distance x1() const; Distance x1() const;
Distance y1() const; Distance y1() const;
Distance x2() const; Distance x2() const;
Distance y2() const; Distance y2() const;
Markup* dup() const override; std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
Distance mX1; Distance mX1;
@@ -93,11 +106,11 @@ namespace glabels
class MarkupRect : public Markup class MarkupRect : public Markup
{ {
public: public:
MarkupRect( const Distance& x1, MarkupRect( Distance x1,
const Distance& y1, Distance y1,
const Distance& w, Distance w,
const Distance& h, Distance h,
const Distance& r ); Distance r );
Distance x1() const; Distance x1() const;
Distance y1() const; Distance y1() const;
@@ -105,7 +118,10 @@ namespace glabels
Distance h() const; Distance h() const;
Distance r() const; Distance r() const;
Markup* dup() const override; std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
Distance mX1; Distance mX1;
@@ -119,17 +135,20 @@ namespace glabels
class MarkupEllipse : public Markup class MarkupEllipse : public Markup
{ {
public: public:
MarkupEllipse( const Distance& x1, MarkupEllipse( Distance x1,
const Distance& y1, Distance y1,
const Distance& w, Distance w,
const Distance& h ); Distance h );
Distance x1() const; Distance x1() const;
Distance y1() const; Distance y1() const;
Distance w() const; Distance w() const;
Distance h() const; Distance h() const;
Markup* dup() const override; std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
Distance mX1; Distance mX1;
@@ -142,15 +161,18 @@ namespace glabels
class MarkupCircle : public Markup class MarkupCircle : public Markup
{ {
public: public:
MarkupCircle( const Distance& x0, MarkupCircle( Distance x0,
const Distance& y0, Distance y0,
const Distance& r ); Distance r );
Distance x0() const; Distance x0() const;
Distance y0() const; Distance y0() const;
Distance r() const; Distance r() const;
Markup* dup() const override; std::unique_ptr<Markup> clone() const override;
// Debugging support
void print( QDebug& dbg ) const override;
private: private:
Distance mX0; Distance mX0;
@@ -163,4 +185,8 @@ namespace glabels
} }
// Debugging support
QDebug operator<<( QDebug dbg, const glabels::model::Markup& markup );
#endif // model_Markup_h #endif // model_Markup_h
+54 -50
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Model.h" #include "Model.h"
#include "ModelObject.h" #include "ModelObject.h"
@@ -55,17 +56,9 @@ namespace glabels
/// ///
Model::Model() Model::Model()
{ {
mVariables = new Variables(); mMerge.reset( new merge::None() );
mMerge = new merge::None();
connect( mVariables, SIGNAL(changed()), this, SLOT(onVariablesChanged()) ); connect( &mVariables, SIGNAL(changed()), this, SLOT(onVariablesChanged()) );
}
Model::Model( merge::Merge* merge, Variables* variables )
{
mVariables = variables; // Shared
mMerge = merge; // Shared
} }
@@ -75,7 +68,6 @@ namespace glabels
Model::~Model() Model::~Model()
{ {
qDeleteAll( mObjectList ); qDeleteAll( mObjectList );
// Final instance of mMerge and mVariables to be deleted by Model owner
} }
@@ -84,7 +76,7 @@ namespace glabels
/// ///
Model* Model::save() const 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 ) if ( mFileName.isEmpty() && mUntitledInstance == 0 )
{ {
@@ -127,6 +119,10 @@ namespace glabels
connect( object, SIGNAL(moved()), this, SLOT(onObjectMoved()) ); connect( object, SIGNAL(moved()), this, SLOT(onObjectMoved()) );
} }
mVariables.copy( savedModel->mVariables );
mMerge = savedModel->mMerge;
// Emit signals based on potential changes // Emit signals based on potential changes
emit changed(); emit changed();
emit selectionChanged(); emit selectionChanged();
@@ -170,34 +166,34 @@ namespace glabels
/// ///
/// Get template /// Get template
/// ///
const Template* Model::tmplate() const const Template& Model::tmplate() const
{ {
return &mTmplate; return mTmplate;
} }
/// ///
/// Get frame /// 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 /// Set template
/// ///
void Model::setTmplate( const Template* tmplate ) void Model::setTmplate( const Template& tmplate )
{ {
mTmplate = *tmplate; mTmplate = tmplate;
setModified(); setModified();
emit changed(); emit changed();
emit sizeChanged(); emit sizeChanged();
Settings::addToRecentTemplateList( tmplate->name() ); Settings::addToRecentTemplateList( tmplate.name() );
} }
@@ -232,10 +228,9 @@ namespace glabels
/// ///
Distance Model::w() const Distance Model::w() const
{ {
auto& frames = mTmplate.frames(); auto frame = mTmplate.frame();
if ( !frames.isEmpty() ) if ( frame )
{ {
auto* frame = mTmplate.frames().constFirst();
return mRotate ? frame->h() : frame->w(); return mRotate ? frame->h() : frame->w();
} }
else else
@@ -250,10 +245,9 @@ namespace glabels
/// ///
Distance Model::h() const Distance Model::h() const
{ {
auto& frames = mTmplate.frames(); auto frame = mTmplate.frame();
if ( !frames.isEmpty() ) if ( frame )
{ {
auto* frame = mTmplate.frames().constFirst();
return mRotate ? frame->w() : frame->h(); return mRotate ? frame->w() : frame->h();
} }
else else
@@ -266,12 +260,10 @@ namespace glabels
/// ///
/// Set height (if variable length) /// 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(); setModified();
emit changed(); emit changed();
@@ -350,7 +342,16 @@ namespace glabels
/// ///
/// Get variables object /// 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; return mVariables;
} }
@@ -361,7 +362,7 @@ namespace glabels
/// ///
merge::Merge* Model::merge() const merge::Merge* Model::merge() const
{ {
return mMerge; return mMerge.get();
} }
@@ -372,11 +373,10 @@ namespace glabels
{ {
if ( merge != mMerge ) if ( merge != mMerge )
{ {
delete mMerge; mMerge.reset( merge );
mMerge = merge;
connect( mMerge, SIGNAL(sourceChanged()), this, SLOT(onMergeSourceChanged()) ); connect( mMerge.get(), SIGNAL(sourceChanged()), this, SLOT(onMergeSourceChanged()) );
connect( mMerge, SIGNAL(selectionChanged()), this, SLOT(onMergeSelectionChanged()) ); connect( mMerge.get(), SIGNAL(selectionChanged()), this, SLOT(onMergeSelectionChanged()) );
setModified(); setModified();
@@ -445,9 +445,9 @@ namespace glabels
/// ///
/// Object at x,y /// Object at x,y
/// ///
ModelObject* Model::objectAt( double scale, ModelObject* Model::objectAt( double scale,
const Distance& x, Distance x,
const Distance& y ) const Distance y ) const
{ {
/* Search object list in reverse order. I.e. from top to bottom. */ /* Search object list in reverse order. I.e. from top to bottom. */
QList<ModelObject*>::const_iterator it = mObjectList.end(); QList<ModelObject*>::const_iterator it = mObjectList.end();
@@ -468,20 +468,22 @@ namespace glabels
/// ///
/// Handle at x,y /// Handle at x,y
/// ///
Handle* Model::handleAt( double scale, const Handle& Model::handleAt( double scale,
const Distance& x, Distance x,
const Distance& y ) const Distance y ) const
{ {
static Handle nullHandle;
foreach( ModelObject* object, mObjectList ) foreach( ModelObject* object, mObjectList )
{ {
Handle* handle = object->handleAt( scale, x, y ); auto& handle = object->handleAt( scale, x, y );
if ( handle ) if ( !handle.isNull() )
{ {
return handle; return handle;
} }
} }
return nullptr; return nullHandle;
} }
@@ -1216,7 +1218,7 @@ namespace glabels
/// ///
/// Move Selected Objects By dx,dy /// 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 ) foreach ( ModelObject* object, mObjectList )
{ {
@@ -1387,7 +1389,7 @@ namespace glabels
/// ///
/// Set Line Width Of Selected Objects /// Set Line Width Of Selected Objects
/// ///
void Model::setSelectionLineWidth( const Distance& lineWidth ) void Model::setSelectionLineWidth( Distance lineWidth )
{ {
foreach ( ModelObject* object, mObjectList ) foreach ( ModelObject* object, mObjectList )
{ {
@@ -1450,8 +1452,7 @@ namespace glabels
{ {
QClipboard *clipboard = QApplication::clipboard(); QClipboard *clipboard = QApplication::clipboard();
QByteArray buffer; auto buffer = XmlLabelCreator::serializeObjects( getSelection(), this );
XmlLabelCreator::serializeObjects( getSelection(), this, buffer );
auto *mimeData = new QMimeData; auto *mimeData = new QMimeData;
mimeData->setData( MIME_TYPE, buffer ); mimeData->setData( MIME_TYPE, buffer );
@@ -1607,11 +1608,14 @@ namespace glabels
/// ///
/// Draw label objects /// 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 ) foreach ( ModelObject* object, mObjectList )
{ {
object->draw( painter, inEditor, record, variables ); object->draw( painter, inEditor, record, variablesInstance );
} }
} }
+22 -20
View File
@@ -60,7 +60,7 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
public: public:
Model(); Model();
Model( merge::Merge* merge, Variables* variables ); Model( merge::Merge* merge );
~Model(); ~Model();
@@ -100,9 +100,9 @@ namespace glabels
const QString& fileName() const; const QString& fileName() const;
void setFileName( const QString &fileName ); void setFileName( const QString &fileName );
const Template* tmplate() const; const Template& tmplate() const;
const Frame* frame() const; const Frame* frame( const QString& id = "0" ) const;
void setTmplate( const Template* tmplate ); void setTmplate( const Template& tmplate );
bool rotate() const; bool rotate() const;
void setRotate( bool rotate ); void setRotate( bool rotate );
@@ -110,11 +110,12 @@ namespace glabels
Distance w() const; Distance w() const;
Distance h() const; Distance h() const;
void setH( const Distance& h ); void setH( Distance h );
const QList<ModelObject*>& objectList() const; const QList<ModelObject*>& objectList() const;
Variables* variables() const; Variables& variables();
const Variables& constVariables() const;
merge::Merge* merge() const; merge::Merge* merge() const;
void setMerge( merge::Merge* merge ); void setMerge( merge::Merge* merge );
@@ -127,13 +128,13 @@ namespace glabels
void addObject( ModelObject* object ); void addObject( ModelObject* object );
void deleteObject( ModelObject* object ); void deleteObject( ModelObject* object );
ModelObject* objectAt( double scale, ModelObject* objectAt( double scale,
const Distance& x, Distance x,
const Distance& y ) const; Distance y ) const;
Handle* handleAt( double scale, const Handle& handleAt( double scale,
const Distance& x, Distance x,
const Distance& y ) const; Distance y ) const;
///////////////////////////////// /////////////////////////////////
@@ -188,7 +189,7 @@ namespace glabels
void centerSelection(); void centerSelection();
void centerSelectionHoriz(); void centerSelectionHoriz();
void centerSelectionVert(); void centerSelectionVert();
void moveSelection( const Distance& dx, const Distance& dy ); void moveSelection( Distance dx, Distance dy );
void setSelectionFontFamily( const QString& fontFamily ); void setSelectionFontFamily( const QString& fontFamily );
void setSelectionFontSize( double fontSize ); void setSelectionFontSize( double fontSize );
void setSelectionFontWeight( QFont::Weight fontWeight ); void setSelectionFontWeight( QFont::Weight fontWeight );
@@ -197,7 +198,7 @@ namespace glabels
void setSelectionTextVAlign( Qt::Alignment textVAlign ); void setSelectionTextVAlign( Qt::Alignment textVAlign );
void setSelectionTextLineSpacing( double textLineSpacing ); void setSelectionTextLineSpacing( double textLineSpacing );
void setSelectionTextColorNode( ColorNode textColorNode ); void setSelectionTextColorNode( ColorNode textColorNode );
void setSelectionLineWidth( const Distance& lineWidth ); void setSelectionLineWidth( Distance lineWidth );
void setSelectionLineColorNode( ColorNode lineColorNode ); void setSelectionLineColorNode( ColorNode lineColorNode );
void setSelectionFillColorNode( ColorNode fillColorNode ); void setSelectionFillColorNode( ColorNode fillColorNode );
@@ -218,10 +219,10 @@ namespace glabels
// Drawing operations // Drawing operations
///////////////////////////////// /////////////////////////////////
public: public:
void draw( QPainter* painter, void draw( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const; const Variables& variablesInstance ) const;
///////////////////////////////// /////////////////////////////////
@@ -247,8 +248,9 @@ namespace glabels
QList<ModelObject*> mObjectList; QList<ModelObject*> mObjectList;
Variables* mVariables; Variables mVariables;
merge::Merge* mMerge;
QSharedPointer<merge::Merge> mMerge;
}; };
} }
+39 -72
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ModelBarcodeObject.h" #include "ModelBarcodeObject.h"
#include "Size.h" #include "Size.h"
@@ -58,16 +59,16 @@ namespace glabels
/// ///
ModelBarcodeObject::ModelBarcodeObject() ModelBarcodeObject::ModelBarcodeObject()
{ {
mOutline = new Outline( this ); mOutline.setOwner( this );
mHandles << new HandleNorthWest( this ); mHandles.push_back( Handle( this, Handle::NW ) );
mHandles << new HandleNorth( this ); mHandles.push_back( Handle( this, Handle::N ) );
mHandles << new HandleNorthEast( this ); mHandles.push_back( Handle( this, Handle::NE ) );
mHandles << new HandleEast( this ); mHandles.push_back( Handle( this, Handle::E ) );
mHandles << new HandleSouthEast( this ); mHandles.push_back( Handle( this, Handle::SE ) );
mHandles << new HandleSouth( this ); mHandles.push_back( Handle( this, Handle::S ) );
mHandles << new HandleSouthWest( this ); mHandles.push_back( Handle( this, Handle::SW ) );
mHandles << new HandleWest( this ); mHandles.push_back( Handle( this, Handle::W ) );
mBcStyle = barcode::Backends::defaultStyle(); mBcStyle = barcode::Backends::defaultStyle();
mBcTextFlag = mBcStyle.canText(); mBcTextFlag = mBcStyle.canText();
@@ -76,9 +77,6 @@ namespace glabels
mBcData = ""; mBcData = "";
mBcColorNode = ColorNode( Qt::black ); mBcColorNode = ColorNode( Qt::black );
mEditorBarcode = nullptr;
mEditorDefaultBarcode = nullptr;
update(); // Initialize cached editor layouts update(); // Initialize cached editor layouts
} }
@@ -86,10 +84,10 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
ModelBarcodeObject::ModelBarcodeObject( const Distance& x0, ModelBarcodeObject::ModelBarcodeObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const barcode::Style& bcStyle, const barcode::Style& bcStyle,
bool bcTextFlag, bool bcTextFlag,
@@ -99,16 +97,16 @@ namespace glabels
const QTransform& matrix ) const QTransform& matrix )
: ModelObject( x0, y0, w, h, lockAspectRatio, matrix ) : ModelObject( x0, y0, w, h, lockAspectRatio, matrix )
{ {
mOutline = new Outline( this ); mOutline.setOwner( this );
mHandles << new HandleNorthWest( this ); mHandles.push_back( Handle( this, Handle::NW ) );
mHandles << new HandleNorth( this ); mHandles.push_back( Handle( this, Handle::N ) );
mHandles << new HandleNorthEast( this ); mHandles.push_back( Handle( this, Handle::NE ) );
mHandles << new HandleEast( this ); mHandles.push_back( Handle( this, Handle::E ) );
mHandles << new HandleSouthEast( this ); mHandles.push_back( Handle( this, Handle::SE ) );
mHandles << new HandleSouth( this ); mHandles.push_back( Handle( this, Handle::S ) );
mHandles << new HandleSouthWest( this ); mHandles.push_back( Handle( this, Handle::SW ) );
mHandles << new HandleWest( this ); mHandles.push_back( Handle( this, Handle::W ) );
mBcStyle = bcStyle; mBcStyle = bcStyle;
mBcTextFlag = bcTextFlag; mBcTextFlag = bcTextFlag;
@@ -117,9 +115,6 @@ namespace glabels
mBcData = bcData; mBcData = bcData;
mBcColorNode = bcColorNode; mBcColorNode = bcColorNode;
mEditorBarcode = nullptr;
mEditorDefaultBarcode = nullptr;
update(); // Initialize cached editor layouts update(); // Initialize cached editor layouts
} }
@@ -137,30 +132,10 @@ namespace glabels
mBcData = object->mBcData; mBcData = object->mBcData;
mBcColorNode = object->mBcColorNode; mBcColorNode = object->mBcColorNode;
mEditorBarcode = nullptr;
mEditorDefaultBarcode = nullptr;
update(); // Initialize cached editor layouts update(); // Initialize cached editor layouts
} }
///
/// Destructor
///
ModelBarcodeObject::~ModelBarcodeObject()
{
delete mOutline;
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
delete mEditorBarcode;
}
/// ///
/// Clone /// Clone
/// ///
@@ -311,10 +286,10 @@ namespace glabels
/// ///
/// Draw shadow of object /// Draw shadow of object
/// ///
void ModelBarcodeObject::drawShadow( QPainter* painter, void ModelBarcodeObject::drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
// Barcodes don't support shadows. // Barcodes don't support shadows.
} }
@@ -323,10 +298,10 @@ namespace glabels
/// ///
/// Draw object itself /// Draw object itself
/// ///
void ModelBarcodeObject::drawObject( QPainter* painter, void ModelBarcodeObject::drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
QColor bcColor = mBcColorNode.color( record, variables ); QColor bcColor = mBcColorNode.color( record, variables );
@@ -367,16 +342,12 @@ namespace glabels
// //
// Build barcode from data // Build barcode from data
// //
if ( mEditorBarcode ) mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
{
delete mEditorBarcode;
}
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
if ( !mEditorBarcode ) if ( !mEditorBarcode )
{ {
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\"."; qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
mBcStyle = barcode::Backends::defaultStyle(); mBcStyle = barcode::Backends::defaultStyle();
mEditorBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ); mEditorBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
} }
mEditorBarcode->setChecksum(mBcChecksumFlag); mEditorBarcode->setChecksum(mBcChecksumFlag);
mEditorBarcode->setShowText(mBcTextFlag); mEditorBarcode->setShowText(mBcTextFlag);
@@ -386,16 +357,12 @@ namespace glabels
// //
// Build a place holder barcode to display in editor, if cannot display actual barcode // Build a place holder barcode to display in editor, if cannot display actual barcode
// //
if ( mEditorDefaultBarcode ) mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() ) );
{
delete mEditorDefaultBarcode;
}
mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.fullId().toStdString() );
if ( !mEditorDefaultBarcode ) if ( !mEditorDefaultBarcode )
{ {
qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\"."; qWarning() << "Invalid barcode style" << mBcStyle.fullId() << "using \"code39\".";
mBcStyle = barcode::Backends::defaultStyle(); mBcStyle = barcode::Backends::defaultStyle();
mEditorDefaultBarcode = glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ); mEditorDefaultBarcode.reset( glbarcode::Factory::createBarcode( mBcStyle.id().toStdString() ) );
} }
mEditorDefaultBarcode->setChecksum(mBcChecksumFlag); mEditorDefaultBarcode->setChecksum(mBcChecksumFlag);
mEditorDefaultBarcode->setShowText(mBcTextFlag); mEditorDefaultBarcode->setShowText(mBcTextFlag);
@@ -452,10 +419,10 @@ namespace glabels
/// Draw barcode in final printout or preview /// Draw barcode in final printout or preview
/// ///
void void
ModelBarcodeObject::drawBc( QPainter* painter, ModelBarcodeObject::drawBc( QPainter* painter,
const QColor& color, const QColor& color,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
painter->setPen( QPen( color ) ); painter->setPen( QPen( color ) );
+21 -19
View File
@@ -28,6 +28,8 @@
#include "glbarcode/Barcode.h" #include "glbarcode/Barcode.h"
#include <memory>
namespace glabels namespace glabels
{ {
@@ -47,10 +49,10 @@ namespace glabels
public: public:
ModelBarcodeObject(); ModelBarcodeObject();
ModelBarcodeObject( const Distance& x0, ModelBarcodeObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const barcode::Style& bcStyle, const barcode::Style& bcStyle,
bool bcTextFlag, bool bcTextFlag,
@@ -61,7 +63,7 @@ namespace glabels
ModelBarcodeObject( const ModelBarcodeObject* object ); ModelBarcodeObject( const ModelBarcodeObject* object );
~ModelBarcodeObject() override; virtual ~ModelBarcodeObject() = default;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@@ -127,15 +129,15 @@ namespace glabels
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
void drawShadow( QPainter* painter, void drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
void drawObject( QPainter* painter, void drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override; QPainterPath hoverPath( double scale ) const override;
@@ -149,10 +151,10 @@ namespace glabels
void drawBcInEditor( QPainter* painter, const QColor& color ) const; void drawBcInEditor( QPainter* painter, const QColor& color ) const;
void drawBc( QPainter* painter, void drawBc( QPainter* painter,
const QColor& color, const QColor& color,
merge::Record* record, const merge::Record& record,
Variables* variables ) const; const Variables& variables ) const;
void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const; void drawPlaceHolder( QPainter* painter, const QColor& color, const QString& text ) const;
@@ -169,8 +171,8 @@ namespace glabels
RawText mBcData; RawText mBcData;
ColorNode mBcColorNode; ColorNode mBcColorNode;
glbarcode::Barcode* mEditorBarcode; std::unique_ptr<glbarcode::Barcode> mEditorBarcode;
glbarcode::Barcode* mEditorDefaultBarcode; std::unique_ptr<glbarcode::Barcode> mEditorDefaultBarcode;
QPainterPath mHoverPath; QPainterPath mHoverPath;
+35 -33
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ModelBoxObject.h" #include "ModelBoxObject.h"
#include <QBrush> #include <QBrush>
@@ -50,24 +51,34 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
ModelBoxObject::ModelBoxObject( const Distance& x0, ModelBoxObject::ModelBoxObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const Distance& lineWidth, Distance lineWidth,
const ColorNode& lineColorNode, const ColorNode& lineColorNode,
const ColorNode& fillColorNode, const ColorNode& fillColorNode,
const QTransform& matrix, const QTransform& matrix,
bool shadowState, bool shadowState,
const Distance& shadowX, Distance shadowX,
const Distance& shadowY, Distance shadowY,
double shadowOpacity, double shadowOpacity,
const ColorNode& shadowColorNode ) const ColorNode& shadowColorNode )
: ModelShapeObject( x0, y0, w, h, lockAspectRatio, : ModelShapeObject( x0,
lineWidth, lineColorNode, fillColorNode, y0,
w,
h,
lockAspectRatio,
lineWidth,
lineColorNode,
fillColorNode,
matrix, matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode ) shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{ {
// empty // empty
} }
@@ -83,15 +94,6 @@ namespace glabels
} }
///
/// Destructor
///
ModelBoxObject::~ModelBoxObject()
{
// empty
}
/// ///
/// Clone /// Clone
/// ///
@@ -104,10 +106,10 @@ namespace glabels
/// ///
/// Draw shadow of object /// Draw shadow of object
/// ///
void ModelBoxObject::drawShadow( QPainter* painter, void ModelBoxObject::drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
QColor lineColor = mLineColorNode.color( record, variables ); QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables ); QColor fillColor = mFillColorNode.color( record, variables );
@@ -152,10 +154,10 @@ namespace glabels
/// ///
/// Draw object itself /// Draw object itself
/// ///
void ModelBoxObject::drawObject( QPainter* painter, void ModelBoxObject::drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
QColor lineColor = mLineColorNode.color( record, variables ); QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables ); QColor fillColor = mFillColorNode.color( record, variables );
+22 -22
View File
@@ -43,24 +43,24 @@ namespace glabels
public: public:
ModelBoxObject(); ModelBoxObject();
ModelBoxObject( const Distance& x0, ModelBoxObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const Distance& lineWidth, Distance lineWidth,
const ColorNode& lineColorNode, const ColorNode& lineColorNode,
const ColorNode& fillColorNode, const ColorNode& fillColorNode,
const QTransform& matrix = QTransform(), const QTransform& matrix = QTransform(),
bool shadowState = false, bool shadowState = false,
const Distance& shadowX = 0, Distance shadowX = 0,
const Distance& shadowY = 0, Distance shadowY = 0,
double shadowOpacity = 1.0, double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() ); const ColorNode& shadowColorNode = ColorNode() );
ModelBoxObject( const ModelBoxObject* object ); ModelBoxObject( const ModelBoxObject* object );
~ModelBoxObject() override; virtual ~ModelBoxObject() = default;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@@ -73,15 +73,15 @@ namespace glabels
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
void drawShadow( QPainter* painter, void drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
void drawObject( QPainter* painter, void drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override; QPainterPath hoverPath( double scale ) const override;
+35 -33
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ModelEllipseObject.h" #include "ModelEllipseObject.h"
#include <QBrush> #include <QBrush>
@@ -50,24 +51,34 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
ModelEllipseObject::ModelEllipseObject( const Distance& x0, ModelEllipseObject::ModelEllipseObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const Distance& lineWidth, Distance lineWidth,
const ColorNode& lineColorNode, const ColorNode& lineColorNode,
const ColorNode& fillColorNode, const ColorNode& fillColorNode,
const QTransform& matrix, const QTransform& matrix,
bool shadowState, bool shadowState,
const Distance& shadowX, Distance shadowX,
const Distance& shadowY, Distance shadowY,
double shadowOpacity, double shadowOpacity,
const ColorNode& shadowColorNode ) const ColorNode& shadowColorNode )
: ModelShapeObject( x0, y0, w, h, lockAspectRatio, : ModelShapeObject( x0,
lineWidth, lineColorNode, fillColorNode, y0,
w,
h,
lockAspectRatio,
lineWidth,
lineColorNode,
fillColorNode,
matrix, matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode ) shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{ {
// empty // empty
} }
@@ -83,15 +94,6 @@ namespace glabels
} }
///
/// Destructor
///
ModelEllipseObject::~ModelEllipseObject()
{
// empty
}
/// ///
/// Clone /// Clone
/// ///
@@ -104,10 +106,10 @@ namespace glabels
/// ///
/// Draw shadow of object /// Draw shadow of object
/// ///
void ModelEllipseObject::drawShadow( QPainter* painter, void ModelEllipseObject::drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
QColor lineColor = mLineColorNode.color( record, variables ); QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables ); QColor fillColor = mFillColorNode.color( record, variables );
@@ -152,10 +154,10 @@ namespace glabels
/// ///
/// Draw object itself /// Draw object itself
/// ///
void ModelEllipseObject::drawObject( QPainter* painter, void ModelEllipseObject::drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
QColor lineColor = mLineColorNode.color( record, variables ); QColor lineColor = mLineColorNode.color( record, variables );
QColor fillColor = mFillColorNode.color( record, variables ); QColor fillColor = mFillColorNode.color( record, variables );
+22 -22
View File
@@ -43,24 +43,24 @@ namespace glabels
public: public:
ModelEllipseObject(); ModelEllipseObject();
ModelEllipseObject( const Distance& x0, ModelEllipseObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const Distance& lineWidth, Distance lineWidth,
const ColorNode& lineColorNode, const ColorNode& lineColorNode,
const ColorNode& fillColorNode, const ColorNode& fillColorNode,
const QTransform& matrix = QTransform(), const QTransform& matrix = QTransform(),
bool shadowState = false, bool shadowState = false,
const Distance& shadowX = 0, Distance shadowX = 0,
const Distance& shadowY = 0, Distance shadowY = 0,
double shadowOpacity = 1.0, double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() ); const ColorNode& shadowColorNode = ColorNode() );
ModelEllipseObject( const ModelEllipseObject* object ); ModelEllipseObject( const ModelEllipseObject* object );
~ModelEllipseObject() override; virtual ~ModelEllipseObject() = default;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@@ -73,15 +73,15 @@ namespace glabels
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
void drawShadow( QPainter* painter, void drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
void drawObject( QPainter* painter, void drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override; QPainterPath hoverPath( double scale ) const override;
+168 -259
View File
@@ -18,17 +18,18 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ModelImageObject.h" #include "ModelImageObject.h"
#include "Model.h" #include "Model.h"
#include "Size.h" #include "Size.h"
#include <QBrush> #include <QBrush>
#include <QDebug>
#include <QDir> #include <QDir>
#include <QFileInfo> #include <QFileInfo>
#include <QImage> #include <QImage>
#include <QPen> #include <QPen>
#include <QtDebug>
namespace glabels namespace glabels
@@ -39,7 +40,7 @@ namespace glabels
/// ///
/// Static data /// Static data
/// ///
QImage* ModelImageObject::smDefaultImage = nullptr; QImage ModelImageObject::smDefaultImage( ":images/checkerboard.png" );
// //
@@ -56,23 +57,18 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
ModelImageObject::ModelImageObject() : mImage(nullptr), mSvgRenderer(nullptr) ModelImageObject::ModelImageObject()
{ {
mOutline = new Outline( this ); mOutline.setOwner( this );
mHandles << new HandleNorthWest( this ); mHandles.push_back( Handle( this, Handle::NW ) );
mHandles << new HandleNorth( this ); mHandles.push_back( Handle( this, Handle::N ) );
mHandles << new HandleNorthEast( this ); mHandles.push_back( Handle( this, Handle::NE ) );
mHandles << new HandleEast( this ); mHandles.push_back( Handle( this, Handle::E ) );
mHandles << new HandleSouthEast( this ); mHandles.push_back( Handle( this, Handle::SE ) );
mHandles << new HandleSouth( this ); mHandles.push_back( Handle( this, Handle::S ) );
mHandles << new HandleSouthWest( this ); mHandles.push_back( Handle( this, Handle::SW ) );
mHandles << new HandleWest( this ); mHandles.push_back( Handle( this, Handle::W ) );
if ( smDefaultImage == nullptr )
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
mLockAspectRatio = true; mLockAspectRatio = true;
} }
@@ -81,43 +77,43 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
ModelImageObject::ModelImageObject( const Distance& x0, ModelImageObject::ModelImageObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const TextNode& filenameNode, const TextNode& filenameNode,
const QTransform& matrix, const QTransform& matrix,
bool shadowState, bool shadowState,
const Distance& shadowX, Distance shadowX,
const Distance& shadowY, Distance shadowY,
double shadowOpacity, double shadowOpacity,
const ColorNode& shadowColorNode ) const ColorNode& shadowColorNode )
: ModelObject( x0, y0, w, h, lockAspectRatio, : ModelObject( x0,
y0,
w,
h,
lockAspectRatio,
matrix, matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode ) shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{ {
mOutline = new Outline( this ); mOutline.setOwner( this );
mHandles << new HandleNorthWest( this ); mHandles.push_back( Handle( this, Handle::NW ) );
mHandles << new HandleNorth( this ); mHandles.push_back( Handle( this, Handle::N ) );
mHandles << new HandleNorthEast( this ); mHandles.push_back( Handle( this, Handle::NE ) );
mHandles << new HandleEast( this ); mHandles.push_back( Handle( this, Handle::E ) );
mHandles << new HandleSouthEast( this ); mHandles.push_back( Handle( this, Handle::SE ) );
mHandles << new HandleSouth( this ); mHandles.push_back( Handle( this, Handle::S ) );
mHandles << new HandleSouthWest( this ); mHandles.push_back( Handle( this, Handle::SW ) );
mHandles << new HandleWest( this ); mHandles.push_back( Handle( this, Handle::W ) );
if ( smDefaultImage == nullptr )
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
mFilenameNode = filenameNode; mFilenameNode = filenameNode;
mImage = nullptr;
mSvgRenderer = nullptr;
loadImage(); loadImage();
} }
@@ -125,85 +121,92 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
ModelImageObject::ModelImageObject( const Distance& x0, ModelImageObject::ModelImageObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const QString& filename, const QString& filename,
const QImage& image, const QImage& image,
const QTransform& matrix, const QTransform& matrix,
bool shadowState, bool shadowState,
const Distance& shadowX, Distance shadowX,
const Distance& shadowY, Distance shadowY,
double shadowOpacity, double shadowOpacity,
const ColorNode& shadowColorNode ) const ColorNode& shadowColorNode )
: ModelObject( x0, y0, w, h, lockAspectRatio, : ModelObject( x0,
y0,
w,
h,
lockAspectRatio,
matrix, matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode ) shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{ {
mOutline = new Outline( this ); mOutline.setOwner( this );
mHandles << new HandleNorthWest( this ); mHandles.push_back( Handle( this, Handle::NW ) );
mHandles << new HandleNorth( this ); mHandles.push_back( Handle( this, Handle::N ) );
mHandles << new HandleNorthEast( this ); mHandles.push_back( Handle( this, Handle::NE ) );
mHandles << new HandleEast( this ); mHandles.push_back( Handle( this, Handle::E ) );
mHandles << new HandleSouthEast( this ); mHandles.push_back( Handle( this, Handle::SE ) );
mHandles << new HandleSouth( this ); mHandles.push_back( Handle( this, Handle::S ) );
mHandles << new HandleSouthWest( this ); mHandles.push_back( Handle( this, Handle::SW ) );
mHandles << new HandleWest( this ); mHandles.push_back( Handle( this, Handle::W ) );
if ( smDefaultImage == nullptr ) mImage = image;
{
smDefaultImage = new QImage( ":images/checkerboard.png" );
}
mImage = new QImage(image);
mFilenameNode = TextNode( false, filename ); mFilenameNode = TextNode( false, filename );
mSvgRenderer = nullptr;
} }
/// ///
/// Constructor /// Constructor
/// ///
ModelImageObject::ModelImageObject( const Distance& x0, ModelImageObject::ModelImageObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const QString& filename, const QString& filename,
const QByteArray& svg, const QByteArray& svg,
const QTransform& matrix, const QTransform& matrix,
bool shadowState, bool shadowState,
const Distance& shadowX, Distance shadowX,
const Distance& shadowY, Distance shadowY,
double shadowOpacity, double shadowOpacity,
const ColorNode& shadowColorNode ) const ColorNode& shadowColorNode )
: ModelObject( x0, y0, w, h, lockAspectRatio, : ModelObject( x0,
y0,
w,
h,
lockAspectRatio,
matrix, matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode ) shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{ {
mOutline = new Outline( this ); mOutline.setOwner( this );
mHandles << new HandleNorthWest( this ); mHandles.push_back( Handle( this, Handle::NW ) );
mHandles << new HandleNorth( this ); mHandles.push_back( Handle( this, Handle::N ) );
mHandles << new HandleNorthEast( this ); mHandles.push_back( Handle( this, Handle::NE ) );
mHandles << new HandleEast( this ); mHandles.push_back( Handle( this, Handle::E ) );
mHandles << new HandleSouthEast( this ); mHandles.push_back( Handle( this, Handle::SE ) );
mHandles << new HandleSouth( this ); mHandles.push_back( Handle( this, Handle::S ) );
mHandles << new HandleSouthWest( this ); mHandles.push_back( Handle( this, Handle::SW ) );
mHandles << new HandleWest( this ); 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 ); mFilenameNode = TextNode( false, filename );
mImage = nullptr;
} }
@@ -213,50 +216,11 @@ namespace glabels
ModelImageObject::ModelImageObject( const ModelImageObject* object ) : ModelObject(object) ModelImageObject::ModelImageObject( const ModelImageObject* object ) : ModelObject(object)
{ {
mFilenameNode = object->mFilenameNode; mFilenameNode = object->mFilenameNode;
if ( object->mImage ) mImage = object->mImage;
{
mImage = new QImage( *object->mImage );
}
else
{
mImage = nullptr;
}
if ( object->mSvgRenderer )
{
mSvgRenderer = new QSvgRenderer( object->mSvg );
}
else
{
mSvgRenderer = nullptr;
}
mSvg = object->mSvg; 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 /// Clone
/// ///
@@ -293,7 +257,7 @@ namespace glabels
/// ///
/// Image image Property Getter /// Image image Property Getter
/// ///
const QImage* ModelImageObject::image() const const QImage& ModelImageObject::image() const
{ {
return mImage; return mImage;
} }
@@ -306,19 +270,10 @@ namespace glabels
{ {
if ( !value.isNull() ) if ( !value.isNull() )
{ {
if ( mImage ) mSvg.clear();
{
delete mImage;
mImage = nullptr;
}
if ( mSvgRenderer )
{
delete mSvgRenderer;
mSvgRenderer = nullptr;
}
mImage = new QImage(value); mImage = value;
quint16 cs = qChecksum( QByteArray( (const char*)mImage->constBits(), mImage->sizeInBytes() ) ); quint16 cs = qChecksum( QByteArray( (const char*)mImage.constBits(), mImage.sizeInBytes() ) );
mFilenameNode = TextNode( false, QString("%image_%1%").arg( cs ) ); mFilenameNode = TextNode( false, QString("%image_%1%").arg( cs ) );
emit changed(); emit changed();
@@ -333,18 +288,9 @@ namespace glabels
{ {
if ( !value.isNull() ) if ( !value.isNull() )
{ {
if ( mImage ) mSvg.clear();
{
delete mImage;
mImage = nullptr;
}
if ( mSvgRenderer )
{
delete mSvgRenderer;
mSvgRenderer = nullptr;
}
mImage = new QImage(value); mImage = value;
mFilenameNode = TextNode( false, name ); mFilenameNode = TextNode( false, name );
emit changed(); emit changed();
@@ -355,7 +301,7 @@ namespace glabels
/// ///
/// Image svg Property Getter /// Image svg Property Getter
/// ///
QByteArray ModelImageObject::svg() const const QByteArray& ModelImageObject::svg() const
{ {
return mSvg; return mSvg;
} }
@@ -368,19 +314,13 @@ namespace glabels
{ {
if ( !value.isEmpty() ) if ( !value.isEmpty() )
{ {
if ( mImage ) mImage = QImage(); // clear
{ mSvg.clear();
delete mImage;
mImage = nullptr;
}
if ( mSvgRenderer )
{
delete mSvgRenderer;
mSvgRenderer = nullptr;
}
mSvg = value; if ( QSvgRenderer( value ).isValid() )
mSvgRenderer = new QSvgRenderer( mSvg ); {
mSvg = value;
}
mFilenameNode = TextNode( false, name ); mFilenameNode = TextNode( false, name );
emit changed(); emit changed();
@@ -395,15 +335,15 @@ namespace glabels
{ {
Size size( Distance::pt(72), Distance::pt(72) ); 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.setW( Distance::pt( qsize.width() ) );
size.setH( Distance::pt( qsize.height() ) ); 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.setW( Distance::pt( qsize.width() ) );
size.setH( Distance::pt( qsize.height() ) ); size.setH( Distance::pt( qsize.height() ) );
} }
@@ -415,23 +355,22 @@ namespace glabels
/// ///
/// Draw shadow of object /// Draw shadow of object
/// ///
void ModelImageObject::drawShadow( QPainter* painter, void ModelImageObject::drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
QRectF destRect( 0, 0, mW.pt(), mH.pt() ); QRectF destRect( 0, 0, mW.pt(), mH.pt() );
QColor shadowColor = mShadowColorNode.color( record, variables ); QColor shadowColor = mShadowColorNode.color( record, variables );
shadowColor.setAlphaF( mShadowOpacity ); shadowColor.setAlphaF( mShadowOpacity );
if ( mImage && mImage->hasAlphaChannel() && (mImage->depth() == 32) ) if ( !mImage.isNull() && mImage.hasAlphaChannel() && (mImage.depth() == 32) )
{ {
QImage* shadowImage = createShadowImage( *mImage, shadowColor ); auto shadowImage = createShadowImage( mImage, shadowColor );
painter->drawImage( destRect, *shadowImage ); painter->drawImage( destRect, shadowImage );
delete shadowImage;
} }
else if ( mImage || mSvgRenderer || inEditor ) else if ( !mImage.isNull() || !mSvg.isEmpty() || inEditor )
{ {
painter->setBrush( shadowColor ); painter->setBrush( shadowColor );
painter->setPen( QPen( Qt::NoPen ) ); painter->setPen( QPen( Qt::NoPen ) );
@@ -441,16 +380,14 @@ namespace glabels
else else
{ {
QString filename = mFilenameNode.text( record, variables ).trimmed(); QString filename = mFilenameNode.text( record, variables ).trimmed();
QImage* image; QImage image;
QSvgRenderer* svgRenderer;
QByteArray svg; 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 ); QImage shadowImage = createShadowImage( image, shadowColor );
painter->drawImage( destRect, *shadowImage ); painter->drawImage( destRect, shadowImage );
delete shadowImage;
} }
else else
{ {
@@ -459,14 +396,6 @@ namespace glabels
painter->drawRect( destRect ); painter->drawRect( destRect );
} }
if ( image )
{
delete image;
}
else
{
delete svgRenderer;
}
} }
} }
} }
@@ -475,21 +404,21 @@ namespace glabels
/// ///
/// Draw object itself /// Draw object itself
/// ///
void ModelImageObject::drawObject( QPainter* painter, void ModelImageObject::drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
QRectF destRect( 0, 0, mW.pt(), mH.pt() ); 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 // Render default place holder image
// //
painter->save(); painter->save();
painter->setRenderHint( QPainter::SmoothPixmapTransform, false ); painter->setRenderHint( QPainter::SmoothPixmapTransform, false );
painter->drawImage( destRect, *smDefaultImage ); painter->drawImage( destRect, smDefaultImage );
painter->restore(); painter->restore();
// //
@@ -540,31 +469,28 @@ namespace glabels
labelText ); 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() ) else if ( mFilenameNode.isField() )
{ {
QString filename = mFilenameNode.text( record, variables ).trimmed(); QString filename = mFilenameNode.text( record, variables ).trimmed();
QImage* image; QImage image;
QSvgRenderer* svgRenderer;
QByteArray svg; QByteArray svg;
if ( readImageFile( filename, image, svgRenderer, svg ) ) if ( readImageFile( filename, image, svg ) )
{ {
if ( image ) if ( !image.isNull() )
{ {
painter->drawImage( destRect, *image ); painter->drawImage( destRect, image );
delete image;
} }
else else if ( !svg.isEmpty() )
{ {
svgRenderer->render( painter, destRect ); QSvgRenderer( svg ).render( painter, destRect );
delete svgRenderer;
} }
} }
} }
@@ -588,34 +514,26 @@ namespace glabels
/// ///
void ModelImageObject::loadImage() void ModelImageObject::loadImage()
{ {
if ( mImage ) mImage = QImage(); // clear
{ mSvg.clear();
delete mImage;
mImage = nullptr;
}
if ( mSvgRenderer )
{
delete mSvgRenderer;
mSvgRenderer = nullptr;
}
if ( !mFilenameNode.isField() ) if ( !mFilenameNode.isField() )
{ {
QString filename = mFilenameNode.data(); QString filename = mFilenameNode.data();
if ( readImageFile( filename, mImage, mSvgRenderer, mSvg ) ) if ( readImageFile( filename, mImage, mSvg ) )
{ {
double aspectRatio = 0; double aspectRatio = 0;
if ( mSvgRenderer ) if ( !mSvg.isEmpty() )
{ {
// Adjust size based on aspect ratio of SVG image // 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; aspectRatio = rect.width() ? rect.height() / rect.width() : 0;
} }
else else
{ {
// Adjust size based on aspect ratio of image // Adjust size based on aspect ratio of image
double imageW = mImage->width(); double imageW = mImage.width();
double imageH = mImage->height(); double imageH = mImage.height();
aspectRatio = imageW ? imageH / imageW : 0; aspectRatio = imageW ? imageH / imageW : 0;
} }
@@ -639,12 +557,10 @@ namespace glabels
/// Read an image or svg file /// Read an image or svg file
/// ///
bool ModelImageObject::readImageFile( const QString& fileName, bool ModelImageObject::readImageFile( const QString& fileName,
QImage*& image, QImage& image,
QSvgRenderer*& svgRenderer,
QByteArray& svg ) const QByteArray& svg ) const
{ {
image = nullptr; image = QImage(); // clear
svgRenderer = nullptr;
svg.clear(); svg.clear();
if ( !fileName.isEmpty() ) if ( !fileName.isEmpty() )
@@ -667,48 +583,41 @@ namespace glabels
{ {
svg = file.readAll(); svg = file.readAll();
file.close(); file.close();
svgRenderer = new QSvgRenderer( svg ); QSvgRenderer renderer( svg );
if ( !svgRenderer->isValid() ) if ( !renderer.isValid() )
{ {
delete svgRenderer;
svgRenderer = nullptr;
svg.clear(); svg.clear();
} }
} }
} }
else else
{ {
image = new QImage( fileInfo.filePath() ); image = QImage( fileInfo.filePath() );
if ( image->isNull() )
{
delete image;
image = nullptr;
}
} }
} }
} }
return image != nullptr || svgRenderer != nullptr; return !image.isNull() || !svg.isEmpty();
} }
/// ///
/// Create shadow image /// Create shadow image
/// ///
QImage* ModelImageObject::createShadowImage( const QImage& image, QImage ModelImageObject::createShadowImage( const QImage& image,
const QColor& color ) const const QColor& color ) const
{ {
int r = color.red(); int r = color.red();
int g = color.green(); int g = color.green();
int b = color.blue(); int b = color.blue();
int a = color.alpha(); int a = color.alpha();
auto* shadow = new QImage( image ); QImage shadow = image;
for ( int iy = 0; iy < shadow->height(); iy++ ) 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 ); scanLine[ix] = qRgba( r, g, b, (a*qAlpha(scanLine[ix]))/255 );
} }
+47 -49
View File
@@ -45,50 +45,50 @@ namespace glabels
public: public:
ModelImageObject(); ModelImageObject();
ModelImageObject( const Distance& x0, ModelImageObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const TextNode& filenameNode, const TextNode& filenameNode,
const QTransform& matrix = QTransform(), const QTransform& matrix = QTransform(),
bool shadowState = false, bool shadowState = false,
const Distance& shadowX = 0, Distance shadowX = 0,
const Distance& shadowY = 0, Distance shadowY = 0,
double shadowOpacity = 1.0, double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() ); const ColorNode& shadowColorNode = ColorNode() );
ModelImageObject( const Distance& x0, ModelImageObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const QString& filename, const QString& filename,
const QImage& image, const QImage& image,
const QTransform& matrix = QTransform(), const QTransform& matrix = QTransform(),
bool shadowState = false, bool shadowState = false,
const Distance& shadowX = 0, Distance shadowX = 0,
const Distance& shadowY = 0, Distance shadowY = 0,
double shadowOpacity = 1.0, double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() ); const ColorNode& shadowColorNode = ColorNode() );
ModelImageObject( const Distance& x0, ModelImageObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const QString& filename, const QString& filename,
const QByteArray& svg, const QByteArray& svg,
const QTransform& matrix = QTransform(), const QTransform& matrix = QTransform(),
bool shadowState = false, bool shadowState = false,
const Distance& shadowX = 0, Distance shadowX = 0,
const Distance& shadowY = 0, Distance shadowY = 0,
double shadowOpacity = 1.0, double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() ); const ColorNode& shadowColorNode = ColorNode() );
ModelImageObject( const ModelImageObject* object ); ModelImageObject( const ModelImageObject* object );
~ModelImageObject() override; virtual ~ModelImageObject() = default;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@@ -110,14 +110,14 @@ namespace glabels
// //
// Image Property: image // Image Property: image
// //
const QImage* image() const override; const QImage& image() const override;
void setImage( const QImage& value ) override; void setImage( const QImage& value ) override;
void setImage( const QString& name, const QImage& value ) override; void setImage( const QString& name, const QImage& value ) override;
// //
// Image Property: svg // Image Property: svg
// //
QByteArray svg() const override; const QByteArray& svg() const override;
void setSvg( const QString& name, const QByteArray& value ) override; void setSvg( const QString& name, const QByteArray& value ) override;
// //
@@ -135,15 +135,15 @@ namespace glabels
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
void drawShadow( QPainter* painter, void drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
void drawObject( QPainter* painter, void drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override; QPainterPath hoverPath( double scale ) const override;
@@ -154,24 +154,22 @@ namespace glabels
void loadImage(); void loadImage();
bool readImageFile( const QString& fileName, bool readImageFile( const QString& fileName,
QImage*& image, QImage& image,
QSvgRenderer*& svgRenderer,
QByteArray& svg ) const; QByteArray& svg ) const;
QImage* createShadowImage( const QImage& image, QImage createShadowImage( const QImage& image,
const QColor& color ) const; const QColor& color ) const;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
// Private Members // Private Members
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
TextNode mFilenameNode; TextNode mFilenameNode;
QImage* mImage; QImage mImage;
QSvgRenderer* mSvgRenderer; QByteArray mSvg;
QByteArray mSvg;
static QImage* smDefaultImage; static QImage smDefaultImage;
}; };
+35 -49
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ModelLineObject.h" #include "ModelLineObject.h"
#include <QBrush> #include <QBrush>
@@ -43,10 +44,8 @@ namespace glabels
/// ///
ModelLineObject::ModelLineObject() ModelLineObject::ModelLineObject()
{ {
mOutline = nullptr; mHandles.push_back( Handle( this, Handle::P1 ) );
mHandles.push_back( Handle( this, Handle::P2 ) );
mHandles << new HandleP1( this );
mHandles << new HandleP2( this );
mLineWidth = 1.0; mLineWidth = 1.0;
mLineColorNode = ColorNode( QColor( 0, 0, 0 ) ); mLineColorNode = ColorNode( QColor( 0, 0, 0 ) );
@@ -56,32 +55,32 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
ModelLineObject::ModelLineObject( const Distance& x0, ModelLineObject::ModelLineObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& dx, Distance dx,
const Distance& dy, Distance dy,
const Distance& lineWidth, Distance lineWidth,
const ColorNode& lineColorNode, const ColorNode& lineColorNode,
const QTransform& matrix, const QTransform& matrix,
bool shadowState, bool shadowState,
const Distance& shadowX, Distance shadowX,
const Distance& shadowY, Distance shadowY,
double shadowOpacity, double shadowOpacity,
const ColorNode& shadowColorNode ) const ColorNode& shadowColorNode )
: ModelObject( x0, y0, dx, dy, false /*lockAspectRatio*/, : ModelObject( x0,
y0,
dx,
dy,
false /*lockAspectRatio*/,
matrix, matrix,
shadowState, shadowX, shadowY, shadowOpacity, shadowColorNode ) shadowState,
shadowX,
shadowY,
shadowOpacity,
shadowColorNode )
{ {
mOutline = new Outline( this ); mHandles.push_back( Handle( this, Handle::P1 ) );
mHandles.push_back( Handle( this, Handle::P2 ) );
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 );
mLineWidth = lineWidth; mLineWidth = lineWidth;
mLineColorNode = lineColorNode; mLineColorNode = lineColorNode;
@@ -99,19 +98,6 @@ namespace glabels
} }
///
/// Destructor
///
ModelLineObject::~ModelLineObject()
{
foreach( Handle* handle, mHandles )
{
delete handle;
}
mHandles.clear();
}
/// ///
/// Clone /// Clone
/// ///
@@ -133,7 +119,7 @@ namespace glabels
/// ///
/// Line Width Property Setter /// Line Width Property Setter
/// ///
void ModelLineObject::setLineWidth( const Distance& value ) void ModelLineObject::setLineWidth( Distance value )
{ {
if ( mLineWidth != value ) if ( mLineWidth != value )
{ {
@@ -186,10 +172,10 @@ namespace glabels
/// ///
/// Draw shadow of object /// Draw shadow of object
/// ///
void ModelLineObject::drawShadow( QPainter* painter, void ModelLineObject::drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
QColor lineColor = mLineColorNode.color( record, variables ); QColor lineColor = mLineColorNode.color( record, variables );
QColor shadowColor = mShadowColorNode.color( record, variables ); QColor shadowColor = mShadowColorNode.color( record, variables );
@@ -207,10 +193,10 @@ namespace glabels
/// ///
/// Draw object itself /// Draw object itself
/// ///
void ModelLineObject::drawObject( QPainter* painter, void ModelLineObject::drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
QColor lineColor = mLineColorNode.color( record, variables ); QColor lineColor = mLineColorNode.color( record, variables );
+21 -21
View File
@@ -43,22 +43,22 @@ namespace glabels
public: public:
ModelLineObject(); ModelLineObject();
ModelLineObject( const Distance& x0, ModelLineObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
const Distance& lineWidth, Distance lineWidth,
const ColorNode& lineColorNode, const ColorNode& lineColorNode,
const QTransform& matrix = QTransform(), const QTransform& matrix = QTransform(),
bool shadowState = false, bool shadowState = false,
const Distance& shadowX = 0, Distance shadowX = 0,
const Distance& shadowY = 0, Distance shadowY = 0,
double shadowOpacity = 1.0, double shadowOpacity = 1.0,
const ColorNode& shadowColorNode = ColorNode() ); const ColorNode& shadowColorNode = ColorNode() );
ModelLineObject( const ModelLineObject* object ); ModelLineObject( const ModelLineObject* object );
~ModelLineObject() override; virtual ~ModelLineObject() = default;
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
@@ -75,7 +75,7 @@ namespace glabels
// Line Property: lineWidth // Line Property: lineWidth
// //
Distance lineWidth() const override; Distance lineWidth() const override;
void setLineWidth( const Distance& value ) override; void setLineWidth( Distance value ) override;
// //
@@ -97,15 +97,15 @@ namespace glabels
// Drawing operations // Drawing operations
/////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////
protected: protected:
void drawShadow( QPainter* painter, void drawShadow( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
void drawObject( QPainter* painter, void drawObject( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const override; const Variables& variables ) const override;
QPainterPath hoverPath( double scale ) const override; QPainterPath hoverPath( double scale ) const override;
+63 -75
View File
@@ -18,6 +18,7 @@
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>. * along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "ModelObject.h" #include "ModelObject.h"
#include "ColorNode.h" #include "ColorNode.h"
@@ -43,7 +44,8 @@ namespace glabels
/// ///
/// Constructor /// Constructor
/// ///
ModelObject::ModelObject() : QObject(nullptr) ModelObject::ModelObject()
: QObject(nullptr)
{ {
mId = msNextId++; mId = msNextId++;
@@ -61,25 +63,24 @@ namespace glabels
mShadowOpacity = 0.5; mShadowOpacity = 0.5;
mSelectedFlag = false; mSelectedFlag = false;
mOutline = nullptr;
} }
/// ///
/// Constructor /// Constructor
/// ///
ModelObject::ModelObject( const Distance& x0, ModelObject::ModelObject( Distance x0,
const Distance& y0, Distance y0,
const Distance& w, Distance w,
const Distance& h, Distance h,
bool lockAspectRatio, bool lockAspectRatio,
const QTransform& matrix, const QTransform& matrix,
bool shadowState, bool shadowState,
const Distance& shadowX, Distance shadowX,
const Distance& shadowY, Distance shadowY,
double shadowOpacity, double shadowOpacity,
const ColorNode& shadowColorNode ) : QObject(nullptr) const ColorNode& shadowColorNode )
: QObject(nullptr)
{ {
mId = msNextId++; mId = msNextId++;
@@ -97,8 +98,6 @@ namespace glabels
mShadowOpacity = shadowOpacity; mShadowOpacity = shadowOpacity;
mSelectedFlag = false; mSelectedFlag = false;
mOutline = nullptr;
} }
@@ -123,33 +122,21 @@ namespace glabels
mShadowOpacity = object->mShadowOpacity; mShadowOpacity = object->mShadowOpacity;
mShadowColorNode = object->mShadowColorNode; mShadowColorNode = object->mShadowColorNode;
foreach ( Handle* handle, object->mHandles ) if ( object->mOutline.isEnabled() )
{ {
mHandles.append( handle->clone( this ) ); mOutline = object->mOutline;
mOutline.setOwner( this );
} }
if ( object->mOutline ) for ( auto& handle : object->mHandles )
{ {
mOutline = object->mOutline->clone( this ); mHandles.push_back( Handle( this, handle.location() ) );
}
else
{
mOutline = nullptr;
} }
mMatrix = object->mMatrix; mMatrix = object->mMatrix;
} }
///
/// Destructor
///
ModelObject::~ModelObject()
{
// empty
}
/// ///
/// ID Property Getter /// ID Property Getter
/// ///
@@ -198,7 +185,7 @@ namespace glabels
/// ///
/// X0 Property Setter /// X0 Property Setter
/// ///
void ModelObject::setX0( const Distance& value ) void ModelObject::setX0( Distance value )
{ {
if ( mX0 != value ) if ( mX0 != value )
{ {
@@ -220,7 +207,7 @@ namespace glabels
/// ///
/// Y0 Property Setter /// Y0 Property Setter
/// ///
void ModelObject::setY0( const Distance& value ) void ModelObject::setY0( Distance value )
{ {
if ( mY0 != value ) if ( mY0 != value )
{ {
@@ -242,7 +229,7 @@ namespace glabels
/// ///
/// W (Width) Property Setter /// W (Width) Property Setter
/// ///
void ModelObject::setW( const Distance& value ) void ModelObject::setW( Distance value )
{ {
if ( mW != value ) if ( mW != value )
{ {
@@ -265,7 +252,7 @@ namespace glabels
/// ///
/// H (Height) Property Setter /// H (Height) Property Setter
/// ///
void ModelObject::setH( const Distance& value ) void ModelObject::setH( Distance value )
{ {
if ( mH != value ) if ( mH != value )
{ {
@@ -354,7 +341,7 @@ namespace glabels
/// ///
/// Shadow X Property Setter /// Shadow X Property Setter
/// ///
void ModelObject::setShadowX( const Distance& value ) void ModelObject::setShadowX( Distance value )
{ {
if ( mShadowX != value ) if ( mShadowX != value )
{ {
@@ -376,7 +363,7 @@ namespace glabels
/// ///
/// Shadow Y Property Setter /// Shadow Y Property Setter
/// ///
void ModelObject::setShadowY( const Distance& value ) void ModelObject::setShadowY( Distance value )
{ {
if ( mShadowY != value ) if ( mShadowY != value )
{ {
@@ -704,9 +691,10 @@ namespace glabels
/// Virtual Image Property Default Getter /// Virtual Image Property Default Getter
/// (Overridden by concrete class) /// (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 /// Virtual SVG Property Default Getter
/// (Overridden by concrete class) /// (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 /// Virtual Line Width Property Default Setter
/// (Overridden by concrete class) /// (Overridden by concrete class)
/// ///
void ModelObject::setLineWidth( const Distance& value ) void ModelObject::setLineWidth( Distance value )
{ {
// empty // empty
} }
@@ -973,8 +962,8 @@ namespace glabels
/// ///
/// Set Absolute Position /// Set Absolute Position
/// ///
void ModelObject::setPosition( const Distance& x0, void ModelObject::setPosition( Distance x0,
const Distance& y0 ) Distance y0 )
{ {
if ( ( mX0 != x0 ) || ( mY0 != y0 ) ) if ( ( mX0 != x0 ) || ( mY0 != y0 ) )
{ {
@@ -989,8 +978,8 @@ namespace glabels
/// ///
/// Set Relative Position /// Set Relative Position
/// ///
void ModelObject::setPositionRelative( const Distance& dx, void ModelObject::setPositionRelative( Distance dx,
const Distance& dy ) Distance dy )
{ {
if ( ( dx != 0 ) || ( dy != 0 ) ) if ( ( dx != 0 ) || ( dy != 0 ) )
{ {
@@ -1014,8 +1003,8 @@ namespace glabels
/// ///
/// Set Size /// Set Size
/// ///
void ModelObject::setSize( const Distance& w, void ModelObject::setSize( Distance w,
const Distance& h ) Distance h )
{ {
mW = w; mW = w;
mH = h; mH = h;
@@ -1028,7 +1017,7 @@ namespace glabels
/// ///
/// Set Size /// Set Size
/// ///
void ModelObject::setSize( const Size& size ) void ModelObject::setSize( Size size )
{ {
mW = size.w(); mW = size.w();
mH = size.h(); mH = size.h();
@@ -1041,8 +1030,8 @@ namespace glabels
/// ///
/// Set Size (But Maintain Current Aspect Ratio) /// Set Size (But Maintain Current Aspect Ratio)
/// ///
void ModelObject::setSizeHonorAspect( const Distance& w, void ModelObject::setSizeHonorAspect( Distance w,
const Distance& h ) Distance h )
{ {
double aspectRatio = mH / mW; double aspectRatio = mH / mW;
Distance wNew = w; Distance wNew = w;
@@ -1064,7 +1053,7 @@ namespace glabels
/// ///
/// Set Width (But Maintain Current Aspect Ratio) /// Set Width (But Maintain Current Aspect Ratio)
/// ///
void ModelObject::setWHonorAspect( const Distance& w ) void ModelObject::setWHonorAspect( Distance w )
{ {
double aspectRatio = mH / mW; double aspectRatio = mH / mW;
Distance h = w * aspectRatio; Distance h = w * aspectRatio;
@@ -1083,7 +1072,7 @@ namespace glabels
/// ///
/// Set Height (But Maintain Current Aspect Ratio) /// Set Height (But Maintain Current Aspect Ratio)
/// ///
void ModelObject::setHHonorAspect( const Distance& h ) void ModelObject::setHHonorAspect( Distance h )
{ {
double aspectRatio = mH / mW; double aspectRatio = mH / mW;
Distance w = h / aspectRatio; Distance w = h / aspectRatio;
@@ -1169,9 +1158,9 @@ namespace glabels
/// ///
/// Is this object located at x,y? /// Is this object located at x,y?
/// ///
bool ModelObject::isLocatedAt( double scale, bool ModelObject::isLocatedAt( double scale,
const Distance& x, Distance x,
const Distance& y ) const Distance y ) const
{ {
QPointF p( x.pt(), y.pt() ); QPointF p( x.pt(), y.pt() );
@@ -1185,9 +1174,9 @@ namespace glabels
{ {
return true; return true;
} }
else if ( isSelected() && mOutline ) else if ( isSelected() )
{ {
if ( mOutline->hoverPath( scale ).contains( p ) ) if ( mOutline.hoverPath( scale ).contains( p ) )
{ {
return true; return true;
} }
@@ -1200,18 +1189,20 @@ namespace glabels
/// ///
/// Is one of this object's handles locate at x,y? If so, return it. /// Is one of this object's handles locate at x,y? If so, return it.
/// ///
Handle* ModelObject::handleAt( double scale, const Handle& ModelObject::handleAt( double scale,
const Distance& x, Distance x,
const Distance& y ) const Distance y ) const
{ {
static Handle nullHandle;
if ( mSelectedFlag ) if ( mSelectedFlag )
{ {
QPointF p( x.pt(), y.pt() ); QPointF p( x.pt(), y.pt() );
p -= QPointF( mX0.pt(), mY0.pt() ); // Translate point to x0,y0 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 ) ) if ( handlePath.contains( p ) )
{ {
return handle; return handle;
@@ -1219,17 +1210,17 @@ namespace glabels
} }
} }
return nullptr; return nullHandle;
} }
/// ///
/// Draw object + shadow /// Draw object + shadow
/// ///
void ModelObject::draw( QPainter* painter, void ModelObject::draw( QPainter* painter,
bool inEditor, bool inEditor,
merge::Record* record, const merge::Record& record,
Variables* variables ) const const Variables& variables ) const
{ {
painter->save(); painter->save();
painter->translate( mX0.pt(), mY0.pt() ); painter->translate( mX0.pt(), mY0.pt() );
@@ -1260,14 +1251,11 @@ namespace glabels
painter->translate( mX0.pt(), mY0.pt() ); painter->translate( mX0.pt(), mY0.pt() );
painter->setTransform( mMatrix, true ); 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(); painter->restore();

Some files were not shown because too many files have changed in this diff Show More