ObjectListItemModel.hh 1.37 KB
Newer Older
Jan Möbius's avatar
 
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
 * ObjectListItemModel.hh
 *
 *  Created on: Feb 29, 2012
 *      Author: ebke
 */

#ifndef OBJECTLISTITEMMODEL_HH_
#define OBJECTLISTITEMMODEL_HH_

#include <QAbstractItemModel>
#include <OpenFlipper/common/DataTypes.hh>

class ObjectListItemModel: public QAbstractListModel {
    public:
        ObjectListItemModel();
        virtual ~ObjectListItemModel();

        virtual int rowCount(const QModelIndex & parent = QModelIndex()) const;
        virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const;

        void refresh(const DataType &datatype);

    protected:
        class ObjectInfo {
            public:
                ObjectInfo(const QString &name, const int id) : name(name), id(id) {}

                bool operator<(const ObjectInfo &rhs) const {
                    const int nameCmp = name.compare(rhs.name);
                    if (!nameCmp) return id < rhs.id;
                    return nameCmp < 0;
                }

                bool operator==(const ObjectInfo &rhs) const {
                    return id == rhs.id && name == rhs.name;
                }

                const QString &getName() const { return name; }
                int getId() const { return id; }

            private:
                QString name;
                int id;
        };

        std::vector<ObjectInfo> objects_;
};

#endif /* OBJECTLISTITEMMODEL_HH_ */