OGS
ColorTableModel Class Reference

Detailed Description

The PolylinesModel is a Qt model which represents Polylines.

Definition at line 25 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 17 of file ColorTableModel.cpp.

20{
21 Q_UNUSED(parent)
22
23 this->buildTable(colorLookupTable);
24}
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 91 of file ColorTableModel.cpp.

93{
94 int count = 0;
95 beginInsertRows(QModelIndex(), 0, colorLookupTable.size() - 1);
96
97 for (const auto& row : colorLookupTable)
98 {
99 QColor color((*row.second)[0], (*row.second)[1], (*row.second)[2]);
100 QString name(QString::fromStdString(row.first));
101
102 /* Saudi Arabia strat names *
103 if (it->first.compare("1")==0) name="Buweib";
104 if (it->first.compare("2")==0) name="Wasia";
105 if (it->first.compare("3")==0) name="Aruma";
106 if (it->first.compare("4")==0) name="Umm Er Radhuma";
107 if (it->first.compare("5")==0) name="Rus";
108 if (it->first.compare("6")==0) name="Dammam";
109 if (it->first.compare("7")==0) name="Neogene";
110 */
111
112 QPair<QString, QColor> pair(name, color);
113 _listOfPairs.insert(count++, pair);
114 }
115
116 endInsertRows();
117 return true;
118}
QList< QPair< QString, QColor > > _listOfPairs

References _listOfPairs.

Referenced by ColorTableModel().

◆ columnCount()

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

Definition at line 28 of file ColorTableModel.cpp.

30{
31 Q_UNUSED(parent)
32
33 return 2;
34}

◆ data()

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

Definition at line 62 of file ColorTableModel.cpp.

63{
64 if (!index.isValid())
65 {
66 return QVariant();
67 }
68
69 if (index.row() >= _listOfPairs.size() || index.row() < 0)
70 {
71 return QVariant();
72 }
73
74 if (role == Qt::DisplayRole)
75 {
76 QPair<QString, QColor> pair = _listOfPairs.at(index.row());
77
78 switch (index.column())
79 {
80 case 0:
81 return pair.first;
82 case 1:
83 return pair.second;
84 default:
85 return QVariant();
86 }
87 }
88 return QVariant();
89}

References _listOfPairs.

◆ headerData()

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

Definition at line 36 of file ColorTableModel.cpp.

38{
39 if (role != Qt::DisplayRole)
40 {
41 return QVariant();
42 }
43
44 if (orientation == Qt::Horizontal)
45 {
46 switch (section)
47 {
48 case 0:
49 return "Name";
50 case 1:
51 return "Colour";
52 default:
53 return QVariant();
54 }
55 }
56 else
57 {
58 return QString("Row %1").arg(section);
59 }
60}

◆ rowCount()

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

Definition at line 39 of file ColorTableModel.h.

40 {
41 Q_UNUSED (parent);
42 return _listOfPairs.size();
43 }

References _listOfPairs.

Member Data Documentation

◆ _listOfPairs

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

Definition at line 51 of file ColorTableModel.h.

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


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