QGIS API Documentation 3.99.0-Master (d270888f95f)
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}
34
35void QgsPanelWidget::connectChildPanels( const QList<QgsPanelWidget *> &panels )
36{
37 const auto constPanels = panels;
38 for ( QgsPanelWidget *widget : constPanels )
39 {
40 connectChildPanel( widget );
41 }
42}
43
49
51{
52 mDockMode = dockMode;
53}
54
56{
57 return false;
58}
59
61{
62 QWidget *p = widget;
63 while ( p )
64 {
65 if ( QgsPanelWidget *panel = qobject_cast<QgsPanelWidget *>( p ) )
66 return panel;
67
68 if ( p->window() == p )
69 {
70 // break on encountering a window - e.g., a dialog opened from a panel should not inline
71 // widgets inside the parent panel
72 return nullptr;
73 }
74
75 p = p->parentWidget();
76 }
77 return nullptr;
78}
79
81{
82 return QString();
83}
84
86{
87 return nullptr;
88}
89
91{
92 //panel dock mode inherits from this panel
93 panel->setDockMode( dockMode() );
94
95 if ( mDockMode )
96 {
97 emit showPanel( panel );
98 }
99 else
100 {
101 // Show the dialog version if no one is connected
102 QDialog *dlg = new QDialog();
103 const QString key = u"/UI/paneldialog/%1"_s.arg( panel->panelTitle() );
104 QgsSettings settings;
105 dlg->restoreGeometry( settings.value( key ).toByteArray() );
106 dlg->setWindowTitle( panel->panelTitle() );
107 dlg->setLayout( new QVBoxLayout() );
108 dlg->layout()->addWidget( panel );
109 QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok );
110 connect( buttonBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept );
111 dlg->layout()->addWidget( buttonBox );
112 dlg->exec();
113 settings.setValue( key, dlg->saveGeometry() );
114 panel->acceptPanel();
115 }
116}
117
119{
120 emit panelAccepted( this );
121}
122
123void QgsPanelWidget::keyPressEvent( QKeyEvent *event )
124{
125 if ( event->key() == Qt::Key_Escape )
126 {
127 acceptPanel();
128 }
129 else
130 {
131 QWidget::keyPressEvent( event );
132 }
133}
134
136 : QgsPanelWidget( parent )
137 , mWidget( widget )
138{
139 this->setLayout( new QVBoxLayout() );
140 this->layout()->setContentsMargins( 0, 0, 0, 0 );
141 this->layout()->addWidget( widget );
142}
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: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.