/usr/include/qgis/qgsdataitem.h is in libqgis-dev 2.8.6+dfsg-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | /***************************************************************************
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 <QFileSystemWatcher>
#include <QFutureWatcher>
#include <QIcon>
#include <QLibrary>
#include <QMovie>
#include <QObject>
#include <QPixmap>
#include <QString>
#include <QTreeWidget>
#include <QVector>
#include "qgsapplication.h"
#include "qgsmaplayer.h"
#include "qgscoordinatereferencesystem.h"
class QgsDataProvider;
class QgsDataItem;
typedef QgsDataItem * dataItem_t( QString, QgsDataItem* );
/** Base class for all items in the model.
* Parent/children hierarchy is not based on QObject. */
class CORE_EXPORT QgsDataItem : public QObject
{
Q_OBJECT
Q_ENUMS( Type )
Q_ENUMS( State )
public:
enum Type
{
Collection,
Directory,
Layer,
Error,
Favourites
};
/** Create new data item. */
QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path );
virtual ~QgsDataItem();
bool hasChildren();
int rowCount();
/** Create children. Children are not expected to have parent set.
* This method MUST BE THREAD SAFE. */
virtual QVector<QgsDataItem*> createChildren();
enum State
{
NotPopulated, //!< Children not yet created
Populating, //!< Creating children in separate thread (populating or refreshing)
Populated //!< children created
};
State state() const;
/** Set item state. It also take care about starting/stopping loading icon animation.
* @param state */
virtual void setState( State state );
//! @deprecated in 2.8, use state()
bool isPopulated() { return state() == Populated; }
// 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 emitted
virtual void deleteChildItem( QgsDataItem * child );
// remove child item but don't delete it, signals to browser are emitted
// returns pointer to the removed item or null if no such item was found
virtual QgsDataItem *removeChildItem( 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*>(); }
// whether accepts drag&drop'd layers - e.g. for import
virtual bool acceptDrop() { return false; }
// try to process the data dropped on this item
virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ ) { return false; }
enum Capability
{
NoCapabilities = 0,
SetCrs = 1 << 0, //!< Can set CRS on layer or group of layers
Fertile = 1 << 1, //!< Can create children. Even items without this capability may have children, but cannot create them, it means that children are created by item ancestors.
Fast = 1 << 2 //!< createChildren() is fast enough to be run in main thread when refreshing items, most root items (wms,wfs,wcs,postgres...) are considered fast because they are reading data only from QSettings
};
Q_DECLARE_FLAGS( Capabilities, Capability )
// This will _write_ selected crs in data source
virtual bool setCrs( QgsCoordinateReferenceSystem crs )
{ Q_UNUSED( crs ); return false; }
//! @deprecated since 2.8, returned type this will changed to Capabilities
Q_DECL_DEPRECATED virtual Capability capabilities() { return NoCapabilities; }
virtual Capabilities capabilities2() const { return mCapabilities; }
virtual void setCapabilities( Capabilities capabilities ) { mCapabilities = capabilities; }
// static methods
// Find child index in vector of items using '==' operator
static int findItem( QVector<QgsDataItem*> items, QgsDataItem * item );
// members
Type type() const { return mType; }
/** Get item parent. QgsDataItem maintains its own items hierarchy, it does not use
* QObject hierarchy. */
QgsDataItem* parent() const { return mParent; }
/** Set item parent and connect / disconnect parent to / from item signals.
* It does not add itself to parents children (mChildren) */
void setParent( QgsDataItem* parent );
QVector<QgsDataItem*> children() const { return mChildren; }
virtual QIcon icon();
QString name() const { return mName; }
void setName( const QString &name ) { mName = name; }
QString path() const { return mPath; }
void setPath( const QString &path ) { mPath = path; }
//! Create path component replacing path separators
static QString pathComponent( const QString &component );
// Because QIcon (QPixmap) must not be used in outside the GUI thread, it is
// not possible to set mIcon in constructor. Either use mIconName/setIconName()
// or implement icon().
void setIcon( QIcon icon ) { mIcon = icon; }
void setIconName( const QString & iconName ) { mIconName = iconName; }
void setToolTip( QString msg ) { mToolTip = msg; }
QString toolTip() const { return mToolTip; }
// deleteLater() items anc clear the vector
static void deleteLater( QVector<QgsDataItem*> &items );
/** Move object and all its descendants to thread */
void moveToThread( QThread * targetThread );
protected:
virtual void populate( QVector<QgsDataItem*> children );
virtual void refresh( QVector<QgsDataItem*> children );
QIcon populatingIcon() { return mPopulatingIcon; }
/** The item is scheduled to be deleted. E.g. if deleteLater() is called when
* item is in Populating state (createChildren() running in another thread),
* the deferredDelete() returns true and item will be deleted once Populating finished.
* Items with slow reateChildren() (for example network or database based) may
* check during createChildren() if deferredDelete() returns true and return from
* createChildren() immediately because result will be useless. */
bool deferredDelete() { return mDeferredDelete; }
Type mType;
Capabilities mCapabilities;
QgsDataItem* mParent;
QVector<QgsDataItem*> mChildren; // easier to have it always
State mState;
//! @deprecated since 2.8, use mState
bool mPopulated;
QString mName;
// Path is slash ('/') separated chain of item identifiers which are usually item names, but may be differen if it is
// necessary to distinguish paths of two providers to the same source (e.g GRASS location and standard directory have the same
// name but different paths). Identifiers in path must not contain '/' characters.
// The path is used to identify item in tree.
QString mPath;
QString mToolTip;
QString mIconName;
QIcon mIcon;
static QMap<QString, QIcon> mIconMap;
public slots:
/** Safely delete the item:
* - disconnects parent
* - unsets parent (but does not remove itself)
* - deletes all its descendants recursively
* - waits until Populating state (createChildren() in thread) finished without blocking main thread
* - calls QObject::deleteLater()
*/
virtual void deleteLater();
// Populate children using children vector created by createChildren()
// @param foreground run createChildren in foreground
virtual void populate( bool foreground = false );
/** Remove children recursively and set as not populated. This is used when refreshing collapsed items. */
virtual void depopulate();
virtual void refresh();
void emitBeginInsertItems( QgsDataItem* parent, int first, int last );
void emitEndInsertItems();
void emitBeginRemoveItems( QgsDataItem* parent, int first, int last );
void emitEndRemoveItems();
void emitDataChanged( QgsDataItem* item );
void emitDataChanged( );
void emitStateChanged( QgsDataItem* item, QgsDataItem::State oldState );
virtual void childrenCreated();
void setPopulatingIcon();
signals:
void beginInsertItems( QgsDataItem* parent, int first, int last );
void endInsertItems();
void beginRemoveItems( QgsDataItem* parent, int first, int last );
void endRemoveItems();
void dataChanged( QgsDataItem * item );
void stateChanged( QgsDataItem * item, QgsDataItem::State oldState );
private:
static QVector<QgsDataItem*> runCreateChildren( QgsDataItem* item );
// Set to true if object has to be deleted when possible (nothing running in threads)
bool mDeferredDelete;
QFutureWatcher< QVector <QgsDataItem*> > *mFutureWatcher;
// number of items currently in loading (populating) state
static int mPopulatingCount;
static QMovie * mPopulatingMovie;
static QIcon mPopulatingIcon;
};
Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDataItem::Capabilities )
/** 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 ) override;
// --- 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; }
/** Returns the supported CRS
* @note Added in 2.8
*/
QStringList supportedCRS() { return mSupportedCRS; }
/** Returns the supported formats
* @note Added in 2.8
*/
QStringList supportedFormats() { return mSupportFormats; }
protected:
QString mProviderKey;
QString mUri;
LayerType mLayerType;
QStringList mSupportedCRS;
QStringList mSupportFormats;
public:
static const QIcon &iconPoint();
static const QIcon &iconLine();
static const QIcon &iconPolygon();
static const QIcon &iconTable();
static const QIcon &iconRaster();
static const QIcon &iconDefault();
virtual QString layerName() const { return name(); }
};
/** 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 addChild( QgsDataItem *item ) { mChildren.append( item ); }
static const QIcon &iconDir(); // shared icon: open/closed directory
static const QIcon &iconDataCollection(); // default icon for data collection
};
/** 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 );
/** Constructor.
* @param parent
* @param name directory name
* @param dirPath path to directory in file system
* @param path item path in the tree, it may be dirPath or dirPath with some prefix, e.g. favourites: */
QgsDirectoryItem( QgsDataItem* parent, QString name, QString dirPath, QString path );
~QgsDirectoryItem();
virtual void setState( State state ) override;
QVector<QgsDataItem*> createChildren() override;
QString dirPath() const { return mDirPath; }
virtual bool equal( const QgsDataItem *other ) override;
virtual QIcon icon() override;
virtual QWidget *paramWidget() override;
/* static QVector<QgsDataProvider*> mProviders; */
//! @note not available via python bindings
static QVector<QLibrary*> mLibraries;
public slots:
virtual void childrenCreated() override;
void directoryChanged();
protected:
void init();
QString mDirPath;
private:
QFileSystemWatcher * mFileSystemWatcher;
bool mRefreshLater;
};
/**
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();
};
// ---------
class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
{
Q_OBJECT
public:
QgsDirectoryParamWidget( QString path, QWidget* parent = NULL );
protected:
void mousePressEvent( QMouseEvent* event ) override;
public slots:
void showHideColumn();
};
/** Contains various Favourites directories */
class CORE_EXPORT QgsFavouritesItem : public QgsDataCollectionItem
{
Q_OBJECT
public:
QgsFavouritesItem( QgsDataItem* parent, QString name, QString path = QString() );
~QgsFavouritesItem();
QVector<QgsDataItem*> createChildren() override;
void addDirectory( QString favIcon );
void removeDirectory( QgsDirectoryItem *item );
static const QIcon &iconFavourites();
};
/** A zip file: contains layers, using GDAL/OGR VSIFILE mechanism */
class CORE_EXPORT QgsZipItem : public QgsDataCollectionItem
{
Q_OBJECT
protected:
QString mFilePath;
QString mVsiPrefix;
QStringList mZipFileList;
public:
QgsZipItem( QgsDataItem* parent, QString name, QString path );
QgsZipItem( QgsDataItem* parent, QString name, QString filePath, QString path );
~QgsZipItem();
QVector<QgsDataItem*> createChildren() override;
const QStringList & getZipFileList();
//! @note not available via python bindings
static QVector<dataItem_t *> mDataItemPtr;
static QStringList mProviderNames;
static QString vsiPrefix( QString uri ) { return qgsVsiPrefix( uri ); }
static QgsDataItem* itemFromPath( QgsDataItem* parent, QString path, QString name );
static QgsDataItem* itemFromPath( QgsDataItem* parent, QString filePath, QString name, QString path );
static const QIcon &iconZip();
private:
void init();
};
#endif // QGSDATAITEM_H
|