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