Added Merge base class.

This commit is contained in:
Jim Evins
2015-09-26 10:45:49 -04:00
parent 5daa902430
commit cf1c194928
4 changed files with 287 additions and 4 deletions
+2
View File
@@ -30,6 +30,7 @@ set (glabels_sources
LabelModelShapeObject.cpp LabelModelShapeObject.cpp
LabelRegion.cpp LabelRegion.cpp
MainWindow.cpp MainWindow.cpp
Merge.cpp
MergeField.cpp MergeField.cpp
MergePropertyEditor.cpp MergePropertyEditor.cpp
MergeRecord.cpp MergeRecord.cpp
@@ -67,6 +68,7 @@ set (glabels_qobject_headers
LabelModelBoxObject.h LabelModelBoxObject.h
LabelModelShapeObject.h LabelModelShapeObject.h
MainWindow.h MainWindow.h
Merge.h
MergePropertyEditor.h MergePropertyEditor.h
NewLabelDialog.h NewLabelDialog.h
ObjectEditor.h ObjectEditor.h
+127
View File
@@ -0,0 +1,127 @@
/* Merge.cpp
*
* Copyright (C) 2015 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#include "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<MergeRecord*> Merge::selectedRecords() const
{
QList<MergeRecord*> list;
foreach ( MergeRecord* record, mRecordList )
{
if ( record->isSelected() )
{
list.append( record );
}
}
return list;
}
}
+147
View File
@@ -0,0 +1,147 @@
/* Merge.h
*
* Copyright (C) 2015 Jim Evins <evins@snaught.com>
*
* This file is part of gLabels-qt.
*
* gLabels-qt is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* gLabels-qt is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gLabels-qt. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef glabels_Merge_h
#define glabels_Merge_h
#include <QObject>
#include <QString>
#include <QList>
#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<MergeRecord*>& recordList( void ) const;
/////////////////////////////////
// Selection methods
/////////////////////////////////
public:
void select( MergeRecord* record );
void unselect( MergeRecord* record );
void selectAll();
void unselectAll();
const QList<MergeRecord*> selectedRecords() const;
/////////////////////////////////
// Virtual methods
/////////////////////////////////
public:
virtual QList<QString> 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<MergeRecord*> 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<MergeRecord*>& Merge::recordList( void ) const
{
return mRecordList;
}
}
#endif // glabels_Merge_h
+11 -4
View File
@@ -46,10 +46,11 @@ namespace glabels
// Properties // Properties
///////////////////////////////// /////////////////////////////////
public: public:
inline bool selected( void ) const; inline bool isSelected() const;
inline void setSelected( bool value ); inline void setSelected( bool value );
inline bool empty() const;
inline const QList<MergeField>& fieldList( void ) const; inline const QList<MergeField>& fieldList() const;
inline void setFieldList( QList<MergeField>& value ); inline void setFieldList( QList<MergeField>& value );
@@ -65,7 +66,7 @@ namespace glabels
///////////////////////////////// /////////////////////////////////
// INLINE METHODS // INLINE METHODS
///////////////////////////////// /////////////////////////////////
bool MergeRecord::selected( void ) const bool MergeRecord::isSelected() const
{ {
return mSelected; return mSelected;
} }
@@ -77,7 +78,13 @@ namespace glabels
} }
const QList<MergeField>& MergeRecord::fieldList( void ) const bool MergeRecord::empty() const
{
return mFieldList.size() == 0;
}
const QList<MergeField>& MergeRecord::fieldList() const
{ {
return mFieldList; return mFieldList;
} }