QGIS API Documentation 4.3.0-Master (0cfde48c85b)
Loading...
Searching...
No Matches
qgspanelwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgspanelwidget.cpp
3 ---------------------
4 begin : June 2016
5 copyright : (C) 2016 by Nathan Woodrow
6 email :
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#include "qgspanelwidget.h"
16
17#include "qgslogger.h"
18#include "qgssettings.h"
19
20#include <QDialog>
21#include <QDialogButtonBox>
22#include <QPushButton>
23#include <QString>
24#include <QVBoxLayout>
25
26#include "moc_qgspanelwidget.cpp"
27
28using namespace Qt::StringLiterals;
29
31 : QWidget( parent )
32{
33 // Forward the changed signal to the deprecated one, for backwards compatibility.
34 // TODO QGIS 5.0 remove
36 connect( this, &QgsPanelWidget::changed, this, [this] {
37 if ( mForwardChangedSignal )
38 {
39 return;
40 }
41 mForwardChangedSignal = true;
42 emit widgetChanged();
43 mForwardChangedSignal = false;
44 } );
45
46 // Forward the deprecated signal to the new one for subclasses which still use the deprecated one
47 connect( this, &QgsPanelWidget::widgetChanged, this, [this] {
48 if ( mForwardChangedSignal )
49 {
50 return;
51 }
52 mForwardChangedSignal = true;
53 emit changed();
54 mForwardChangedSignal = false;
55 } );
57}
58
59void QgsPanelWidget::connectChildPanels( const QList<QgsPanelWidget *> &panels )
60{
61 const auto constPanels = panels;
62 for ( QgsPanelWidget *widget : constPanels )
63 {
64 connectChildPanel( widget );
65 }
66}
67
73
75{
76 mDockMode = dockMode;
77}
78
80{
81 return false;
82}
83
85{
86 QWidget *p = widget;
87 while ( p )
88 {
89 if ( QgsPanelWidget *panel = qobject_cast<QgsPanelWidget *>( p ) )
90 return panel;
91
92 if ( p->window() == p )
93 {
94 // break on encountering a window - e.g., a dialog opened from a panel should not inline
95 // widgets inside the parent panel
96 return nullptr;
97 }
98
99 p = p->parentWidget();
100 }
101 return nullptr;
102}
103
105{
106 return QString();
107}
108
110{
111 return nullptr;
112}
113
115{
116 //panel dock mode inherits from this panel
117 panel->setDockMode( dockMode() );
118
119 if ( mDockMode )
120 {
121 emit showPanel( panel );
122 }
123 else
124 {
125 // Show the dialog version if no one is connected
126 QDialog *dlg = new QDialog();
127 const QString key = u"/UI/paneldialog/%1"_s.arg( panel->panelTitle() );
128 QgsSettings settings;
129 dlg->restoreGeometry( settings.value( key ).toByteArray() );
130 dlg->setWindowTitle( panel->panelTitle() );
131 dlg->setLayout( new QVBoxLayout() );
132 dlg->layout()->addWidget( panel );
133 QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok );
134 connect( buttonBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept );
135 dlg->layout()->addWidget( buttonBox );
136 dlg->exec();
137 settings.setValue( key, dlg->saveGeometry() );
138 panel->acceptPanel();
139 }
140}
141
143{
144 emit panelAccepted( this );
145}
146
147void QgsPanelWidget::keyPressEvent( QKeyEvent *event )
148{
149 if ( event->key() == Qt::Key_Escape )
150 {
151 acceptPanel();
152 }
153 else
154 {
155 QWidget::keyPressEvent( event );
156 }
157}
158
160 : QgsPanelWidget( parent )
161 , mWidget( widget )
162{
163 this->setLayout( new QVBoxLayout() );
164 this->layout()->setContentsMargins( 0, 0, 0, 0 );
165 this->layout()->addWidget( widget );
166}
QWidget * widget()
Returns the internal widget that is wrapped in this panel.
QgsPanelWidgetWrapper(QWidget *widget, QWidget *parent=nullptr)
Wrapper widget for existing widgets which can't have the inheritance tree changed,...
QString panelTitle() const
The title of the panel.
void connectChildPanels(const QList< QgsPanelWidget * > &panels)
Connect the given sub panel widgets showPanel signals to this current panels main showPanel event to ...
void showPanel(QgsPanelWidget *panel)
Emit when you require a panel to be show in the interface.
void openPanel(QgsPanelWidget *panel)
Open a panel or dialog depending on dock mode setting If dock mode is true this method will emit the ...
virtual QMenu * menuButtonMenu()
Returns the menu to use for the menu button for this panel, or nullptr if no menu button is required.
bool dockMode() const
Returns the dock mode state.
void changed()
Emitted when the widget state changes.
void panelAccepted(QgsPanelWidget *panel)
Emitted when the panel is accepted by the user.
virtual bool applySizeConstraintsToStack() const
Returns true if the size constraints and hints for the panel widget should be applied to the parent Q...
virtual QString menuButtonTooltip() const
Returns the (translated) tooltip text to use for the menu button for this panel.
void connectChildPanel(QgsPanelWidget *panel)
Connect the given sub panel widgets showPanel signals to this current panels main showPanel event to ...
QgsPanelWidget(QWidget *parent=nullptr)
Base class for any widget that can be shown as an inline panel.
void acceptPanel()
Accept the panel.
void keyPressEvent(QKeyEvent *event) override
Overridden key press event to handle the esc event on the widget.
Q_DECL_DEPRECATED void widgetChanged()
Emitted when the widget state changes.
static QgsPanelWidget * findParentPanel(QWidget *widget)
Traces through the parents of a widget to find if it is contained within a QgsPanelWidget widget.
virtual void setDockMode(bool dockMode)
Set the widget in dock mode which tells the widget to emit panel widgets and not open dialogs.
Stores settings for use within QGIS.
Definition qgssettings.h:68
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:8361
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:8360