From cf1c194928166409d96428f72b9a1ef80d4e3cfe Mon Sep 17 00:00:00 2001 From: Jim Evins Date: Sat, 26 Sep 2015 10:45:49 -0400 Subject: [PATCH] Added Merge base class. --- glabels/CMakeLists.txt | 2 + glabels/Merge.cpp | 127 +++++++++++++++++++++++++++++++++++ glabels/Merge.h | 147 +++++++++++++++++++++++++++++++++++++++++ glabels/MergeRecord.h | 15 +++-- 4 files changed, 287 insertions(+), 4 deletions(-) create mode 100644 glabels/Merge.cpp create mode 100644 glabels/Merge.h diff --git a/glabels/CMakeLists.txt b/glabels/CMakeLists.txt index cea1482..b8fe177 100644 --- a/glabels/CMakeLists.txt +++ b/glabels/CMakeLists.txt @@ -30,6 +30,7 @@ set (glabels_sources LabelModelShapeObject.cpp LabelRegion.cpp MainWindow.cpp + Merge.cpp MergeField.cpp MergePropertyEditor.cpp MergeRecord.cpp @@ -67,6 +68,7 @@ set (glabels_qobject_headers LabelModelBoxObject.h LabelModelShapeObject.h MainWindow.h + Merge.h MergePropertyEditor.h NewLabelDialog.h ObjectEditor.h diff --git a/glabels/Merge.cpp b/glabels/Merge.cpp new file mode 100644 index 0000000..7d20052 --- /dev/null +++ b/glabels/Merge.cpp @@ -0,0 +1,127 @@ +/* Merge.cpp + * + * Copyright (C) 2015 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#include "Merge.h" + + +namespace glabels +{ + + /// + /// Constructor + /// + Merge::Merge( QString id, QString name, SourceType type ) + : mId(id), mName(name), mType(type) + { + } + + + /// + /// Set source + /// + void Merge::setSource( const QString& source ) + { + mSource = source; + + // Clear out any old records + foreach ( MergeRecord* record, mRecordList ) + { + delete record; + } + mRecordList.clear(); + + open(); + for ( MergeRecord* record = readNextRecord(); record != 0; record = readNextRecord() ) + { + mRecordList.append( record ); + } + close(); + + emit sourceChanged(); + } + + + /// + /// Select matching record + /// + void Merge::select( MergeRecord* record ) + { + record->setSelected( true ); + emit selectionChanged(); + } + + + /// + /// Unselect matching record + /// + void Merge::unselect( MergeRecord* record ) + { + record->setSelected( false ); + emit selectionChanged(); + } + + + /// + /// Select all records + /// + void Merge::selectAll() + { + foreach ( MergeRecord* record, mRecordList ) + { + record->setSelected( true ); + } + emit selectionChanged(); + } + + + /// + /// Unselect all records + /// + void Merge::unselectAll() + { + foreach ( MergeRecord* record, mRecordList ) + { + record->setSelected( false ); + } + emit selectionChanged(); + } + + + /// + /// Return list of selected records + /// + const QList Merge::selectedRecords() const + { + QList list; + + foreach ( MergeRecord* record, mRecordList ) + { + if ( record->isSelected() ) + { + list.append( record ); + } + } + + return list; + } + +} + + diff --git a/glabels/Merge.h b/glabels/Merge.h new file mode 100644 index 0000000..ab199e6 --- /dev/null +++ b/glabels/Merge.h @@ -0,0 +1,147 @@ +/* Merge.h + * + * Copyright (C) 2015 Jim Evins + * + * This file is part of gLabels-qt. + * + * gLabels-qt is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels-qt is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels-qt. If not, see . + */ + +#ifndef glabels_Merge_h +#define glabels_Merge_h + +#include +#include +#include + +#include "MergeRecord.h" + + +namespace glabels +{ + + /// + /// Merge Record Structure + /// + struct Merge : QObject + { + Q_OBJECT + + + ///////////////////////////////// + // Source Type + ///////////////////////////////// + enum SourceType { NONE, FIXED, FILE }; + + + ///////////////////////////////// + // Life Cycle + ///////////////////////////////// + protected: + Merge( QString id, QString name, SourceType type ); + + + ///////////////////////////////// + // Properties + ///////////////////////////////// + public: + inline QString id() const; + inline QString name() const; + inline SourceType type() const; + inline QString source() const; + void setSource( const QString& source ); + + inline const QList& recordList( void ) const; + + + ///////////////////////////////// + // Selection methods + ///////////////////////////////// + public: + void select( MergeRecord* record ); + void unselect( MergeRecord* record ); + void selectAll(); + void unselectAll(); + const QList selectedRecords() const; + + + ///////////////////////////////// + // Virtual methods + ///////////////////////////////// + public: + virtual QList keyList() const = 0; + virtual QString primaryKey() const = 0; + protected: + virtual void open() = 0; + virtual void close() = 0; + virtual MergeRecord* readNextRecord() = 0; + + + ///////////////////////////////// + // Signals + ///////////////////////////////// + signals: + void sourceChanged(); + void selectionChanged(); + + + ///////////////////////////////// + // Private data + ///////////////////////////////// + private: + QString mId; + QString mName; + SourceType mType; + + QString mSource; + bool mSelected; + QList mRecordList; + }; + + + ///////////////////////////////// + // INLINE METHODS + ///////////////////////////////// + QString Merge::id() const + { + return mId; + } + + + QString Merge::name() const + { + return mId; + } + + + Merge::SourceType Merge::type() const + { + return mType; + } + + + QString Merge::source() const + { + return mSource; + } + + + const QList& Merge::recordList( void ) const + { + return mRecordList; + } + +} + +#endif // glabels_Merge_h diff --git a/glabels/MergeRecord.h b/glabels/MergeRecord.h index e135f93..f51f2c1 100644 --- a/glabels/MergeRecord.h +++ b/glabels/MergeRecord.h @@ -46,10 +46,11 @@ namespace glabels // Properties ///////////////////////////////// public: - inline bool selected( void ) const; + inline bool isSelected() const; inline void setSelected( bool value ); + inline bool empty() const; - inline const QList& fieldList( void ) const; + inline const QList& fieldList() const; inline void setFieldList( QList& value ); @@ -65,7 +66,7 @@ namespace glabels ///////////////////////////////// // INLINE METHODS ///////////////////////////////// - bool MergeRecord::selected( void ) const + bool MergeRecord::isSelected() const { return mSelected; } @@ -77,7 +78,13 @@ namespace glabels } - const QList& MergeRecord::fieldList( void ) const + bool MergeRecord::empty() const + { + return mFieldList.size() == 0; + } + + + const QList& MergeRecord::fieldList() const { return mFieldList; }