Servus  1.5.1
C++ network oriented utilities including a zeroconf implementation
itemModel.h
1 /* Copyright (c) 2015, Human Brain Project
2  * Daniel.Nachbaur@epfl.ch
3  *
4  * This file is part of Servus <https://github.com/HBPVIS/Servus>
5  *
6  * This library is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Lesser General Public License version 3.0 as published
8  * by the Free Software Foundation.
9  *
10  * This library is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this library; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef SERVUSQT_ITEMMODEL
21 #define SERVUSQT_ITEMMODEL
22 
23 #include <servus/qt/api.h>
24 #include <servus/types.h>
25 
26 #include <QAbstractItemModel> // base class
27 #include <memory> // std::unique_ptr
28 
29 namespace servus
30 {
31 namespace qt
32 {
45 class ItemModel : public QAbstractItemModel
46 {
47 public:
56  SERVUSQT_API ItemModel(Servus& service, QObject* parent = nullptr);
57 
59  SERVUSQT_API virtual ~ItemModel();
60 
62  SERVUSQT_API QModelIndex
63  index(int row, int colum,
64  const QModelIndex& parent = QModelIndex()) const override;
65 
73  SERVUSQT_API QModelIndex parent(const QModelIndex& index) const override;
74 
83  SERVUSQT_API
84  int rowCount(const QModelIndex& index = QModelIndex()) const override;
85 
91  SERVUSQT_API
92  int columnCount(const QModelIndex& index = QModelIndex()) const override;
93 
104  SERVUSQT_API QVariant data(const QModelIndex& index,
105  int role = Qt::DisplayRole) const override;
106 
115  SERVUSQT_API QVariant headerData(int section, Qt::Orientation orientation,
116  int role) const override;
117 
118 private:
119  class Impl;
120  std::unique_ptr<Impl> _impl;
121 };
122 }
123 }
124 
125 #endif // SERVUSQT_ITEMMODEL
SERVUSQT_API QModelIndex parent(const QModelIndex &index) const override
Mandatory override of QAbstractItemModel::parent.
SERVUSQT_API int columnCount(const QModelIndex &index=QModelIndex()) const override
Mandatory override of QAbstractItemModel::columnCount.
SERVUSQT_API QModelIndex index(int row, int colum, const QModelIndex &parent=QModelIndex()) const override
Mandatory override of QAbstractItemModel::index.
An item model on top of a Servus service, to be used in a Qt item view.
Definition: itemModel.h:45
Simple wrapper for ZeroConf key/value pairs.
Definition: servus.h:46
SERVUSQT_API int rowCount(const QModelIndex &index=QModelIndex()) const override
Mandatory override of QAbstractItemModel::rowCount.
Defines export visibility macros for library ServusQt.
virtual SERVUSQT_API ~ItemModel()
Destruct the model and reset the service back to non-browsing state.
SERVUSQT_API QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Mandatory override of QAbstractItemModel::data.
SERVUSQT_API QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Optional override of QAbstractItemModel::headerData.
SERVUSQT_API ItemModel(Servus &service, QObject *parent=nullptr)
Construct a new model by filling it with the current discovered instances and put the service into br...