OGS
ColorTableModel Class Reference

Detailed Description

The PolylinesModel is a Qt model which represents Polylines.

Definition at line 14 of file ColorTableModel.h.

#include <ColorTableModel.h>

Inheritance diagram for ColorTableModel:
[legend]
Collaboration diagram for ColorTableModel:
[legend]

Public Member Functions

 ColorTableModel (const std::map< std::string, DataHolderLib::Color * > &colorLookupTable, QObject *parent=nullptr)
 ~ColorTableModel () override
int columnCount (const QModelIndex &parent=QModelIndex()) const override
QVariant data (const QModelIndex &index, int role) const override
int rowCount (const QModelIndex &parent=QModelIndex()) const override
QVariant headerData (int section, Qt::Orientation orientation, int role) const override

Private Member Functions

bool buildTable (const std::map< std::string, DataHolderLib::Color * > &colorLookupTable)

Private Attributes

QList< QPair< QString, QColor > > _listOfPairs

Constructor & Destructor Documentation

◆ ColorTableModel()

ColorTableModel::ColorTableModel ( const std::map< std::string, DataHolderLib::Color * > & colorLookupTable,
QObject * parent = nullptr )
explicit

Definition at line 6 of file ColorTableModel.cpp.

9{
10 Q_UNUSED(parent)
11
12 this->buildTable(colorLookupTable);
13}
bool buildTable(const std::map< std::string, DataHolderLib::Color * > &colorLookupTable)

References buildTable().

◆ ~ColorTableModel()

ColorTableModel::~ColorTableModel ( )
overridedefault

Member Function Documentation

◆ buildTable()

bool ColorTableModel::buildTable ( const std::map< std::string, DataHolderLib::Color * > & colorLookupTable)
private

Definition at line 80 of file ColorTableModel.cpp.

82{
83 int count = 0;
84 beginInsertRows(QModelIndex(), 0, colorLookupTable.size() - 1);
85
86 for (const auto& row : colorLookupTable)
87 {
88 QColor color((*row.second)[0], (*row.second)[1], (*row.second)[2]);
89 QString name(QString::fromStdString(row.first));
90
91 /* Saudi Arabia strat names *
92 if (it->first.compare("1")==0) name="Buweib";
93 if (it->first.compare("2")==0) name="Wasia";
94 if (it->first.compare("3")==0) name="Aruma";
95 if (it->first.compare("4")==0) name="Umm Er Radhuma";
96 if (it->first.compare("5")==0) name="Rus";
97 if (it->first.compare("6")==0) name="Dammam";
98 if (it->first.compare("7")==0) name="Neogene";
99 */
100
101 QPair<QString, QColor> pair(name, color);
102 _listOfPairs.insert(count++, pair);
103 }
104
105 endInsertRows();
106 return true;
107}
QList< QPair< QString, QColor > > _listOfPairs

References _listOfPairs.

Referenced by ColorTableModel().

◆ columnCount()

int ColorTableModel::columnCount ( const QModelIndex & parent = QModelIndex()) const
override

Definition at line 17 of file ColorTableModel.cpp.

19{
20 Q_UNUSED(parent)
21
22 return 2;
23}

◆ data()

QVariant ColorTableModel::data ( const QModelIndex & index,
int role ) const
override

Definition at line 51 of file ColorTableModel.cpp.

52{
53 if (!index.isValid())
54 {
55 return QVariant();
56 }
57
58 if (index.row() >= _listOfPairs.size() || index.row() < 0)
59 {
60 return QVariant();
61 }
62
63 if (role == Qt::DisplayRole)
64 {
65 QPair<QString, QColor> pair = _listOfPairs.at(index.row());
66
67 switch (index.column())
68 {
69 case 0:
70 return pair.first;
71 case 1:
72 return pair.second;
73 default:
74 return QVariant();
75 }
76 }
77 return QVariant();
78}

References _listOfPairs.

◆ headerData()

QVariant ColorTableModel::headerData ( int section,
Qt::Orientation orientation,
int role ) const
override

Definition at line 25 of file ColorTableModel.cpp.

27{
28 if (role != Qt::DisplayRole)
29 {
30 return QVariant();
31 }
32
33 if (orientation == Qt::Horizontal)
34 {
35 switch (section)
36 {
37 case 0:
38 return "Name";
39 case 1:
40 return "Colour";
41 default:
42 return QVariant();
43 }
44 }
45 else
46 {
47 return QString("Row %1").arg(section);
48 }
49}

◆ rowCount()

int ColorTableModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
inlineoverride

Definition at line 28 of file ColorTableModel.h.

29 {
30 Q_UNUSED (parent);
31 return _listOfPairs.size();
32 }

References _listOfPairs.

Member Data Documentation

◆ _listOfPairs

QList< QPair<QString, QColor> > ColorTableModel::_listOfPairs
private

Definition at line 40 of file ColorTableModel.h.

Referenced by buildTable(), data(), and rowCount().


The documentation for this class was generated from the following files: