mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-07 00:15:48 -04:00
[FEATURE] API to allow drag'n'drop of custom browser items
QgsDataItem implementations may provide hasDragEnabled(), mimeUri() and QgsCustomDropHandler implementation to deal with drop of custom items.
This commit is contained in:
parent
2ea828e1b3
commit
b4fe9002d8
@ -450,6 +450,12 @@ be returned instead of a null pointer if no transformation is required.</li>
|
|||||||
plugins calling this method will need to be updated.</li>
|
plugins calling this method will need to be updated.</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
\subsection qgis_api_break_3_0_QgsMimeDataUtils QgsMimeDataUtils
|
||||||
|
|
||||||
|
<ul>
|
||||||
|
<li>Constructor taking QgsLayerItem argument has been removed. Use QgsDataItem::mimeUri() instead.</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
\subsection qgis_api_break_3_0_QgsOSMElement QgsOSMElement
|
\subsection qgis_api_break_3_0_QgsOSMElement QgsOSMElement
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
|
@ -135,6 +135,21 @@ class QgsDataItem : QObject
|
|||||||
*/
|
*/
|
||||||
virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ );
|
virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ );
|
||||||
|
|
||||||
|
/** Returns true if the item may be dragged.
|
||||||
|
* Default implementation returns false.
|
||||||
|
* A draggable item has to implement mimeUri() that will be used to pass data.
|
||||||
|
* @see mimeUri()
|
||||||
|
* @note added in 3.0
|
||||||
|
*/
|
||||||
|
virtual bool hasDragEnabled() const;
|
||||||
|
|
||||||
|
/** Return mime URI for the data item.
|
||||||
|
* Items that return valid URI will be returned in mime data when dragging a selection from browser model.
|
||||||
|
* @see hasDragEnabled()
|
||||||
|
* @note added in 3.0
|
||||||
|
*/
|
||||||
|
virtual QgsMimeDataUtils::Uri mimeUri() const;
|
||||||
|
|
||||||
enum Capability
|
enum Capability
|
||||||
{
|
{
|
||||||
NoCapabilities,
|
NoCapabilities,
|
||||||
@ -262,26 +277,30 @@ class QgsLayerItem : QgsDataItem
|
|||||||
|
|
||||||
virtual bool equal( const QgsDataItem *other );
|
virtual bool equal( const QgsDataItem *other );
|
||||||
|
|
||||||
|
virtual bool hasDragEnabled() const;
|
||||||
|
|
||||||
|
virtual QgsMimeDataUtils::Uri mimeUri() const;
|
||||||
|
|
||||||
// --- New virtual methods for layer item derived classes ---
|
// --- New virtual methods for layer item derived classes ---
|
||||||
|
|
||||||
// Returns QgsMapLayer::LayerType
|
// Returns QgsMapLayer::LayerType
|
||||||
QgsMapLayer::LayerType mapLayerType();
|
QgsMapLayer::LayerType mapLayerType() const;
|
||||||
|
|
||||||
// Returns layer uri or empty string if layer cannot be created
|
// Returns layer uri or empty string if layer cannot be created
|
||||||
QString uri();
|
QString uri() const;
|
||||||
|
|
||||||
// Returns provider key
|
// Returns provider key
|
||||||
QString providerKey();
|
QString providerKey() const;
|
||||||
|
|
||||||
/** Returns the supported CRS
|
/** Returns the supported CRS
|
||||||
* @note Added in 2.8
|
* @note Added in 2.8
|
||||||
*/
|
*/
|
||||||
QStringList supportedCrs();
|
QStringList supportedCrs() const;
|
||||||
|
|
||||||
/** Returns the supported formats
|
/** Returns the supported formats
|
||||||
* @note Added in 2.8
|
* @note Added in 2.8
|
||||||
*/
|
*/
|
||||||
QStringList supportedFormats();
|
QStringList supportedFormats() const;
|
||||||
|
|
||||||
/** Returns comments of the layer
|
/** Returns comments of the layer
|
||||||
* @note added in 2.12
|
* @note added in 2.12
|
||||||
@ -389,6 +408,7 @@ class QgsProjectItem : QgsDataItem
|
|||||||
QgsProjectItem( QgsDataItem* parent, const QString& name, const QString& path );
|
QgsProjectItem( QgsDataItem* parent, const QString& name, const QString& path );
|
||||||
~QgsProjectItem();
|
~QgsProjectItem();
|
||||||
|
|
||||||
|
virtual bool hasDragEnabled() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,14 +7,27 @@ class QgsMimeDataUtils
|
|||||||
|
|
||||||
struct Uri
|
struct Uri
|
||||||
{
|
{
|
||||||
Uri( QgsLayerItem* layer );
|
//! Constructs invalid URI
|
||||||
Uri( QString& encData );
|
Uri();
|
||||||
|
//! Constructs URI from encoded data
|
||||||
|
explicit Uri( QString& encData );
|
||||||
|
|
||||||
|
//! Returns whether the object contains valid data
|
||||||
|
//! @note added in 3.0
|
||||||
|
bool isValid() const;
|
||||||
|
|
||||||
|
//! Returns encoded representation of the object
|
||||||
QString data() const;
|
QString data() const;
|
||||||
|
|
||||||
|
//! Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom"
|
||||||
QString layerType;
|
QString layerType;
|
||||||
|
//! For "vector" / "raster" type: provider id.
|
||||||
|
//! For "plugin" type: plugin layer type name.
|
||||||
|
//! For "custom" type: key of its QgsCustomDropHandler
|
||||||
QString providerKey;
|
QString providerKey;
|
||||||
|
//! Human readable name to be used e.g. in layer tree
|
||||||
QString name;
|
QString name;
|
||||||
|
//! Identifier of the data source recognized by its providerKey
|
||||||
QString uri;
|
QString uri;
|
||||||
QStringList supportedCrs;
|
QStringList supportedCrs;
|
||||||
QStringList supportedFormats;
|
QStringList supportedFormats;
|
||||||
|
@ -57,6 +57,7 @@
|
|||||||
%Include qgscompoundcolorwidget.sip
|
%Include qgscompoundcolorwidget.sip
|
||||||
%Include qgsconfigureshortcutsdialog.sip
|
%Include qgsconfigureshortcutsdialog.sip
|
||||||
%Include qgscredentialdialog.sip
|
%Include qgscredentialdialog.sip
|
||||||
|
%Include qgscustomdrophandler.sip
|
||||||
%Include qgsdatadefinedbutton.sip
|
%Include qgsdatadefinedbutton.sip
|
||||||
%Include qgsdetaileditemdata.sip
|
%Include qgsdetaileditemdata.sip
|
||||||
%Include qgsdetaileditemdelegate.sip
|
%Include qgsdetaileditemdelegate.sip
|
||||||
|
@ -292,6 +292,18 @@ class QgisInterface : QObject
|
|||||||
*/
|
*/
|
||||||
virtual void unregisterMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory* factory ) = 0;
|
virtual void unregisterMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory* factory ) = 0;
|
||||||
|
|
||||||
|
/** Register a new custom drop handler.
|
||||||
|
* @note added in QGIS 3.0
|
||||||
|
* @note Ownership of the factory is not transferred, and the factory must
|
||||||
|
* be unregistered when plugin is unloaded.
|
||||||
|
* @see unregisterCustomDropHandler() */
|
||||||
|
virtual void registerCustomDropHandler( QgsCustomDropHandler* handler ) = 0;
|
||||||
|
|
||||||
|
/** Unregister a previously registered custom drop handler.
|
||||||
|
* @note added in QGIS 3.0
|
||||||
|
* @see registerCustomDropHandler() */
|
||||||
|
virtual void unregisterCustomDropHandler( QgsCustomDropHandler* handler ) = 0;
|
||||||
|
|
||||||
// @todo is this deprecated in favour of QgsContextHelp?
|
// @todo is this deprecated in favour of QgsContextHelp?
|
||||||
/** Open a url in the users browser. By default the QGIS doc directory is used
|
/** Open a url in the users browser. By default the QGIS doc directory is used
|
||||||
* as the base for the URL. To open a URL that is not relative to the installed
|
* as the base for the URL. To open a URL that is not relative to the installed
|
||||||
|
21
python/gui/qgscustomdrophandler.sip
Normal file
21
python/gui/qgscustomdrophandler.sip
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/** \ingroup gui
|
||||||
|
* Abstract base class that may be implemented to handle new types of data to be dropped in QGIS.
|
||||||
|
* Implementations will be used when a QgsMimeDataUtils::Uri has layerType equal to "custom",
|
||||||
|
* and the providerKey is equal to key() returned by the implementation.
|
||||||
|
* @note added in QGIS 3.0
|
||||||
|
*/
|
||||||
|
class QgsCustomDropHandler
|
||||||
|
{
|
||||||
|
%TypeHeaderCode
|
||||||
|
#include <qgscustomdrophandler.h>
|
||||||
|
%End
|
||||||
|
|
||||||
|
public:
|
||||||
|
virtual ~QgsCustomDropHandler();
|
||||||
|
|
||||||
|
//! Type of custom URI recognized by the handler
|
||||||
|
virtual QString key() const = 0;
|
||||||
|
|
||||||
|
//! Method called from QGIS after a drop event with custom URI known by the handler
|
||||||
|
virtual void handleDrop( const QgsMimeDataUtils::Uri& uri ) const = 0;
|
||||||
|
};
|
@ -128,6 +128,7 @@
|
|||||||
#include "qgscoordinateutils.h"
|
#include "qgscoordinateutils.h"
|
||||||
#include "qgscredentialdialog.h"
|
#include "qgscredentialdialog.h"
|
||||||
#include "qgscursors.h"
|
#include "qgscursors.h"
|
||||||
|
#include "qgscustomdrophandler.h"
|
||||||
#include "qgscustomization.h"
|
#include "qgscustomization.h"
|
||||||
#include "qgscustomlayerorderwidget.h"
|
#include "qgscustomlayerorderwidget.h"
|
||||||
#include "qgscustomprojectiondialog.h"
|
#include "qgscustomprojectiondialog.h"
|
||||||
@ -1341,29 +1342,58 @@ void QgisApp::dropEvent( QDropEvent *event )
|
|||||||
if ( QgsMimeDataUtils::isUriList( event->mimeData() ) )
|
if ( QgsMimeDataUtils::isUriList( event->mimeData() ) )
|
||||||
{
|
{
|
||||||
QgsMimeDataUtils::UriList lst = QgsMimeDataUtils::decodeUriList( event->mimeData() );
|
QgsMimeDataUtils::UriList lst = QgsMimeDataUtils::decodeUriList( event->mimeData() );
|
||||||
Q_FOREACH ( const QgsMimeDataUtils::Uri& u, lst )
|
handleDropUriList( lst );
|
||||||
{
|
|
||||||
QString uri = crsAndFormatAdjustedLayerUri( u.uri, u.supportedCrs, u.supportedFormats );
|
|
||||||
|
|
||||||
if ( u.layerType == "vector" )
|
|
||||||
{
|
|
||||||
addVectorLayer( uri, u.name, u.providerKey );
|
|
||||||
}
|
|
||||||
else if ( u.layerType == "raster" )
|
|
||||||
{
|
|
||||||
addRasterLayer( uri, u.name, u.providerKey );
|
|
||||||
}
|
|
||||||
else if ( u.layerType == "plugin" )
|
|
||||||
{
|
|
||||||
addPluginLayer( uri, u.name, u.providerKey );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
mMapCanvas->freeze( false );
|
mMapCanvas->freeze( false );
|
||||||
mMapCanvas->refresh();
|
mMapCanvas->refresh();
|
||||||
event->acceptProposedAction();
|
event->acceptProposedAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void QgisApp::registerCustomDropHandler( QgsCustomDropHandler* handler )
|
||||||
|
{
|
||||||
|
if ( !mCustomDropHandlers.contains( handler ) )
|
||||||
|
mCustomDropHandlers << handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgisApp::unregisterCustomDropHandler( QgsCustomDropHandler* handler )
|
||||||
|
{
|
||||||
|
mCustomDropHandlers.removeOne( handler );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgisApp::handleDropUriList( const QgsMimeDataUtils::UriList& lst )
|
||||||
|
{
|
||||||
|
Q_FOREACH ( const QgsMimeDataUtils::Uri& u, lst )
|
||||||
|
{
|
||||||
|
QString uri = crsAndFormatAdjustedLayerUri( u.uri, u.supportedCrs, u.supportedFormats );
|
||||||
|
|
||||||
|
if ( u.layerType == "vector" )
|
||||||
|
{
|
||||||
|
addVectorLayer( uri, u.name, u.providerKey );
|
||||||
|
}
|
||||||
|
else if ( u.layerType == "raster" )
|
||||||
|
{
|
||||||
|
addRasterLayer( uri, u.name, u.providerKey );
|
||||||
|
}
|
||||||
|
else if ( u.layerType == "plugin" )
|
||||||
|
{
|
||||||
|
addPluginLayer( uri, u.name, u.providerKey );
|
||||||
|
}
|
||||||
|
else if ( u.layerType == "custom" )
|
||||||
|
{
|
||||||
|
Q_FOREACH ( QgsCustomDropHandler* handler, mCustomDropHandlers )
|
||||||
|
{
|
||||||
|
if ( handler->key() == u.providerKey )
|
||||||
|
{
|
||||||
|
handler->handleDrop( u );
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool QgisApp::event( QEvent * event )
|
bool QgisApp::event( QEvent * event )
|
||||||
{
|
{
|
||||||
bool done = false;
|
bool done = false;
|
||||||
|
@ -44,6 +44,7 @@ class QgsClipboard;
|
|||||||
class QgsComposer;
|
class QgsComposer;
|
||||||
class QgsComposerManager;
|
class QgsComposerManager;
|
||||||
class QgsComposerView;
|
class QgsComposerView;
|
||||||
|
class QgsCustomDropHandler;
|
||||||
class QgsStatusBarCoordinatesWidget;
|
class QgsStatusBarCoordinatesWidget;
|
||||||
class QgsStatusBarMagnifierWidget;
|
class QgsStatusBarMagnifierWidget;
|
||||||
class QgsStatusBarScaleWidget;
|
class QgsStatusBarScaleWidget;
|
||||||
@ -120,6 +121,7 @@ class QgsDiagramProperties;
|
|||||||
#include "qgsfeature.h"
|
#include "qgsfeature.h"
|
||||||
#include "qgspoint.h"
|
#include "qgspoint.h"
|
||||||
#include "qgsmessagebar.h"
|
#include "qgsmessagebar.h"
|
||||||
|
#include "qgsmimedatautils.h"
|
||||||
#include "qgswelcomepageitemsmodel.h"
|
#include "qgswelcomepageitemsmodel.h"
|
||||||
#include "qgsraster.h"
|
#include "qgsraster.h"
|
||||||
|
|
||||||
@ -513,6 +515,15 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
|
|||||||
/** Unregister a previously registered tab in the layer properties dialog */
|
/** Unregister a previously registered tab in the layer properties dialog */
|
||||||
void unregisterMapLayerPropertiesFactory( QgsMapLayerConfigWidgetFactory* factory );
|
void unregisterMapLayerPropertiesFactory( QgsMapLayerConfigWidgetFactory* factory );
|
||||||
|
|
||||||
|
/** Register a new custom drop handler. */
|
||||||
|
void registerCustomDropHandler( QgsCustomDropHandler* handler );
|
||||||
|
|
||||||
|
/** Unregister a previously registered custom drop handler. */
|
||||||
|
void unregisterCustomDropHandler( QgsCustomDropHandler* handler );
|
||||||
|
|
||||||
|
/** Process the list of URIs that have been dropped in QGIS */
|
||||||
|
void handleDropUriList( const QgsMimeDataUtils::UriList& lst );
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void layerTreeViewDoubleClicked( const QModelIndex& index );
|
void layerTreeViewDoubleClicked( const QModelIndex& index );
|
||||||
//! Make sure the insertion point for new layers is up-to-date with the current item in layer tree view
|
//! Make sure the insertion point for new layers is up-to-date with the current item in layer tree view
|
||||||
@ -1772,6 +1783,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
|
|||||||
|
|
||||||
QList<QgsMapLayerConfigWidgetFactory*> mMapLayerPanelFactories;
|
QList<QgsMapLayerConfigWidgetFactory*> mMapLayerPanelFactories;
|
||||||
|
|
||||||
|
QList<QgsCustomDropHandler*> mCustomDropHandlers;
|
||||||
|
|
||||||
QDateTime mProjectLastModified;
|
QDateTime mProjectLastModified;
|
||||||
|
|
||||||
QgsWelcomePage* mWelcomePage;
|
QgsWelcomePage* mWelcomePage;
|
||||||
|
@ -485,6 +485,16 @@ void QgisAppInterface::unregisterMapLayerConfigWidgetFactory( QgsMapLayerConfigW
|
|||||||
qgis->unregisterMapLayerPropertiesFactory( factory );
|
qgis->unregisterMapLayerPropertiesFactory( factory );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QgisAppInterface::registerCustomDropHandler( QgsCustomDropHandler *handler )
|
||||||
|
{
|
||||||
|
qgis->registerCustomDropHandler( handler );
|
||||||
|
}
|
||||||
|
|
||||||
|
void QgisAppInterface::unregisterCustomDropHandler( QgsCustomDropHandler *handler )
|
||||||
|
{
|
||||||
|
qgis->unregisterCustomDropHandler( handler );
|
||||||
|
}
|
||||||
|
|
||||||
//! Menus
|
//! Menus
|
||||||
QMenu *QgisAppInterface::projectMenu() { return qgis->projectMenu(); }
|
QMenu *QgisAppInterface::projectMenu() { return qgis->projectMenu(); }
|
||||||
QMenu *QgisAppInterface::editMenu() { return qgis->editMenu(); }
|
QMenu *QgisAppInterface::editMenu() { return qgis->editMenu(); }
|
||||||
|
@ -301,6 +301,18 @@ class APP_EXPORT QgisAppInterface : public QgisInterface
|
|||||||
*/
|
*/
|
||||||
virtual void unregisterMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory* factory ) override;
|
virtual void unregisterMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory* factory ) override;
|
||||||
|
|
||||||
|
/** Register a new custom drop handler.
|
||||||
|
* @note added in QGIS 3.0
|
||||||
|
* @note Ownership of the factory is not transferred, and the factory must
|
||||||
|
* be unregistered when plugin is unloaded.
|
||||||
|
* @see unregisterCustomDropHandler() */
|
||||||
|
virtual void registerCustomDropHandler( QgsCustomDropHandler* handler ) override;
|
||||||
|
|
||||||
|
/** Unregister a previously registered custom drop handler.
|
||||||
|
* @note added in QGIS 3.0
|
||||||
|
* @see registerCustomDropHandler() */
|
||||||
|
virtual void unregisterCustomDropHandler( QgsCustomDropHandler* handler ) override;
|
||||||
|
|
||||||
/** Accessors for inserting items into menus and toolbars.
|
/** Accessors for inserting items into menus and toolbars.
|
||||||
* An item can be inserted before any existing action.
|
* An item can be inserted before any existing action.
|
||||||
*/
|
*/
|
||||||
|
@ -516,26 +516,9 @@ void QgsBrowserDockWidget::addLayer( QgsLayerItem *layerItem )
|
|||||||
if ( !layerItem )
|
if ( !layerItem )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QString uri = QgisApp::instance()->crsAndFormatAdjustedLayerUri( layerItem->uri(), layerItem->supportedCrs(), layerItem->supportedFormats() );
|
QgsMimeDataUtils::UriList list;
|
||||||
if ( uri.isEmpty() )
|
list << layerItem->mimeUri();
|
||||||
return;
|
QgisApp::instance()->handleDropUriList( list );
|
||||||
|
|
||||||
QgsMapLayer::LayerType type = layerItem->mapLayerType();
|
|
||||||
QString providerKey = layerItem->providerKey();
|
|
||||||
|
|
||||||
QgsDebugMsg( providerKey + " : " + uri );
|
|
||||||
if ( type == QgsMapLayer::VectorLayer )
|
|
||||||
{
|
|
||||||
QgisApp::instance()->addVectorLayer( uri, layerItem->layerName(), providerKey );
|
|
||||||
}
|
|
||||||
if ( type == QgsMapLayer::RasterLayer )
|
|
||||||
{
|
|
||||||
QgisApp::instance()->addRasterLayer( uri, layerItem->layerName(), providerKey );
|
|
||||||
}
|
|
||||||
if ( type == QgsMapLayer::PluginLayer )
|
|
||||||
{
|
|
||||||
QgisApp::instance()->addPluginLayer( uri, layerItem->layerName(), providerKey );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex& index )
|
void QgsBrowserDockWidget::addLayerAtIndex( const QModelIndex& index )
|
||||||
|
@ -186,10 +186,9 @@ Qt::ItemFlags QgsBrowserModel::flags( const QModelIndex & index ) const
|
|||||||
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
|
||||||
|
|
||||||
QgsDataItem* ptr = reinterpret_cast< QgsDataItem* >( index.internalPointer() );
|
QgsDataItem* ptr = reinterpret_cast< QgsDataItem* >( index.internalPointer() );
|
||||||
if ( ptr->type() == QgsDataItem::Layer || ptr->type() == QgsDataItem::Project )
|
if ( ptr->hasDragEnabled() )
|
||||||
{
|
|
||||||
flags |= Qt::ItemIsDragEnabled;
|
flags |= Qt::ItemIsDragEnabled;
|
||||||
}
|
|
||||||
if ( ptr->acceptDrop() )
|
if ( ptr->acceptDrop() )
|
||||||
flags |= Qt::ItemIsDropEnabled;
|
flags |= Qt::ItemIsDropEnabled;
|
||||||
return flags;
|
return flags;
|
||||||
@ -461,9 +460,9 @@ QMimeData * QgsBrowserModel::mimeData( const QModelIndexList &indexes ) const
|
|||||||
return mimeData;
|
return mimeData;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ptr->type() != QgsDataItem::Layer ) continue;
|
QgsMimeDataUtils::Uri uri = ptr->mimeUri();
|
||||||
QgsLayerItem *layer = static_cast< QgsLayerItem* >( ptr );
|
if ( uri.isValid() )
|
||||||
lst.append( QgsMimeDataUtils::Uri( layer ) );
|
lst.append( uri );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QgsMimeDataUtils::encodeUriList( lst );
|
return QgsMimeDataUtils::encodeUriList( lst );
|
||||||
|
@ -670,7 +670,7 @@ QgsLayerItem::QgsLayerItem( QgsDataItem* parent, const QString& name, const QStr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsMapLayer::LayerType QgsLayerItem::mapLayerType()
|
QgsMapLayer::LayerType QgsLayerItem::mapLayerType() const
|
||||||
{
|
{
|
||||||
if ( mLayerType == QgsLayerItem::Raster )
|
if ( mLayerType == QgsLayerItem::Raster )
|
||||||
return QgsMapLayer::RasterLayer;
|
return QgsMapLayer::RasterLayer;
|
||||||
@ -694,6 +694,33 @@ bool QgsLayerItem::equal( const QgsDataItem *other )
|
|||||||
return ( mPath == o->mPath && mName == o->mName && mUri == o->mUri && mProviderKey == o->mProviderKey );
|
return ( mPath == o->mPath && mName == o->mName && mUri == o->mUri && mProviderKey == o->mProviderKey );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QgsMimeDataUtils::Uri QgsLayerItem::mimeUri() const
|
||||||
|
{
|
||||||
|
QgsMimeDataUtils::Uri u;
|
||||||
|
|
||||||
|
switch ( mapLayerType() )
|
||||||
|
{
|
||||||
|
case QgsMapLayer::VectorLayer:
|
||||||
|
u.layerType = "vector";
|
||||||
|
break;
|
||||||
|
case QgsMapLayer::RasterLayer:
|
||||||
|
u.layerType = "raster";
|
||||||
|
break;
|
||||||
|
case QgsMapLayer::PluginLayer:
|
||||||
|
u.layerType = "plugin";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return u; // invalid URI
|
||||||
|
}
|
||||||
|
|
||||||
|
u.providerKey = providerKey();
|
||||||
|
u.name = layerName();
|
||||||
|
u.uri = uri();
|
||||||
|
u.supportedCrs = supportedCrs();
|
||||||
|
u.supportedFormats = supportedFormats();
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
QgsDataCollectionItem::QgsDataCollectionItem( QgsDataItem* parent, const QString& name, const QString& path )
|
QgsDataCollectionItem::QgsDataCollectionItem( QgsDataItem* parent, const QString& name, const QString& path )
|
||||||
: QgsDataItem( Collection, parent, name, path )
|
: QgsDataItem( Collection, parent, name, path )
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
#include "qgsmaplayer.h"
|
#include "qgsmaplayer.h"
|
||||||
#include "qgscoordinatereferencesystem.h"
|
#include "qgscoordinatereferencesystem.h"
|
||||||
|
#include "qgsmimedatautils.h"
|
||||||
|
|
||||||
class QgsDataProvider;
|
class QgsDataProvider;
|
||||||
class QgsDataItem;
|
class QgsDataItem;
|
||||||
@ -161,6 +162,21 @@ class CORE_EXPORT QgsDataItem : public QObject
|
|||||||
*/
|
*/
|
||||||
virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ ) { return false; }
|
virtual bool handleDrop( const QMimeData * /*data*/, Qt::DropAction /*action*/ ) { return false; }
|
||||||
|
|
||||||
|
/** Returns true if the item may be dragged.
|
||||||
|
* Default implementation returns false.
|
||||||
|
* A draggable item has to implement mimeUri() that will be used to pass data.
|
||||||
|
* @see mimeUri()
|
||||||
|
* @note added in 3.0
|
||||||
|
*/
|
||||||
|
virtual bool hasDragEnabled() const { return false; }
|
||||||
|
|
||||||
|
/** Return mime URI for the data item.
|
||||||
|
* Items that return valid URI will be returned in mime data when dragging a selection from browser model.
|
||||||
|
* @see hasDragEnabled()
|
||||||
|
* @note added in 3.0
|
||||||
|
*/
|
||||||
|
virtual QgsMimeDataUtils::Uri mimeUri() const { return QgsMimeDataUtils::Uri(); }
|
||||||
|
|
||||||
enum Capability
|
enum Capability
|
||||||
{
|
{
|
||||||
NoCapabilities = 0,
|
NoCapabilities = 0,
|
||||||
@ -314,26 +330,30 @@ class CORE_EXPORT QgsLayerItem : public QgsDataItem
|
|||||||
|
|
||||||
virtual bool equal( const QgsDataItem *other ) override;
|
virtual bool equal( const QgsDataItem *other ) override;
|
||||||
|
|
||||||
|
virtual bool hasDragEnabled() const override { return true; }
|
||||||
|
|
||||||
|
virtual QgsMimeDataUtils::Uri mimeUri() const override;
|
||||||
|
|
||||||
// --- New virtual methods for layer item derived classes ---
|
// --- New virtual methods for layer item derived classes ---
|
||||||
|
|
||||||
/** Returns QgsMapLayer::LayerType */
|
/** Returns QgsMapLayer::LayerType */
|
||||||
QgsMapLayer::LayerType mapLayerType();
|
QgsMapLayer::LayerType mapLayerType() const;
|
||||||
|
|
||||||
/** Returns layer uri or empty string if layer cannot be created */
|
/** Returns layer uri or empty string if layer cannot be created */
|
||||||
QString uri() { return mUri; }
|
QString uri() const { return mUri; }
|
||||||
|
|
||||||
/** Returns provider key */
|
/** Returns provider key */
|
||||||
QString providerKey() { return mProviderKey; }
|
QString providerKey() const { return mProviderKey; }
|
||||||
|
|
||||||
/** Returns the supported CRS
|
/** Returns the supported CRS
|
||||||
* @note Added in 2.8
|
* @note Added in 2.8
|
||||||
*/
|
*/
|
||||||
QStringList supportedCrs() { return mSupportedCRS; }
|
QStringList supportedCrs() const { return mSupportedCRS; }
|
||||||
|
|
||||||
/** Returns the supported formats
|
/** Returns the supported formats
|
||||||
* @note Added in 2.8
|
* @note Added in 2.8
|
||||||
*/
|
*/
|
||||||
QStringList supportedFormats() { return mSupportFormats; }
|
QStringList supportedFormats() const { return mSupportFormats; }
|
||||||
|
|
||||||
/** Returns comments of the layer
|
/** Returns comments of the layer
|
||||||
* @note added in 2.12
|
* @note added in 2.12
|
||||||
@ -452,6 +472,8 @@ class CORE_EXPORT QgsProjectItem : public QgsDataItem
|
|||||||
QgsProjectItem( QgsDataItem* parent, const QString& name, const QString& path );
|
QgsProjectItem( QgsDataItem* parent, const QString& name, const QString& path );
|
||||||
~QgsProjectItem();
|
~QgsProjectItem();
|
||||||
|
|
||||||
|
virtual bool hasDragEnabled() const override { return true; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \ingroup core
|
/** \ingroup core
|
||||||
|
@ -21,25 +21,9 @@
|
|||||||
|
|
||||||
static const char* QGIS_URILIST_MIMETYPE = "application/x-vnd.qgis.qgis.uri";
|
static const char* QGIS_URILIST_MIMETYPE = "application/x-vnd.qgis.qgis.uri";
|
||||||
|
|
||||||
QgsMimeDataUtils::Uri::Uri( QgsLayerItem* layerItem )
|
|
||||||
: providerKey( layerItem->providerKey() )
|
QgsMimeDataUtils::Uri::Uri()
|
||||||
, name( layerItem->layerName() )
|
|
||||||
, uri( layerItem->uri() )
|
|
||||||
, supportedCrs( layerItem->supportedCrs() )
|
|
||||||
, supportedFormats( layerItem->supportedFormats() )
|
|
||||||
{
|
{
|
||||||
switch ( layerItem->mapLayerType() )
|
|
||||||
{
|
|
||||||
case QgsMapLayer::VectorLayer:
|
|
||||||
layerType = "vector";
|
|
||||||
break;
|
|
||||||
case QgsMapLayer::RasterLayer:
|
|
||||||
layerType = "raster";
|
|
||||||
break;
|
|
||||||
case QgsMapLayer::PluginLayer:
|
|
||||||
layerType = "plugin";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QgsMimeDataUtils::Uri::Uri( QString& encData )
|
QgsMimeDataUtils::Uri::Uri( QString& encData )
|
||||||
|
@ -29,14 +29,27 @@ class CORE_EXPORT QgsMimeDataUtils
|
|||||||
|
|
||||||
struct CORE_EXPORT Uri
|
struct CORE_EXPORT Uri
|
||||||
{
|
{
|
||||||
Uri( QgsLayerItem* layer );
|
//! Constructs invalid URI
|
||||||
Uri( QString& encData );
|
Uri();
|
||||||
|
//! Constructs URI from encoded data
|
||||||
|
explicit Uri( QString& encData );
|
||||||
|
|
||||||
|
//! Returns whether the object contains valid data
|
||||||
|
//! @note added in 3.0
|
||||||
|
bool isValid() const { return !layerType.isEmpty(); }
|
||||||
|
|
||||||
|
//! Returns encoded representation of the object
|
||||||
QString data() const;
|
QString data() const;
|
||||||
|
|
||||||
|
//! Type of URI. Recognized types: "vector" / "raster" / "plugin" / "custom"
|
||||||
QString layerType;
|
QString layerType;
|
||||||
|
//! For "vector" / "raster" type: provider id.
|
||||||
|
//! For "plugin" type: plugin layer type name.
|
||||||
|
//! For "custom" type: key of its QgsCustomDropHandler
|
||||||
QString providerKey;
|
QString providerKey;
|
||||||
|
//! Human readable name to be used e.g. in layer tree
|
||||||
QString name;
|
QString name;
|
||||||
|
//! Identifier of the data source recognized by its providerKey
|
||||||
QString uri;
|
QString uri;
|
||||||
QStringList supportedCrs;
|
QStringList supportedCrs;
|
||||||
QStringList supportedFormats;
|
QStringList supportedFormats;
|
||||||
|
@ -194,6 +194,7 @@ SET(QGIS_GUI_SRCS
|
|||||||
qgsconfigureshortcutsdialog.cpp
|
qgsconfigureshortcutsdialog.cpp
|
||||||
qgscredentialdialog.cpp
|
qgscredentialdialog.cpp
|
||||||
qgscursors.cpp
|
qgscursors.cpp
|
||||||
|
qgscustomdrophandler.cpp
|
||||||
qgsdatadefinedbutton.cpp
|
qgsdatadefinedbutton.cpp
|
||||||
qgsdatumtransformdialog.cpp
|
qgsdatumtransformdialog.cpp
|
||||||
qgsdetaileditemdata.cpp
|
qgsdetaileditemdata.cpp
|
||||||
@ -619,6 +620,7 @@ SET(QGIS_GUI_HDRS
|
|||||||
qgsattributeforminterface.h
|
qgsattributeforminterface.h
|
||||||
qgsattributeformlegacyinterface.h
|
qgsattributeformlegacyinterface.h
|
||||||
qgscursors.h
|
qgscursors.h
|
||||||
|
qgscustomdrophandler.h
|
||||||
qgsdetaileditemdata.h
|
qgsdetaileditemdata.h
|
||||||
qgsexpressionbuilderdialog.h
|
qgsexpressionbuilderdialog.h
|
||||||
qgsfiledropedit.h
|
qgsfiledropedit.h
|
||||||
|
@ -28,6 +28,7 @@ class QWidget;
|
|||||||
class QgsAdvancedDigitizingDockWidget;
|
class QgsAdvancedDigitizingDockWidget;
|
||||||
class QgsAttributeDialog;
|
class QgsAttributeDialog;
|
||||||
class QgsComposerView;
|
class QgsComposerView;
|
||||||
|
class QgsCustomDropHandler;
|
||||||
class QgsFeature;
|
class QgsFeature;
|
||||||
class QgsLayerTreeMapCanvasBridge;
|
class QgsLayerTreeMapCanvasBridge;
|
||||||
class QgsLayerTreeView;
|
class QgsLayerTreeView;
|
||||||
@ -342,6 +343,18 @@ class GUI_EXPORT QgisInterface : public QObject
|
|||||||
*/
|
*/
|
||||||
virtual void unregisterMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory* factory ) = 0;
|
virtual void unregisterMapLayerConfigWidgetFactory( QgsMapLayerConfigWidgetFactory* factory ) = 0;
|
||||||
|
|
||||||
|
/** Register a new custom drop handler.
|
||||||
|
* @note added in QGIS 3.0
|
||||||
|
* @note Ownership of the factory is not transferred, and the factory must
|
||||||
|
* be unregistered when plugin is unloaded.
|
||||||
|
* @see unregisterCustomDropHandler() */
|
||||||
|
virtual void registerCustomDropHandler( QgsCustomDropHandler* handler ) = 0;
|
||||||
|
|
||||||
|
/** Unregister a previously registered custom drop handler.
|
||||||
|
* @note added in QGIS 3.0
|
||||||
|
* @see registerCustomDropHandler() */
|
||||||
|
virtual void unregisterCustomDropHandler( QgsCustomDropHandler* handler ) = 0;
|
||||||
|
|
||||||
// @todo is this deprecated in favour of QgsContextHelp?
|
// @todo is this deprecated in favour of QgsContextHelp?
|
||||||
/** Open a url in the users browser. By default the QGIS doc directory is used
|
/** Open a url in the users browser. By default the QGIS doc directory is used
|
||||||
* as the base for the URL. To open a URL that is not relative to the installed
|
* as the base for the URL. To open a URL that is not relative to the installed
|
||||||
|
20
src/gui/qgscustomdrophandler.cpp
Normal file
20
src/gui/qgscustomdrophandler.cpp
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgscustomdrophandler.cpp
|
||||||
|
---------------------
|
||||||
|
begin : August 2016
|
||||||
|
copyright : (C) 2016 by Martin Dobias
|
||||||
|
email : wonder dot sk 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. *
|
||||||
|
* *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "qgscustomdrophandler.h"
|
||||||
|
|
||||||
|
QgsCustomDropHandler::~QgsCustomDropHandler()
|
||||||
|
{
|
||||||
|
}
|
39
src/gui/qgscustomdrophandler.h
Normal file
39
src/gui/qgscustomdrophandler.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/***************************************************************************
|
||||||
|
qgscustomdrophandler.h
|
||||||
|
---------------------
|
||||||
|
begin : August 2016
|
||||||
|
copyright : (C) 2016 by Martin Dobias
|
||||||
|
email : wonder dot sk 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 QGSCUSTOMDROPHANDLER_H
|
||||||
|
#define QGSCUSTOMDROPHANDLER_H
|
||||||
|
|
||||||
|
#include "qgsmimedatautils.h"
|
||||||
|
|
||||||
|
/** \ingroup gui
|
||||||
|
* Abstract base class that may be implemented to handle new types of data to be dropped in QGIS.
|
||||||
|
* Implementations will be used when a QgsMimeDataUtils::Uri has layerType equal to "custom",
|
||||||
|
* and the providerKey is equal to key() returned by the implementation.
|
||||||
|
* @note added in QGIS 3.0
|
||||||
|
*/
|
||||||
|
class GUI_EXPORT QgsCustomDropHandler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual ~QgsCustomDropHandler();
|
||||||
|
|
||||||
|
//! Type of custom URI recognized by the handler
|
||||||
|
virtual QString key() const = 0;
|
||||||
|
|
||||||
|
//! Method called from QGIS after a drop event with custom URI known by the handler
|
||||||
|
virtual void handleDrop( const QgsMimeDataUtils::Uri& uri ) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // QGSCUSTOMDROPHANDLER_H
|
Loading…
x
Reference in New Issue
Block a user