/*! * \brief Model implementation for the remote device table * * \copyright Copyright (c) 2017-2018 Governikus GmbH & Co. KG, Germany */ #pragma once #include "GlobalStatus.h" #include "ReaderConfigurationInfo.h" #include "RemoteDeviceDescriptor.h" #include "RemoteDeviceList.h" #include "RemoteDispatcher.h" #include "RemoteServiceSettings.h" #include #include #include #include namespace governikus { class RemoteDeviceModelEntry { private: QString mDeviceName; QString mId; bool mPaired; bool mNetworkVisible; bool mSupported; QDateTime mLastConnected; QSharedPointer mRemoteDeviceListEntry; public: RemoteDeviceModelEntry(const QString pDeviceName, const QString mId, QSharedPointer& pRemoteDeviceListEntry); RemoteDeviceModelEntry(const QString pDeviceName, const QString mId, bool pPaired, bool pNetworkVisible, bool pSupported, const QDateTime& pLastConnected); RemoteDeviceModelEntry(const QString pDeviceName = QStringLiteral("UnknownReader")); bool isPaired() const; void setPaired(bool pPaired); const QString& getId() const; void setId(QString pId); bool isNetworkVisible() const; bool isSupported() const; void setNetworkVisible(bool pNetworkVisible); const QDateTime& getLastConnected() const; void setLastConnected(const QDateTime& pLastConnected); const QSharedPointer getRemoteDeviceListEntry() const; QString getDeviceName() const; }; class RemoteDeviceModel : public QAbstractTableModel { Q_OBJECT private: const int NUMBER_OF_COLUMNS = 2; QMap mPairedReaders; QVector mAllRemoteReaders; const bool mShowPairedReaders; const bool mShowUnpairedReaders; QString getStatus(const RemoteDeviceModelEntry& pRemoteDeviceModelEntry) const; void constructReaderList(); public: enum SettingsRemoteRoles { REMOTE_DEVICE_NAME = Qt::UserRole + 1, LAST_CONNECTED, DEVICE_ID, IS_NETWORK_VISIBLE, IS_SUPPORTED }; enum ColumnId : int { ReaderName = 0, ReaderStatus = 1 }; RemoteDeviceModel(QObject* pParent = nullptr, bool pShowPairedReaders = true, bool pShowUnpairedReaders = true); virtual QVariant headerData(int pSection, Qt::Orientation pOrientation, int pRole) const override; virtual int rowCount(const QModelIndex& pParent = QModelIndex()) const override; virtual int columnCount(const QModelIndex& pParent = QModelIndex()) const override; virtual QVariant data(const QModelIndex& pIndex, int pRole = Qt::DisplayRole) const override; virtual QHash roleNames() const override; const QSharedPointer getRemoteDeviceListEntry(const QModelIndex& pIndex) const; const QSharedPointer getRemoteDeviceListEntry(QString pDeviceId) const; bool isPaired(const QModelIndex& pIndex) const; bool isSupported(const QModelIndex& pIndex) const; void forgetDevice(const QModelIndex& pIndex); void forgetDevice(const QString& pDeviceId); public Q_SLOTS: void onWidgetShown(); void onWidgetHidden(); void onKnownRemoteReadersChanged(); void onDeviceDisconnected(GlobalStatus::Code pCloseCode, const QSharedPointer& pRemoteDispatcher); Q_SIGNALS: void fireModelChanged(); }; } /* namespace governikus */