2017-01-14 20:07:12 +01:00
|
|
|
|
#ifndef CONNECTIONLISTMODEL_H
|
|
|
|
|
|
#define CONNECTIONLISTMODEL_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
2017-01-15 12:27:36 +01:00
|
|
|
|
#include <QUuid>
|
2017-01-14 20:07:12 +01:00
|
|
|
|
|
|
|
|
|
|
#include "connectionconfig.h"
|
2017-01-15 21:01:40 +01:00
|
|
|
|
#include "expected.h"
|
2017-01-14 20:07:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
2017-02-01 20:00:03 +01:00
|
|
|
|
/** \brief Model class for the list of connections.
|
|
|
|
|
|
*
|
|
|
|
|
|
* This class also allows for the editing of the list.
|
|
|
|
|
|
*/
|
2017-01-14 20:07:12 +01:00
|
|
|
|
class ConnectionListModel : public QAbstractListModel {
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
public:
|
|
|
|
|
|
ConnectionListModel(QObject *parent);
|
|
|
|
|
|
|
|
|
|
|
|
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
2017-01-14 22:03:58 +01:00
|
|
|
|
virtual int columnCount(const QModelIndex &/*parent*/) const override;
|
2017-01-14 20:07:12 +01:00
|
|
|
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
|
|
|
|
|
// virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
2017-01-14 22:29:12 +01:00
|
|
|
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
|
|
|
|
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
2017-01-14 20:07:12 +01:00
|
|
|
|
|
2017-01-14 22:29:12 +01:00
|
|
|
|
void add(const ConnectionConfig &cfg);
|
2017-01-15 21:01:40 +01:00
|
|
|
|
Expected<ConnectionConfig> get(int row);
|
|
|
|
|
|
virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
|
2017-01-14 20:07:12 +01:00
|
|
|
|
|
2017-01-15 12:27:36 +01:00
|
|
|
|
void load();
|
|
|
|
|
|
void save();
|
2017-01-18 20:48:31 +01:00
|
|
|
|
void save(int index);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
private:
|
2017-01-15 12:27:36 +01:00
|
|
|
|
class LijstElem {
|
|
|
|
|
|
public:
|
|
|
|
|
|
QUuid m_uuid;
|
2017-01-18 20:48:31 +01:00
|
|
|
|
bool m_dirty = false;
|
2017-01-15 12:27:36 +01:00
|
|
|
|
ConnectionConfig m_config;
|
|
|
|
|
|
|
|
|
|
|
|
LijstElem(const QUuid id, const ConnectionConfig &cfg)
|
|
|
|
|
|
: m_uuid(id), m_config(cfg)
|
|
|
|
|
|
{}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
using t_Connections = std::vector<LijstElem>;
|
2017-01-14 20:07:12 +01:00
|
|
|
|
t_Connections m_connections;
|
|
|
|
|
|
|
2017-01-18 20:48:31 +01:00
|
|
|
|
void deleteFromIni(t_Connections::iterator begin, t_Connections::iterator end);
|
2017-01-15 12:27:36 +01:00
|
|
|
|
static QString iniFileName();
|
|
|
|
|
|
|
2017-01-14 20:07:12 +01:00
|
|
|
|
static QString makeLongDescription(const ConnectionConfig &cfg);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CONNECTIONLISTMODEL_H
|