QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsdataitemguiprovider.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdataitemguiprovider.h
3 --------------------------------------
4 Date : October 2018
5 Copyright : (C) 2018 by Nyall Dawson
6 Email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSDATAITEMGUIPROVIDER_H
17#define QGSDATAITEMGUIPROVIDER_H
18
19#include "qgis.h"
20#include "qgis_gui.h"
21#include "qgis_sip.h"
22
23#include <QList>
24#include <QMenu>
25#include <QMimeData>
26#include <QString>
27#include <QWidget>
28
29class QgsDataItem;
30class QgsMessageBar;
31class QgsLayerItem;
33class QgsMapCanvas;
34
43class GUI_EXPORT QgsDataItemGuiContext
44{
45 public:
47
56
64 void setMessageBar( QgsMessageBar *bar );
65
74 void setMapCanvas( QgsMapCanvas *canvas );
75
82 QgsMapCanvas *mapCanvas() const;
83
90 QgsBrowserTreeView *view() const;
91
99
100 private:
101 QgsMessageBar *mMessageBar = nullptr;
102
103 QgsBrowserTreeView *mView = nullptr;
104
105 QgsMapCanvas *mCanvas = nullptr;
106};
107
109
122{
123 public:
124 virtual ~QgsDataItemGuiProvider() = default;
125
129 virtual QString name() = 0;
130
155 virtual void populateContextMenu( QgsDataItem *item, QMenu *menu, const QList<QgsDataItem *> &selectedItems, QgsDataItemGuiContext context );
156
168 virtual int precedenceWhenPopulatingMenus() const;
169
179 virtual bool rename( QgsDataItem *item, const QString &name, QgsDataItemGuiContext context );
180
191 virtual bool deleteLayer( QgsLayerItem *item, QgsDataItemGuiContext context );
192
198 virtual bool handleDoubleClick( QgsDataItem *item, QgsDataItemGuiContext context );
199
205 virtual bool acceptDrop( QgsDataItem *item, QgsDataItemGuiContext context );
206
213 virtual bool handleDrop( QgsDataItem *item, QgsDataItemGuiContext context, const QMimeData *data, Qt::DropAction action );
214
224 virtual QWidget *createParamWidget( QgsDataItem *item, QgsDataItemGuiContext context ) SIP_FACTORY;
225
237 static void notify( const QString &title, const QString &message, QgsDataItemGuiContext context, Qgis::MessageLevel level = Qgis::MessageLevel::Info, int duration = -1, QWidget *parent = nullptr );
238};
239
240#endif // QGSDATAITEMGUIPROVIDER_H
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:156
@ Info
Information message.
Definition qgis.h:157
Extends QTreeView with save/restore tree state and other browser-specific functionality.
Encapsulates the context in which a QgsDataItem is shown within the application GUI.
void setView(QgsBrowserTreeView *view)
Sets the associated view.
QgsMessageBar * messageBar() const
Returns the associated message bar.
QgsDataItemGuiContext()=default
QgsBrowserTreeView * view() const
Returns the associated view.
void setMapCanvas(QgsMapCanvas *canvas)
Sets the map canvas associated with the data item.
void setMessageBar(QgsMessageBar *bar)
Sets the associated message bar.
QgsMapCanvas * mapCanvas() const
Returns the map canvas associated with the item.
Abstract base class for providers which affect how QgsDataItem items behave within the application GU...
virtual void populateContextMenu(QgsDataItem *item, QMenu *menu, const QList< QgsDataItem * > &selectedItems, QgsDataItemGuiContext context)
Called when the given context menu is being populated for the given item, allowing the provider to ad...
virtual bool handleDrop(QgsDataItem *item, QgsDataItemGuiContext context, const QMimeData *data, Qt::DropAction action)
Called when a user drops on an item.
virtual ~QgsDataItemGuiProvider()=default
static void notify(const QString &title, const QString &message, QgsDataItemGuiContext context, Qgis::MessageLevel level=Qgis::MessageLevel::Info, int duration=-1, QWidget *parent=nullptr)
Notify the user showing a message with title and level If the context has a message bar the message w...
virtual int precedenceWhenPopulatingMenus() const
Returns the provider's precedence to use when populating context menus via calls to populateContextMe...
virtual bool acceptDrop(QgsDataItem *item, QgsDataItemGuiContext context)
Providers should return true if the drops are allowed (handleDrop() should be implemented in that cas...
virtual QString name()=0
Returns the provider's name.
virtual bool handleDoubleClick(QgsDataItem *item, QgsDataItemGuiContext context)
Called when a user double clicks on an item.
virtual QWidget * createParamWidget(QgsDataItem *item, QgsDataItemGuiContext context)
Creates source widget from data item for QgsBrowserPropertiesWidget By default it returns nullptr.
virtual bool rename(QgsDataItem *item, const QString &name, QgsDataItemGuiContext context)
Sets a new name for the item, and returns true if the item was successfully renamed.
virtual bool deleteLayer(QgsLayerItem *item, QgsDataItemGuiContext context)
Tries to permanently delete map layer representing the given item.
Base class for all items in the model.
Definition qgsdataitem.h:47
A browser item that represents a layer that can be opened with one of the providers.
Map canvas is a class for displaying all GIS data types on a canvas.
A bar for displaying non-blocking messages to the user.
#define SIP_FACTORY
Definition qgis_sip.h:84
Q_DECLARE_METATYPE(QgsDataItemGuiContext)