-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgsdataitem.h
262 lines (198 loc) · 7.14 KB
/
qgsdataitem.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/***************************************************************************
qgsdataitem.h - Items representing data
-------------------
begin : 2011-04-01
copyright : (C) 2011 Radim Blazek
email : radim dot blazek at gmail 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 QGSDATAITEM_H
#define QGSDATAITEM_H
#include <QIcon>
#include <QLibrary>
#include <QObject>
#include <QPixmap>
#include <QString>
#include <QVector>
#include <QTreeWidget>
#include "qgsmaplayer.h"
#include "qgscoordinatereferencesystem.h"
class QgsDataProvider;
class QgsDataItem;
// TODO: bad place, where to put this? qgsproviderregistry.h?
typedef int dataCapabilities_t();
typedef QgsDataItem * dataItem_t( QString, QgsDataItem* );
/** base class for all items in the model */
class CORE_EXPORT QgsDataItem : public QObject
{
Q_OBJECT
public:
enum Type
{
Collection,
Directory,
Layer,
Error,
};
QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path );
virtual ~QgsDataItem() {}
bool hasChildren();
int rowCount();
//
virtual void refresh();
// Create vector of children
virtual QVector<QgsDataItem*> createChildren();
// Populate children using children vector created by createChildren()
virtual void populate();
// Insert new child using alphabetical order based on mName, emits necessary signal to model before and after, sets parent and connects signals
// refresh - refresh populated item, emit signals to model
virtual void addChildItem( QgsDataItem * child, bool refresh = false );
// remove and delete child item, signals to browser are emited
virtual void deleteChildItem( QgsDataItem * child );
virtual bool equal( const QgsDataItem *other );
virtual QWidget * paramWidget() { return 0; }
// list of actions provided by this item - usually used for popup menu on right-click
virtual QList<QAction*> actions() { return QList<QAction*>(); }
//
enum Capability
{
NoCapabilities = 0,
SetCrs = 1 //Can set CRS on layer or group of layers
};
// This will _write_ selected crs in data source
virtual bool setCrs( QgsCoordinateReferenceSystem crs )
{ Q_UNUSED( crs ); return false; }
virtual Capability capabilities() { return NoCapabilities; }
// static methods
static QPixmap getThemePixmap( const QString theName );
// Find child index in vector of items using '==' operator
static int findItem( QVector<QgsDataItem*> items, QgsDataItem * item );
// members
Type type() const { return mType; }
QgsDataItem* parent() const { return mParent; }
QVector<QgsDataItem*> children() const { return mChildren; }
QIcon icon() const { return mIcon; }
QString name() const { return mName; }
QString path() const { return mPath; }
void setIcon( QIcon icon ) { mIcon = icon; }
protected:
Type mType;
QgsDataItem* mParent;
QVector<QgsDataItem*> mChildren; // easier to have it always
bool mPopulated;
QString mName;
QString mPath; // it is also used to identify item in tree
QIcon mIcon;
public slots:
void emitBeginInsertItems( QgsDataItem* parent, int first, int last );
void emitEndInsertItems();
void emitBeginRemoveItems( QgsDataItem* parent, int first, int last );
void emitEndRemoveItems();
signals:
void beginInsertItems( QgsDataItem* parent, int first, int last );
void endInsertItems();
void beginRemoveItems( QgsDataItem* parent, int first, int last );
void endRemoveItems();
};
/** Item that represents a layer that can be opened with one of the providers */
class CORE_EXPORT QgsLayerItem : public QgsDataItem
{
Q_OBJECT
public:
enum LayerType
{
NoType,
Vector,
Raster,
Point,
Line,
Polygon,
TableLayer,
Database,
Table
};
QgsLayerItem( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey );
// --- reimplemented from QgsDataItem ---
virtual bool equal( const QgsDataItem *other );
// --- New virtual methods for layer item derived classes ---
// Returns QgsMapLayer::LayerType
QgsMapLayer::LayerType mapLayerType();
// Returns layer uri or empty string if layer cannot be created
QString uri() { return mUri; }
// Returns provider key
QString providerKey() { return mProviderKey; }
protected:
QString mProviderKey;
QString mUri;
LayerType mLayerType;
static const QIcon &iconPoint();
static const QIcon &iconLine();
static const QIcon &iconPolygon();
static const QIcon &iconTable();
static const QIcon &iconDefault();
};
/** A Collection: logical collection of layers or subcollections, e.g. GRASS location/mapset, database? wms source? */
class CORE_EXPORT QgsDataCollectionItem : public QgsDataItem
{
Q_OBJECT
public:
QgsDataCollectionItem( QgsDataItem* parent, QString name, QString path = QString::null );
~QgsDataCollectionItem();
void setPopulated() { mPopulated = true; }
void addChild( QgsDataItem *item ) { mChildren.append( item ); }
static const QIcon &iconDir(); // shared icon: open/closed directory
};
/** A directory: contains subdirectories and layers */
class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
enum Column
{
Name,
Size,
Date,
Permissions,
Owner,
Group,
Type
};
QgsDirectoryItem( QgsDataItem* parent, QString name, QString path );
~QgsDirectoryItem();
QVector<QgsDataItem*> createChildren();
virtual bool equal( const QgsDataItem *other );
virtual QWidget * paramWidget();
static QVector<QgsDataProvider*> mProviders;
static QVector<QLibrary*> mLibraries;
};
/**
Data item that can be used to report problems (e.g. network error)
*/
class CORE_EXPORT QgsErrorItem : public QgsDataItem
{
Q_OBJECT
public:
QgsErrorItem( QgsDataItem* parent, QString error, QString path );
~QgsErrorItem();
//QVector<QgsDataItem*> createChildren();
//virtual bool equal( const QgsDataItem *other );
};
// ---------
class QgsDirectoryParamWidget : public QTreeWidget
{
Q_OBJECT
public:
QgsDirectoryParamWidget( QString path, QWidget* parent = NULL );
protected:
void mousePressEvent( QMouseEvent* event );
public slots:
void showHideColumn();
};
#endif // QGSDATAITEM_H