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