QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
16 #include "qgsdataitemguiprovider.h"
17 #include "qgsdataitem.h"
18 #include "qgsproviderregistry.h"
19 #include "qgsprovidermetadata.h"
21 #include "qgsmessagebar.h"
22 #include <QMessageBox>
23 //
24 // QgsDataItemGuiContext
25 //
26 
28 {
29  return mMessageBar;
30 }
31 
33 {
34  mMessageBar = messageBar;
35 }
36 
37 //
38 // QgsDataItemGuiProvider
39 //
40 
41 void QgsDataItemGuiProvider::populateContextMenu( QgsDataItem *, QMenu *, const QList<QgsDataItem *> &, QgsDataItemGuiContext )
42 {
43 
44 }
45 
47 {
48  return false;
49 }
50 
52 {
53  return false;
54 }
55 
57 {
58  return false;
59 }
60 
62 {
63  return false;
64 }
65 
66 bool QgsDataItemGuiProvider::handleDrop( QgsDataItem *, QgsDataItemGuiContext, const QMimeData *, Qt::DropAction )
67 {
68  return false;
69 }
70 
72 {
73  return nullptr;
74 }
75 
76 void QgsDataItemGuiProvider::notify( const QString &title, const QString &message, QgsDataItemGuiContext context, Qgis::MessageLevel level )
77 {
78  switch ( level )
79  {
80  case Qgis::MessageLevel::Info:
81  case Qgis::MessageLevel::None:
82  {
83  if ( auto *lMessageBar = context.messageBar() )
84  {
85  lMessageBar->pushInfo( title, message );
86  }
87  else
88  {
89  QMessageBox::information( nullptr, title, message );
90  }
91  break;
92  }
93  case Qgis::MessageLevel::Warning:
94  {
95  if ( auto *lMessageBar = context.messageBar() )
96  {
97  lMessageBar->pushWarning( title, message );
98  }
99  else
100  {
101  QMessageBox::warning( nullptr, title, message );
102  }
103  break;
104  }
105  case Qgis::MessageLevel::Critical:
106  {
107  if ( auto *lMessageBar = context.messageBar() )
108  {
109  lMessageBar->pushCritical( title, message );
110  }
111  else
112  {
113  QMessageBox::critical( nullptr, title, message );
114  }
115  break;
116  }
117  case Qgis::MessageLevel::Success:
118  {
119  if ( auto *lMessageBar = context.messageBar() )
120  {
121  lMessageBar->pushSuccess( title, message );
122  }
123  else
124  {
125  // There is no "success" in message box, let's use information instead
126  QMessageBox::information( nullptr, title, message );
127  }
128  break;
129  }
130  }
131 }
QgsDataItemGuiContext::messageBar
QgsMessageBar * messageBar() const
Returns the associated message bar.
Definition: qgsdataitemguiprovider.cpp:27
QgsDataItemGuiProvider::notify
static void notify(const QString &title, const QString &message, QgsDataItemGuiContext context, Qgis::MessageLevel level=Qgis::Info)
Notify the user showing a message with title and level If the context has a message bar the message w...
Definition: qgsdataitemguiprovider.cpp:76
qgsdataitemguiprovider.h
qgsdataitem.h
QgsDataItemGuiProvider::rename
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.
Definition: qgsdataitemguiprovider.cpp:46
QgsDataItemGuiProvider::handleDrop
virtual bool handleDrop(QgsDataItem *item, QgsDataItemGuiContext context, const QMimeData *data, Qt::DropAction action)
Called when a user drops on an item.
Definition: qgsdataitemguiprovider.cpp:66
QgsDataItemGuiProvider::handleDoubleClick
virtual bool handleDoubleClick(QgsDataItem *item, QgsDataItemGuiContext context)
Called when a user double clicks on an item.
Definition: qgsdataitemguiprovider.cpp:56
qgsprovidermetadata.h
qgsproviderregistry.h
QgsDataItemGuiProvider::createParamWidget
virtual QWidget * createParamWidget(QgsDataItem *item, QgsDataItemGuiContext context)
Creates source widget from data item for QgsBrowserPropertiesWidget By default it returns nullptr.
Definition: qgsdataitemguiprovider.cpp:71
QgsMessageBar
A bar for displaying non-blocking messages to the user.
Definition: qgsmessagebar.h:61
qgsmessagebar.h
QgsDataItemGuiContext
Encapsulates the context in which a QgsDataItem is shown within the application GUI.
Definition: qgsdataitemguiprovider.h:41
QgsDataItemGuiContext::setMessageBar
void setMessageBar(QgsMessageBar *bar)
Sets the associated message bar.
Definition: qgsdataitemguiprovider.cpp:32
Qgis::MessageLevel
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition: qgis.h:89
QgsDataItemGuiProvider::acceptDrop
virtual bool acceptDrop(QgsDataItem *item, QgsDataItemGuiContext context)
Providers should return true if the drops are allowed (handleDrop() should be implemented in that cas...
Definition: qgsdataitemguiprovider.cpp:61
QgsLayerItem
Item that represents a layer that can be opened with one of the providers.
Definition: qgsdataitem.h:507
QgsDataItemGuiProvider::populateContextMenu
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...
Definition: qgsdataitemguiprovider.cpp:41
QgsDataItem
Base class for all items in the model.
Definition: qgsdataitem.h:51
qgsabstractdatabaseproviderconnection.h
QgsDataItemGuiProvider::deleteLayer
virtual bool deleteLayer(QgsLayerItem *item, QgsDataItemGuiContext context)
Tries to permanently delete map layer representing the given item.
Definition: qgsdataitemguiprovider.cpp:51