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

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