2017-01-14 20:07:12 +01:00
|
|
|
|
#ifndef CONNECTIONLISTMODEL_H
|
|
|
|
|
|
#define CONNECTIONLISTMODEL_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
|
|
#include <QAbstractListModel>
|
|
|
|
|
|
|
|
|
|
|
|
#include "connectionconfig.h"
|
2017-01-15 21:01:40 +01:00
|
|
|
|
#include "expected.h"
|
2017-01-14 20:07:12 +01:00
|
|
|
|
|
2017-02-26 19:29:50 +01:00
|
|
|
|
class ConnectionList;
|
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:
|
2017-02-26 19:29:50 +01:00
|
|
|
|
ConnectionListModel(ConnectionList *conns, QObject *parent);
|
|
|
|
|
|
ConnectionListModel(const ConnectionListModel&) = delete;
|
|
|
|
|
|
~ConnectionListModel();
|
2017-01-14 20:07:12 +01:00
|
|
|
|
|
|
|
|
|
|
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-02-26 19:29:50 +01:00
|
|
|
|
void newItem();
|
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 save();
|
2017-01-18 20:48:31 +01:00
|
|
|
|
void save(int index);
|
2017-01-14 20:07:12 +01:00
|
|
|
|
private:
|
2017-02-26 19:29:50 +01:00
|
|
|
|
|
|
|
|
|
|
ConnectionList *m_connections;
|
|
|
|
|
|
|
2017-01-15 12:27:36 +01:00
|
|
|
|
|
2017-01-14 20:07:12 +01:00
|
|
|
|
static QString makeLongDescription(const ConnectionConfig &cfg);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // CONNECTIONLISTMODEL_H
|