-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqgsbookmarks.h
132 lines (97 loc) · 4.31 KB
/
qgsbookmarks.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
QgsBookmarks.h - Spatial Bookmarks
-------------------
begin : 2005-04-23
copyright : (C) 2005 Gary Sherman
email : sherman at mrcc dot com
***************************************************************************/
/***************************************************************************
* *
* 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 QGSBOOKMARKS_H
#define QGSBOOKMARKS_H
#include <QSqlTableModel>
#include <memory>
#include "ui_qgsbookmarksbase.h"
#include "qgsdockwidget.h"
#include "qgis_app.h"
/*
* Model for project bookmarks
*/
class QgsProjectBookmarksTableModel: public QAbstractTableModel
{
Q_OBJECT
public:
QgsProjectBookmarksTableModel();
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const override;
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ) override;
bool insertRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
private slots:
void projectRead() { emit layoutChanged(); };
};
/*
* Model that merge the QGIS and project model
*/
class QgsMergedBookmarksTableModel: public QAbstractTableModel
{
Q_OBJECT
public:
QgsMergedBookmarksTableModel( QAbstractTableModel &qgisTableModel, QAbstractTableModel &projectTableModel, QTreeView *treeView );
int rowCount( const QModelIndex &parent = QModelIndex() ) const override;
int columnCount( const QModelIndex &parent = QModelIndex() ) const override;
QVariant data( const QModelIndex &index, 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;
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() ) override;
QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const override;
QAbstractTableModel *qgisModel();
private:
QAbstractTableModel &mQgisTableModel;
QAbstractTableModel &mProjectTableModel;
QTreeView *mTreeView = nullptr;
bool mProjectOpen;
void moveBookmark( QAbstractTableModel &modelFrom, QAbstractTableModel &modelTo, int row );
private slots:
void projectRead() { mProjectOpen = true; };
void allLayoutChanged() { emit layoutChanged(); };
void qgisDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight )
{
emit dataChanged( topLeft, bottomRight );
};
void projectDataChanged( const QModelIndex &topLeft, const QModelIndex &bottomRight )
{
emit dataChanged(
index( topLeft.row() + mQgisTableModel.rowCount(), topLeft.column() ),
index( bottomRight.row() + mQgisTableModel.rowCount(), bottomRight.column() ) );
};
};
class APP_EXPORT QgsBookmarks : public QgsDockWidget, private Ui::QgsBookmarksBase
{
Q_OBJECT
public:
QgsBookmarks( QWidget *parent = nullptr );
~QgsBookmarks();
public slots:
void addClicked();
private slots:
void deleteClicked();
void zoomToBookmark();
void exportToXml();
void importFromXml();
void on_lstBookmarks_doubleClicked( const QModelIndex & );
private:
QSqlTableModel *mQgisModel = nullptr;
QgsProjectBookmarksTableModel *mProjectModel = nullptr;
std::unique_ptr<QgsMergedBookmarksTableModel> mModel;
void saveWindowLocation();
void restorePosition();
};
#endif // QGSBOOKMARKS_H