-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsvertexeditor.h
118 lines (86 loc) · 3.72 KB
/
qgsvertexeditor.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/***************************************************************************
qgsvertexeditor.h
---------------
begin : Tue Mar 24 2015
copyright : (C) 2015 Sandro Mani / Sourcepole AG
email : smani@sourcepole.ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSVERTEXEDITOR_H
#define QGSVERTEXEDITOR_H
#include "qgsdockwidget.h"
#include <QAbstractTableModel>
#include <QItemSelection>
#include <QStyledItemDelegate>
class QgsMapCanvas;
class QgsLockedFeature;
class QgsVectorLayer;
class QLabel;
class QTableView;
class QgsVertexEditorModel : public QAbstractTableModel
{
Q_OBJECT
public:
QgsVertexEditorModel( QgsMapCanvas *canvas, QObject *parent = nullptr );
void setFeature( QgsLockedFeature *lockedFeature );
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
QVariant data( const QModelIndex &index, int role ) const override;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
Qt::ItemFlags flags( const QModelIndex &index ) const override;
private:
QgsLockedFeature *mLockedFeature = nullptr;
QgsMapCanvas *mCanvas = nullptr;
bool mHasZ = false;
bool mHasM = false;
bool mHasR = true; //always show for now - avoids scanning whole feature for curves TODO - avoid this
int mZCol = -1;
int mMCol = -1;
int mRCol = -1;
QFont mWidgetFont;
bool calcR( int row, double &r, double &minRadius ) const;
};
class QgsVertexEditor : public QgsDockWidget
{
Q_OBJECT
public:
QgsVertexEditor( QgsMapCanvas *canvas );
void updateEditor( QgsLockedFeature *lockedFeature );
QgsLockedFeature *mLockedFeature = nullptr;
QgsMapCanvas *mCanvas = nullptr;
QTableView *mTableView = nullptr;
QgsVertexEditorModel *mVertexModel = nullptr;
signals:
void deleteSelectedRequested();
void editorClosed();
public slots:
void updateTableSelection();
protected:
void keyPressEvent( QKeyEvent *event ) override;
void closeEvent( QCloseEvent *event ) override;
private slots:
void updateVertexSelection( const QItemSelection &selected, const QItemSelection &deselected );
private:
QLabel *mHintLabel = nullptr;
bool mUpdatingTableSelection = false;
bool mUpdatingVertexSelection = false;
};
class CoordinateItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit CoordinateItemDelegate( QObject *parent = nullptr );
QString displayText( const QVariant &value, const QLocale &locale ) const override;
protected:
QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem & /*option*/, const QModelIndex &index ) const override;
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const override;
};
#endif // QGSVERTEXEDITOR_H