QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 <QVBoxLayout>
24
25#include "moc_qgspanelwidget.cpp"
26
28 : QWidget( parent )
29{
30}
31
32void QgsPanelWidget::connectChildPanels( const QList<QgsPanelWidget *> &panels )
33{
34 const auto constPanels = panels;
35 for ( QgsPanelWidget *widget : constPanels )
36 {
37 connectChildPanel( widget );
38 }
39}
40
46
48{
49 mDockMode = dockMode;
50}
51
53{
54 return false;
55}
56
58{
59 QWidget *p = widget;
60 while ( p )
61 {
62 if ( QgsPanelWidget *panel = qobject_cast<QgsPanelWidget *>( p ) )
63 return panel;
64
65 if ( p->window() == p )
66 {
67 // break on encountering a window - e.g., a dialog opened from a panel should not inline
68 // widgets inside the parent panel
69 return nullptr;
70 }
71
72 p = p->parentWidget();
73 }
74 return nullptr;
75}
76
78{
79 return QString();
80}
81
83{
84 return nullptr;
85}
86
88{
89 //panel dock mode inherits from this panel
90 panel->setDockMode( dockMode() );
91
92 if ( mDockMode )
93 {
94 emit showPanel( panel );
95 }
96 else
97 {
98 // Show the dialog version if no one is connected
99 QDialog *dlg = new QDialog();
100 const QString key = QStringLiteral( "/UI/paneldialog/%1" ).arg( panel->panelTitle() );
101 QgsSettings settings;
102 dlg->restoreGeometry( settings.value( key ).toByteArray() );
103 dlg->setWindowTitle( panel->panelTitle() );
104 dlg->setLayout( new QVBoxLayout() );
105 dlg->layout()->addWidget( panel );
106 QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok );
107 connect( buttonBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept );
108 dlg->layout()->addWidget( buttonBox );
109 dlg->exec();
110 settings.setValue( key, dlg->saveGeometry() );
111 panel->acceptPanel();
112 }
113}
114
116{
117 emit panelAccepted( this );
118}
119
120void QgsPanelWidget::keyPressEvent( QKeyEvent *event )
121{
122 if ( event->key() == Qt::Key_Escape )
123 {
124 acceptPanel();
125 }
126 else
127 {
128 QWidget::keyPressEvent( event );
129 }
130}
131
133 : QgsPanelWidget( parent )
134 , mWidget( widget )
135{
136 this->setLayout( new QVBoxLayout() );
137 this->layout()->setContentsMargins( 0, 0, 0, 0 );
138 this->layout()->addWidget( widget );
139}
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 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 widgetChanged()
Emitted when the widget state changes.
void acceptPanel()
Accept the panel.
void keyPressEvent(QKeyEvent *event) override
Overridden key press event to handle the esc event on the widget.
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:65
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.