Quantum GIS API Documentation  master-693a1fe
src/core/qgsdataitem.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                  qgsdataitem.h  - Items representing data
00003                              -------------------
00004     begin                : 2011-04-01
00005     copyright            : (C) 2011 Radim Blazek
00006     email                : radim dot blazek at gmail dot com
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 #ifndef QGSDATAITEM_H
00018 #define QGSDATAITEM_H
00019 
00020 #include <QIcon>
00021 #include <QLibrary>
00022 #include <QObject>
00023 #include <QPixmap>
00024 #include <QString>
00025 #include <QVector>
00026 #include <QTreeWidget>
00027 
00028 #include "qgsapplication.h"
00029 #include "qgsmaplayer.h"
00030 #include "qgscoordinatereferencesystem.h"
00031 
00032 class QgsDataProvider;
00033 class QgsDataItem;
00034 
00035 // TODO: bad place, where to put this? qgsproviderregistry.h?
00036 typedef int dataCapabilities_t();
00037 typedef QgsDataItem * dataItem_t( QString, QgsDataItem* );
00038 
00039 
00041 class CORE_EXPORT QgsDataItem : public QObject
00042 {
00043     Q_OBJECT
00044   public:
00045     enum Type
00046     {
00047       Collection,
00048       Directory,
00049       Layer,
00050       Error,
00051       Favourites
00052     };
00053 
00054     QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent, QString name, QString path );
00055     virtual ~QgsDataItem();
00056 
00057     bool hasChildren();
00058 
00059     int rowCount();
00060 
00061     //
00062 
00063     virtual void refresh();
00064 
00065     // Create vector of children
00066     virtual QVector<QgsDataItem*> createChildren();
00067 
00068     // Populate children using children vector created by createChildren()
00069     virtual void populate();
00070     bool isPopulated() { return mPopulated; }
00071 
00072     // Insert new child using alphabetical order based on mName, emits necessary signal to model before and after, sets parent and connects signals
00073     // refresh - refresh populated item, emit signals to model
00074     virtual void addChildItem( QgsDataItem * child, bool refresh = false );
00075 
00076     // remove and delete child item, signals to browser are emitted
00077     virtual void deleteChildItem( QgsDataItem * child );
00078 
00079     // remove child item but don't delete it, signals to browser are emitted
00080     // returns pointer to the removed item or null if no such item was found
00081     virtual QgsDataItem * removeChildItem( QgsDataItem * child );
00082 
00083     virtual bool equal( const QgsDataItem *other );
00084 
00085     virtual QWidget * paramWidget() { return 0; }
00086 
00087     // list of actions provided by this item - usually used for popup menu on right-click
00088     virtual QList<QAction*> actions() { return QList<QAction*>(); }
00089 
00090     // whether accepts drag&drop'd layers - e.g. for import
00091     virtual bool acceptDrop() { return false; }
00092 
00093     // try to process the data dropped on this item
00094     virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ ) { return false; }
00095 
00096     //
00097 
00098     enum Capability
00099     {
00100       NoCapabilities =          0,
00101       SetCrs         =          1 //Can set CRS on layer or group of layers
00102     };
00103 
00104     // This will _write_ selected crs in data source
00105     virtual bool setCrs( QgsCoordinateReferenceSystem crs )
00106     { Q_UNUSED( crs ); return false; }
00107 
00108     virtual Capability capabilities() { return NoCapabilities; }
00109 
00110     // static methods
00111 
00112     // Find child index in vector of items using '==' operator
00113     static int findItem( QVector<QgsDataItem*> items, QgsDataItem * item );
00114 
00115     // members
00116 
00117     Type type() const { return mType; }
00118     QgsDataItem* parent() const { return mParent; }
00119     void setParent( QgsDataItem* parent ) { mParent = parent; }
00120     QVector<QgsDataItem*> children() const { return mChildren; }
00121     QIcon icon() const { return mIcon; }
00122     QString name() const { return mName; }
00123     QString path() const { return mPath; }
00124 
00125     void setIcon( QIcon icon ) { mIcon = icon; }
00126 
00127     void setToolTip( QString msg ) { mToolTip = msg; }
00128     QString toolTip() const { return mToolTip; }
00129 
00130   protected:
00131 
00132     Type mType;
00133     QgsDataItem* mParent;
00134     QVector<QgsDataItem*> mChildren; // easier to have it always
00135     bool mPopulated;
00136     QString mName;
00137     QString mPath; // it is also used to identify item in tree
00138     QString mToolTip;
00139     QIcon mIcon;
00140 
00141   public slots:
00142     void emitBeginInsertItems( QgsDataItem* parent, int first, int last );
00143     void emitEndInsertItems();
00144     void emitBeginRemoveItems( QgsDataItem* parent, int first, int last );
00145     void emitEndRemoveItems();
00146 
00147   signals:
00148     void beginInsertItems( QgsDataItem* parent, int first, int last );
00149     void endInsertItems();
00150     void beginRemoveItems( QgsDataItem* parent, int first, int last );
00151     void endRemoveItems();
00152 };
00153 
00155 class CORE_EXPORT QgsLayerItem : public QgsDataItem
00156 {
00157     Q_OBJECT
00158   public:
00159     enum LayerType
00160     {
00161       NoType,
00162       Vector,
00163       Raster,
00164       Point,
00165       Line,
00166       Polygon,
00167       TableLayer,
00168       Database,
00169       Table
00170     };
00171 
00172     QgsLayerItem( QgsDataItem* parent, QString name, QString path, QString uri, LayerType layerType, QString providerKey );
00173 
00174     // --- reimplemented from QgsDataItem ---
00175 
00176     virtual bool equal( const QgsDataItem *other );
00177 
00178     // --- New virtual methods for layer item derived classes ---
00179 
00180     // Returns QgsMapLayer::LayerType
00181     QgsMapLayer::LayerType mapLayerType();
00182 
00183     // Returns layer uri or empty string if layer cannot be created
00184     QString uri() { return mUri; }
00185 
00186     // Returns provider key
00187     QString providerKey() { return mProviderKey; }
00188 
00189   protected:
00190 
00191     QString mProviderKey;
00192     QString mUri;
00193     LayerType mLayerType;
00194 
00195   public:
00196     static const QIcon &iconPoint();
00197     static const QIcon &iconLine();
00198     static const QIcon &iconPolygon();
00199     static const QIcon &iconTable();
00200     static const QIcon &iconRaster();
00201     static const QIcon &iconDefault();
00202 
00203     virtual QString layerName() const { return name(); }
00204 };
00205 
00206 
00208 class CORE_EXPORT QgsDataCollectionItem : public QgsDataItem
00209 {
00210     Q_OBJECT
00211   public:
00212     QgsDataCollectionItem( QgsDataItem* parent, QString name, QString path = QString::null );
00213     ~QgsDataCollectionItem();
00214 
00215     void setPopulated() { mPopulated = true; }
00216     void addChild( QgsDataItem *item ) { mChildren.append( item ); }
00217 
00218     static const QIcon &iconDir(); // shared icon: open/closed directory
00219     static const QIcon &iconDataCollection(); // default icon for data collection
00220 };
00221 
00223 class CORE_EXPORT QgsDirectoryItem : public QgsDataCollectionItem
00224 {
00225     Q_OBJECT
00226   public:
00227     enum Column
00228     {
00229       Name,
00230       Size,
00231       Date,
00232       Permissions,
00233       Owner,
00234       Group,
00235       Type
00236     };
00237     QgsDirectoryItem( QgsDataItem* parent, QString name, QString path );
00238     ~QgsDirectoryItem();
00239 
00240     QVector<QgsDataItem*> createChildren();
00241 
00242     virtual bool equal( const QgsDataItem *other );
00243 
00244     virtual QWidget *paramWidget();
00245 
00246     /* static QVector<QgsDataProvider*> mProviders; */
00248     static QVector<QLibrary*> mLibraries;
00249 };
00250 
00254 class CORE_EXPORT QgsErrorItem : public QgsDataItem
00255 {
00256     Q_OBJECT
00257   public:
00258 
00259     QgsErrorItem( QgsDataItem* parent, QString error, QString path );
00260     ~QgsErrorItem();
00261 
00262     //QVector<QgsDataItem*> createChildren();
00263     //virtual bool equal( const QgsDataItem *other );
00264 };
00265 
00266 
00267 // ---------
00268 
00269 class CORE_EXPORT QgsDirectoryParamWidget : public QTreeWidget
00270 {
00271     Q_OBJECT
00272 
00273   public:
00274     QgsDirectoryParamWidget( QString path, QWidget* parent = NULL );
00275 
00276   protected:
00277     void mousePressEvent( QMouseEvent* event );
00278 
00279   public slots:
00280     void showHideColumn();
00281 };
00282 
00284 class CORE_EXPORT QgsFavouritesItem : public QgsDataCollectionItem
00285 {
00286     Q_OBJECT
00287   public:
00288     QgsFavouritesItem( QgsDataItem* parent, QString name, QString path = QString() );
00289     ~QgsFavouritesItem();
00290 
00291     QVector<QgsDataItem*> createChildren();
00292 
00293     void addDirectory( QString favIcon );
00294     void removeDirectory( QgsDirectoryItem *item );
00295 
00296     static const QIcon &iconFavourites();
00297 };
00298 
00300 class CORE_EXPORT QgsZipItem : public QgsDataCollectionItem
00301 {
00302     Q_OBJECT
00303 
00304   protected:
00305     QString mVsiPrefix;
00306     QStringList mZipFileList;
00307 
00308   public:
00309     QgsZipItem( QgsDataItem* parent, QString name, QString path );
00310     ~QgsZipItem();
00311 
00312     QVector<QgsDataItem*> createChildren();
00313     const QStringList & getZipFileList();
00314 
00316     static QVector<dataItem_t *> mDataItemPtr;
00317     static QStringList mProviderNames;
00318 
00319     static QString vsiPrefix( QString uri );
00320 
00321     static QgsDataItem* itemFromPath( QgsDataItem* parent, QString path, QString name );
00322 
00323     static const QIcon &iconZip();
00324 
00325 };
00326 
00327 #endif // QGSDATAITEM_H
00328 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines