QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 <QDialogButtonBox>
16#include <QPushButton>
17#include <QDialog>
18#include <QVBoxLayout>
19
20#include "qgssettings.h"
21#include "qgspanelwidget.h"
22#include "qgslogger.h"
23
25 : QWidget( parent )
26{
27}
28
29void QgsPanelWidget::connectChildPanels( const QList<QgsPanelWidget *> &panels )
30{
31 const auto constPanels = panels;
32 for ( QgsPanelWidget *widget : constPanels )
33 {
34 connectChildPanel( widget );
35 }
36}
37
39{
42}
43
44void QgsPanelWidget::setDockMode( bool dockMode )
45{
46 mDockMode = dockMode;
47}
48
50{
51 return false;
52}
53
55{
56 QWidget *p = widget;
57 while ( p )
58 {
59 if ( QgsPanelWidget *panel = qobject_cast< QgsPanelWidget * >( p ) )
60 return panel;
61
62 if ( p->window() == p )
63 {
64 // break on encountering a window - e.g., a dialog opened from a panel should not inline
65 // widgets inside the parent panel
66 return nullptr;
67 }
68
69 p = p->parentWidget();
70 }
71 return nullptr;
72}
73
75{
76 return QString();
77}
78
80{
81 return nullptr;
82}
83
85{
86 //panel dock mode inherits from this panel
87 panel->setDockMode( dockMode() );
88
89 if ( mDockMode )
90 {
91 emit showPanel( panel );
92 }
93 else
94 {
95 // Show the dialog version if no one is connected
96 QDialog *dlg = new QDialog();
97 const QString key = QStringLiteral( "/UI/paneldialog/%1" ).arg( panel->panelTitle() );
98 QgsSettings settings;
99 dlg->restoreGeometry( settings.value( key ).toByteArray() );
100 dlg->setWindowTitle( panel->panelTitle() );
101 dlg->setLayout( new QVBoxLayout() );
102 dlg->layout()->addWidget( panel );
103 QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok );
104 connect( buttonBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept );
105 dlg->layout()->addWidget( buttonBox );
106 dlg->exec();
107 settings.setValue( key, dlg->saveGeometry() );
108 panel->acceptPanel();
109 }
110}
111
113{
114 emit panelAccepted( this );
115}
116
117void QgsPanelWidget::keyPressEvent( QKeyEvent *event )
118{
119 if ( event->key() == Qt::Key_Escape )
120 {
121 acceptPanel();
122 }
123 else
124 {
125 QWidget::keyPressEvent( event );
126 }
127}
128
129QgsPanelWidgetWrapper::QgsPanelWidgetWrapper( QWidget *widget, QWidget *parent )
130 : QgsPanelWidget( parent )
131 , mWidget( widget )
132{
133 this->setLayout( new QVBoxLayout() );
134 this->layout()->setContentsMargins( 0, 0, 0, 0 );
135 this->layout()->addWidget( widget );
136}
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,...
Base class for any widget that can be shown as a inline 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.
QString panelTitle()
The title of the panel.
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 a 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.
bool dockMode()
Returns the dock mode state.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:62
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.