QGIS API Documentation 3.99.0-Master (2fe06baccd8)
Loading...
Searching...
No Matches
qgsdataitemguiprovider.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdataitemguiprovider.cpp
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
17
19#include "qgsdataitem.h"
20#include "qgsmessagebar.h"
21#include "qgsprovidermetadata.h"
22#include "qgsproviderregistry.h"
23
24#include <QMessageBox>
25
26//
27// QgsDataItemGuiContext
28//
29
31{
32 return mMessageBar;
33}
34
39
41{
42 mCanvas = canvas;
43}
44
46{
47 return mCanvas;
48}
49
51{
52 return mView;
53}
54
59
60//
61// QgsDataItemGuiProvider
62//
63
64void QgsDataItemGuiProvider::populateContextMenu( QgsDataItem *, QMenu *, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
65{
66}
67
72
74{
75 return false;
76}
77
82
87
92
93bool QgsDataItemGuiProvider::handleDrop( QgsDataItem *, QgsDataItemGuiContext, const QMimeData *, Qt::DropAction )
94{
95 return false;
96}
97
102
103void QgsDataItemGuiProvider::notify( const QString &title, const QString &message, QgsDataItemGuiContext context, Qgis::MessageLevel level, int duration, QWidget *parent )
104{
105 if ( QgsMessageBar *bar = context.messageBar() )
106 {
107 bar->pushMessage( title, message, level, duration );
108 }
109 else
110 {
111 switch ( level )
112 {
115 {
116 QMessageBox::information( parent, title, message );
117 break;
118 }
120 {
121 QMessageBox::warning( parent, title, message );
122 break;
123 }
125 {
126 QMessageBox::critical( parent, title, message );
127 break;
128 }
130 {
131 // There is no "success" in message box, let's use information instead
132 QMessageBox::information( parent, title, message );
133 break;
134 }
135 }
136 }
137}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:156
@ NoLevel
No level.
Definition qgis.h:161
@ Warning
Warning message.
Definition qgis.h:158
@ Critical
Critical/error message.
Definition qgis.h:159
@ Info
Information message.
Definition qgis.h:157
@ Success
Used for reporting a successful operation.
Definition qgis.h:160
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.
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.
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.
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 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.