Qt Model Utilities  2.0.3
A set of utilities for the model/view framework of Qt
Public Member Functions | Protected Member Functions | Properties | List of all members
CsvModelSerialiser Class Reference

Serialiser to save and load models in csv (comma separated values) format. More...

Inheritance diagram for CsvModelSerialiser:
AbstractSingleRoleSerialiser AbstractStringSerialiser AbstractModelSerialiser

Public Member Functions

 CsvModelSerialiser (const QAbstractItemModel *model, QObject *parent)
 
 CsvModelSerialiser (QAbstractItemModel *model, QObject *parent)
 
 CsvModelSerialiser (QObject *parent=Q_NULLPTR)
 
const QString & csvSeparator () const
 
bool firstColumnIsHeader ()
 
bool firstRowIsHeader ()
 
bool loadModel (const QByteArray &source) Q_DECL_OVERRIDE
 
bool loadModel (QIODevice *source) Q_DECL_OVERRIDE
 
bool loadModel (QString *source) Q_DECL_OVERRIDE
 
virtual bool loadModel (QTextStream &stream)
 
bool saveModel (QByteArray *destination) const Q_DECL_OVERRIDE
 
bool saveModel (QIODevice *destination) const Q_DECL_OVERRIDE
 
bool saveModel (QString *destination) const Q_DECL_OVERRIDE
 
virtual bool saveModel (QTextStream &stream) const
 
void setCsvSeparator (const QString &val)
 
void setFirstColumnIsHeader (bool val)
 
void setFirstRowIsHeader (bool val)
 
- Public Member Functions inherited from AbstractSingleRoleSerialiser
 AbstractSingleRoleSerialiser (const QAbstractItemModel *model, QObject *parent)
 
 AbstractSingleRoleSerialiser (QAbstractItemModel *model, QObject *parent)
 
 AbstractSingleRoleSerialiser (QObject *parent=Q_NULLPTR)
 
 ~AbstractSingleRoleSerialiser ()=0
 
void addRoleToSave (int role) Q_DECL_OVERRIDE
 
void clearRoleToSave () Q_DECL_OVERRIDE
 
void removeRoleToSave (int role) Q_DECL_OVERRIDE
 
void resetRoleToSave () Q_DECL_OVERRIDE
 
int roleToSave () const
 
void setRoleToSave (const QList< int > &val) Q_DECL_OVERRIDE
 
void setRoleToSave (int val)
 
- Public Member Functions inherited from AbstractStringSerialiser
 AbstractStringSerialiser (const QAbstractItemModel *model, QObject *parent)
 
 AbstractStringSerialiser (QAbstractItemModel *model, QObject *parent)
 
 AbstractStringSerialiser (QObject *parent=Q_NULLPTR)
 
virtual ~AbstractStringSerialiser ()=0
 
Q_INVOKABLE bool loadModel (const QString &source)
 
- Public Member Functions inherited from AbstractModelSerialiser
 AbstractModelSerialiser (const QAbstractItemModel *model, QObject *parent)
 
 AbstractModelSerialiser (QAbstractItemModel *model, QObject *parent)
 
 AbstractModelSerialiser (QObject *parent=Q_NULLPTR)
 
virtual ~AbstractModelSerialiser ()=0
 
virtual const QAbstractItemModel * constModel () const
 
virtual QAbstractItemModel * model () const
 
virtual const QList< int > & rolesToSave () const
 
void setModel (const QAbstractItemModel *val)
 
void setModel (QAbstractItemModel *val)
 
Q_INVOKABLE QDataStream::Version streamVersion () const
 The datastream version used to serialise binary data. More...
 

Protected Member Functions

 CsvModelSerialiser (CsvModelSerialiserPrivate &d, QObject *parent)
 
- Protected Member Functions inherited from AbstractSingleRoleSerialiser
 AbstractSingleRoleSerialiser (AbstractSingleRoleSerialiserPrivate &d, QObject *parent)
 
- Protected Member Functions inherited from AbstractStringSerialiser
 AbstractStringSerialiser (AbstractStringSerialiserPrivate &d, QObject *parent)
 
- Protected Member Functions inherited from AbstractModelSerialiser
 AbstractModelSerialiser (AbstractModelSerialiserPrivate &d, QObject *parent)
 

Properties

QString csvSeparator
 The column separator used in the CSV. More...
 
bool firstColumnIsHeader
 Should the first column contain headers. More...
 
bool firstRowIsHeader
 Should the first row contain headers. More...
 
- Properties inherited from AbstractSingleRoleSerialiser
int roleToSave
 The role that will be serialised. More...
 
- Properties inherited from AbstractModelSerialiser
const QAbstractItemModel * constModel
 The model over which the serialiser will operate in read mode. More...
 
QAbstractItemModel * model
 The model over which the serialiser will operate for reading/writing. More...
 
QList< int > rolesToSave
 The roles that will be serialised. More...
 

Additional Inherited Members

- Public Slots inherited from AbstractModelSerialiser
void setStreamVersion (QDataStream::Version ver)
 Set the datastream version used to serialise binary data. More...
 
- Static Public Member Functions inherited from AbstractModelSerialiser
static QList< int > modelDefaultRoles ()
 

Detailed Description

Serialiser to save and load models in csv (comma separated values) format.

Constructor & Destructor Documentation

◆ CsvModelSerialiser() [1/3]

CsvModelSerialiser::CsvModelSerialiser ( QObject *  parent = Q_NULLPTR)
explicit

Constructs a serialiser

◆ CsvModelSerialiser() [2/3]

CsvModelSerialiser::CsvModelSerialiser ( QAbstractItemModel *  model,
QObject *  parent 
)

Constructs a serialiser operating over model

◆ CsvModelSerialiser() [3/3]

CsvModelSerialiser::CsvModelSerialiser ( const QAbstractItemModel *  model,
QObject *  parent 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

the model will only be allowed to be saved, not loaded

Member Function Documentation

◆ loadModel() [1/4]

bool CsvModelSerialiser::loadModel ( const QByteArray &  source)
virtual

Reimplemented from base class

Implements AbstractModelSerialiser.

◆ loadModel() [2/4]

bool CsvModelSerialiser::loadModel ( QIODevice *  source)
virtual

Reimplemented from base class

Implements AbstractModelSerialiser.

◆ loadModel() [3/4]

bool CsvModelSerialiser::loadModel ( QString *  source)
virtual

Reimplemented from base class

Implements AbstractStringSerialiser.

◆ loadModel() [4/4]

bool CsvModelSerialiser::loadModel ( QTextStream &  stream)
virtual

Loads the model from the given stream

Data previously stored in the model will be removed

◆ saveModel() [1/4]

bool CsvModelSerialiser::saveModel ( QByteArray *  destination) const
virtual

Reimplemented from base class

Implements AbstractModelSerialiser.

◆ saveModel() [2/4]

bool CsvModelSerialiser::saveModel ( QIODevice *  destination) const
virtual

Reimplemented from base class

Implements AbstractModelSerialiser.

◆ saveModel() [3/4]

bool CsvModelSerialiser::saveModel ( QString *  destination) const
virtual

Reimplemented from base class

Implements AbstractStringSerialiser.

◆ saveModel() [4/4]

bool CsvModelSerialiser::saveModel ( QTextStream &  stream) const
virtual

Saves the model to the given stream

Property Documentation

◆ csvSeparator

CsvModelSerialiser::csvSeparator
readwrite

The column separator used in the CSV.

Access functions: csvSeparator(), setCsvSeparator()

This is the string that will be used to separate items in the same row but different columns

By default the separator is set to a comma: ,

◆ firstColumnIsHeader

bool CsvModelSerialiser::firstColumnIsHeader
readwrite

Should the first column contain headers.

Access functions: firstColumnIsHeader(), setFirstColumnIsHeader()

If this property is set to true (the default), the serialisation will the write the vertical headerData of the model as the first column of the csv file and will load the first column of the csv file as the model's vertical headerData

◆ firstRowIsHeader

bool CsvModelSerialiser::firstRowIsHeader
readwrite

Should the first row contain headers.

Access functions: firstRowIsHeader(), setFirstRowIsHeader()

If this property is set to true (the default), the serialisation will the write the horizontal headerData of the model as the first row of the csv file and will load the first row of the csv file as the model's horizontal headerData