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