2012-09-24 02:28:15 +02:00
class QgsDataItem : QObject
{
%TypeHeaderCode
#include <qgsdataitem.h>
2015-07-30 13:43:51 +02:00
%End
%ConvertToSubClassCode
if (qobject_cast<QgsLayerItem*>(sipCpp))
sipType = sipType_QgsLayerItem;
else if (qobject_cast<QgsErrorItem*>(sipCpp))
sipType = sipType_QgsErrorItem;
else if (qobject_cast<QgsDirectoryItem*>(sipCpp))
sipType = sipType_QgsDirectoryItem;
else if (qobject_cast<QgsFavouritesItem*>(sipCpp))
sipType = sipType_QgsFavouritesItem;
else if (qobject_cast<QgsZipItem*>(sipCpp))
sipType = sipType_QgsZipItem;
else if (qobject_cast<QgsDataCollectionItem*>(sipCpp))
sipType = sipType_QgsDataCollectionItem;
else
sipType = 0;
2012-09-24 02:28:15 +02:00
%End
public:
enum Type
{
Collection,
Directory,
Layer,
Error,
Favourites
};
2015-02-03 02:21:52 +01:00
/** Create new data item. */
2015-03-04 23:11:25 +07:00
QgsDataItem( QgsDataItem::Type type, QgsDataItem* parent /TransferThis/, QString name, QString path );
2012-09-24 02:28:15 +02:00
virtual ~QgsDataItem();
bool hasChildren();
int rowCount();
2015-02-03 02:21:52 +01:00
/** Create children. Children are not expected to have parent set.
* This method MUST BE THREAD SAFE. */
2012-09-24 22:40:15 +02:00
virtual QVector<QgsDataItem*> createChildren();
2012-09-24 02:28:15 +02:00
2015-02-03 02:21:52 +01:00
enum State
{
NotPopulated, //!< Children not yet created
Populating, //!< Creating children in separate thread (populating or refreshing)
Populated //!< children created
};
2015-03-18 14:17:32 +07:00
//! @note added in 2.8
2015-02-03 02:21:52 +01:00
State state() const;
/** Set item state. It also take care about starting/stopping loading icon animation.
2015-03-18 14:17:32 +07:00
* @param state
* @note added in 2.8
*/
2015-02-03 02:21:52 +01:00
virtual void setState( State state );
//! @deprecated in 2.8, use state()
2013-05-11 21:30:42 +02:00
bool isPopulated();
2012-09-24 02:28:15 +02:00
// 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
2012-09-24 22:40:15 +02:00
virtual void addChildItem( QgsDataItem *child /Transfer/, bool refresh = false );
2012-09-24 02:28:15 +02:00
2012-09-24 22:40:15 +02:00
// remove and delete child item, signals to browser are emitted
2012-09-24 02:28:15 +02:00
virtual void deleteChildItem( QgsDataItem * child );
2013-05-03 19:27:56 +02:00
// remove child item but don't delete it, signals to browser are emitted
2012-09-24 02:28:15 +02:00
// returns pointer to the removed item or null if no such item was found
2012-09-24 22:40:15 +02:00
virtual QgsDataItem *removeChildItem( QgsDataItem * child ) /TransferBack/;
2012-09-24 02:28:15 +02:00
virtual bool equal( const QgsDataItem *other );
2012-09-24 22:40:15 +02:00
virtual QWidget *paramWidget() /Factory/;
2012-09-24 02:28:15 +02:00
// list of actions provided by this item - usually used for popup menu on right-click
virtual QList<QAction*> actions();
// whether accepts drag&drop'd layers - e.g. for import
virtual bool acceptDrop();
// try to process the data dropped on this item
virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ );
enum Capability
{
2014-06-02 21:00:51 +02:00
NoCapabilities,
2015-02-03 02:21:52 +01:00
SetCrs, //!< Can set CRS on layer or group of layers
Fertile, //!< 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 //!< 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
2012-09-24 02:28:15 +02:00
};
2015-02-03 20:47:20 +11:00
typedef QFlags<QgsDataItem::Capability> Capabilities;
2012-09-24 02:28:15 +02:00
// This will _write_ selected crs in data source
virtual bool setCrs( QgsCoordinateReferenceSystem crs );
2015-02-03 02:21:52 +01:00
//! @deprecated since 2.8, returned type this will changed to Capabilities
virtual Capability capabilities() /Deprecated/;
virtual Capabilities capabilities2() const;
virtual void setCapabilities( Capabilities capabilities );
2012-09-24 02:28:15 +02:00
// static methods
// Find child index in vector of items using '==' operator
2012-09-24 22:40:15 +02:00
static int findItem( QVector<QgsDataItem*> items, QgsDataItem * item );
2012-09-24 02:28:15 +02:00
// members
Type type() const;
2015-02-03 02:21:52 +01:00
/** Get item parent. QgsDataItem maintains its own items hierarchy, it does not use
* QObject hierarchy. */
2012-09-24 02:28:15 +02:00
QgsDataItem* parent() const;
2015-02-03 02:21:52 +01:00
/** Set item parent and connect / disconnect parent to / from item signals.
* It does not add itself to parents children (mChildren) */
2012-09-24 02:28:15 +02:00
void setParent( QgsDataItem* parent );
2012-09-24 22:40:15 +02:00
QVector<QgsDataItem*> children() const;
2014-11-12 21:47:25 +01:00
QIcon icon();
2012-09-24 02:28:15 +02:00
QString name() const;
2015-02-03 02:21:52 +01:00
void setName( const QString &name );
2012-09-24 02:28:15 +02:00
QString path() const;
2014-11-10 19:39:55 +01:00
void setPath( const QString );
2015-02-03 02:21:52 +01:00
//! Create path component replacing path separators
static QString pathComponent( const QString &component );
2012-09-24 02:28:15 +02:00
2014-11-20 14:17:51 +01:00
// 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().
2012-09-24 02:28:15 +02:00
void setIcon( QIcon icon );
2015-02-03 02:21:52 +01:00
void setIconName( const QString & iconName );
2012-09-24 02:28:15 +02:00
void setToolTip( QString msg );
QString toolTip() const;
2015-02-03 02:21:52 +01:00
// deleteLater() items anc clear the vector
static void deleteLater( QVector<QgsDataItem*> &items );
/** Move object and all its descendants to thread */
void moveToThread( QThread * targetThread );
2012-09-24 02:28:15 +02:00
public slots:
2015-02-03 02:21:52 +01:00
// Populate children using children vector created by createChildren()
virtual void populate();
/** Remove children recursively and set as not populated. This is used when refreshing collapsed items. */
virtual void depopulate();
virtual void refresh();
2012-09-24 02:28:15 +02:00
void emitBeginInsertItems( QgsDataItem* parent, int first, int last );
void emitEndInsertItems();
void emitBeginRemoveItems( QgsDataItem* parent, int first, int last );
void emitEndRemoveItems();
2015-02-03 02:21:52 +01:00
void emitDataChanged( QgsDataItem* item );
void emitDataChanged( );
void emitStateChanged( QgsDataItem* item, QgsDataItem::State oldState );
virtual void childrenCreated();
2012-09-24 02:28:15 +02:00
signals:
void beginInsertItems( QgsDataItem* parent, int first, int last );
void endInsertItems();
void beginRemoveItems( QgsDataItem* parent, int first, int last );
void endRemoveItems();
};
2015-02-03 20:47:20 +11:00
QFlags<QgsDataItem::Capability> operator|(QgsDataItem::Capability f1, QFlags<QgsDataItem::Capability> f2);
2012-09-24 02:28:15 +02:00
/** Item that represents a layer that can be opened with one of the providers */
class QgsLayerItem : QgsDataItem
{
%TypeHeaderCode
#include <qgsdataitem.h>
%End
public:
enum LayerType
{
NoType,
Vector,
Raster,
Point,
Line,
Polygon,
TableLayer,
Database,
2015-03-18 14:17:32 +07:00
Table,
Plugin //!< added in 2.10
2012-09-24 02:28:15 +02:00
};
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();
// Returns provider key
QString providerKey();
2014-05-24 23:07:22 +02:00
/** Returns the supported CRS
* @note Added in 2.8
*/
QStringList supportedCRS();
/** Returns the supported formats
* @note Added in 2.8
*/
QStringList supportedFormats();
2012-09-24 02:28:15 +02:00
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;
};
/** A Collection: logical collection of layers or subcollections, e.g. GRASS location/mapset, database? wms source? */
class QgsDataCollectionItem : QgsDataItem
{
%TypeHeaderCode
#include <qgsdataitem.h>
%End
public:
QgsDataCollectionItem( QgsDataItem* parent, QString name, QString path = QString::null );
~QgsDataCollectionItem();
2012-09-24 22:40:15 +02:00
void addChild( QgsDataItem *item /Transfer/ );
2012-09-24 02:28:15 +02:00
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 QgsDirectoryItem : QgsDataCollectionItem
{
%TypeHeaderCode
#include <qgsdataitem.h>
%End
public:
enum Column
{
Name,
Size,
Date,
Permissions,
Owner,
Group,
Type
};
2015-02-03 02:21:52 +01:00
2012-09-24 02:28:15 +02:00
QgsDirectoryItem( QgsDataItem* parent, QString name, QString path );
~QgsDirectoryItem();
2015-02-03 20:47:20 +11:00
virtual void setState( State state );
2015-02-03 02:21:52 +01:00
2012-09-24 22:40:15 +02:00
QVector<QgsDataItem*> createChildren();
2012-09-24 02:28:15 +02:00
2015-02-03 02:21:52 +01:00
QString dirPath() const;
2012-09-24 02:28:15 +02:00
virtual bool equal( const QgsDataItem *other );
2015-02-03 02:21:52 +01:00
virtual QIcon icon();
2015-02-03 20:47:20 +11:00
virtual QWidget *paramWidget() /Factory/;
2012-09-24 02:28:15 +02:00
/* static QVector<QgsDataProvider*> mProviders; */
2014-01-27 09:22:24 +01:00
//! @note not available via python bindings
2012-09-24 02:28:15 +02:00
// static QVector<QLibrary*> mLibraries;
};
/**
Data item that can be used to report problems (e.g. network error)
*/
class QgsErrorItem : QgsDataItem
{
%TypeHeaderCode
#include <qgsdataitem.h>
%End
public:
QgsErrorItem( QgsDataItem* parent, QString error, QString path );
~QgsErrorItem();
};
2013-05-11 21:30:42 +02:00
// ---------
2013-05-13 13:46:56 +02:00
class QgsDirectoryParamWidget : QTreeWidget
2013-05-11 21:30:42 +02:00
{
2013-05-13 09:02:21 +02:00
%TypeHeaderCode
#include <qgsdataitem.h>
%End
2013-05-11 21:30:42 +02:00
public:
2015-02-18 17:00:36 +11:00
QgsDirectoryParamWidget( QString path, QWidget* parent /TransferThis/ = NULL );
2013-05-11 21:30:42 +02:00
protected:
void mousePressEvent( QMouseEvent* event );
public slots:
void showHideColumn();
};
2012-09-24 02:28:15 +02:00
/** Contains various Favourites directories */
class QgsFavouritesItem : QgsDataCollectionItem
{
%TypeHeaderCode
#include <qgsdataitem.h>
%End
public:
QgsFavouritesItem( QgsDataItem* parent, QString name, QString path = QString() );
~QgsFavouritesItem();
2012-09-24 22:40:15 +02:00
QVector<QgsDataItem*> createChildren();
2012-09-24 02:28:15 +02:00
2013-05-11 21:30:42 +02:00
void addDirectory( QString favIcon );
void removeDirectory( QgsDirectoryItem *item );
2012-09-24 02:28:15 +02:00
static const QIcon &iconFavourites();
};
/** A zip file: contains layers, using GDAL/OGR VSIFILE mechanism */
class QgsZipItem : QgsDataCollectionItem
{
%TypeHeaderCode
#include <qgsdataitem.h>
%End
public:
QgsZipItem( QgsDataItem* parent, QString name, QString path );
~QgsZipItem();
2012-09-24 22:40:15 +02:00
QVector<QgsDataItem*> createChildren();
2012-09-24 02:28:15 +02:00
const QStringList & getZipFileList();
2014-01-27 09:22:24 +01:00
//! @note not available via python bindings
2012-09-24 02:28:15 +02:00
// static QVector<dataItem_t *> mDataItemPtr;
static QStringList mProviderNames;
static QString vsiPrefix( QString uri );
2012-09-24 22:40:15 +02:00
static QgsDataItem* itemFromPath( QgsDataItem* parent, QString path, QString name ) /Factory/;
2015-02-03 02:21:52 +01:00
static QgsDataItem* itemFromPath( QgsDataItem* parent, QString filePath, QString name, QString path ) /Factory,PyName=itemFromFilePath/;
2012-09-24 02:28:15 +02:00
static const QIcon &iconZip();
};