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