| 1 |
#pragma once |
| 2 |
|
| 3 |
//########################################################################## |
| 4 |
//# # |
| 5 |
//# CLOUDCOMPARE PLUGIN: qCloudLayers # |
| 6 |
//# # |
| 7 |
//# This program is free software; you can redistribute it and/or modify # |
| 8 |
//# it under the terms of the GNU General Public License as published by # |
| 9 |
//# the Free Software Foundation; version 2 of the License. # |
| 10 |
//# # |
| 11 |
//# This program is distributed in the hope that it will be useful, # |
| 12 |
//# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
| 13 |
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
| 14 |
//# GNU General Public License for more details. # |
| 15 |
//# # |
| 16 |
//# COPYRIGHT: WigginsTech 2022 # |
| 17 |
//# # |
| 18 |
//########################################################################## |
| 19 |
|
| 20 |
//Qt |
| 21 |
#include <QAbstractTableModel> |
| 22 |
#include <QColor> |
| 23 |
|
| 24 |
class ccAsprsModel : public QAbstractTableModel |
| 25 |
{ |
| 26 |
Q_OBJECT |
| 27 |
|
| 28 |
public: |
| 29 |
ccAsprsModel(QObject* parent = nullptr); |
| 30 |
|
| 31 |
int rowCount(const QModelIndex& parent) const; |
| 32 |
int columnCount(const QModelIndex& parent) const; |
| 33 |
QVariant data(const QModelIndex& index, int role) const; |
| 34 |
QVariant headerData(int section, Qt::Orientation orientation, int role) const; |
| 35 |
|
| 36 |
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); |
| 37 |
Qt::ItemFlags flags(const QModelIndex& index) const; |
| 38 |
|
| 39 |
QModelIndex createNewItem(); |
| 40 |
|
| 41 |
// load asprs items data from qsettings |
| 42 |
void load(); |
| 43 |
|
| 44 |
// save asprs items data to qsettings |
| 45 |
void save() const; |
| 46 |
|
| 47 |
enum Column |
| 48 |
{ |
| 49 |
VISIBLE, |
| 50 |
NAME, |
| 51 |
CODE, |
| 52 |
COLOR, |
| 53 |
COUNT, |
| 54 |
LAST |
| 55 |
}; |
| 56 |
|
| 57 |
struct AsprsItem |
| 58 |
{ |
| 59 |
bool visible; |
| 60 |
QString name; |
| 61 |
int code; |
| 62 |
QColor color; |
| 63 |
int count; |
| 64 |
}; |
| 65 |
|
| 66 |
void refreshData(); |
| 67 |
|
| 68 |
inline const QList<AsprsItem>& getData() const { return m_data; } |
| 69 |
inline QList<AsprsItem>& getData() { return m_data; } |
| 70 |
|
| 71 |
AsprsItem* find(QString name); |
| 72 |
AsprsItem* find(int code); |
| 73 |
|
| 74 |
int indexOf(QString name) const; |
| 75 |
|
| 76 |
public Q_SLOTS: |
| 77 |
bool removeRows(int position, int rows, const QModelIndex& parent); |
| 78 |
|
| 79 |
Q_SIGNALS: |
| 80 |
void codeChanged(AsprsItem& item, int oldCode); |
| 81 |
void colorChanged(AsprsItem& item); |
| 82 |
|
| 83 |
private: |
| 84 |
QList<AsprsItem> m_data; |
| 85 |
|
| 86 |
private: |
| 87 |
bool isNameExist(const QString& name) const; |
| 88 |
bool isCodeExist(int code) const; |
| 89 |
|
| 90 |
// default asprs items |
| 91 |
void createDefaultItems(); |
| 92 |
int getUnusedCode() const; |
| 93 |
}; |
| 94 |
|