#pragma once // Qt #include #include // Project #include "VView.h" #include "Network.h" // forward declarations class tst_views; namespace View { /*! * \brief The VNetworkModel class * Interface between QML and the networks * \details Exposes networks to QML and provides an interface to connect and disconnect from those networks. * References: https://doc.qt.io/qt-5.12/qtquick-modelviewsdata-cppmodels.html * */ class VNetworkModel : public QAbstractListModel { Q_OBJECT public: // Note: VIEW_DEC_CLASS(VNetworkModel) requires QObject as the parent, so it's necessary to define it here // Otherwise a VIEW_DEC_CLASS macro could allow specifying the parent class with QObject as the default VNetworkModel(QAbstractListModel *parent = nullptr) : QAbstractListModel(parent) { initConnections(); } enum NetworkDataRole { SSIDRole = Qt::UserRole + 1, SecurityLevelRole, StatusRole, }; void addNetwork (const Network &network); int rowCount (const QModelIndex &parent = QModelIndex()) const; QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const; signals: void didScan(); public slots: void doScan(); protected: QHash roleNames() const; private: QList _networks; void initConnections(); }; }