QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
qgsdockwidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsdockwidget.cpp
3 -----------------
4 begin : June 2016
5 copyright : (C) 2016 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18
19#include "qgsdockwidget.h"
20#include "moc_qgsdockwidget.cpp"
21#include <QAction>
22
23
24QgsDockWidget::QgsDockWidget( QWidget *parent, Qt::WindowFlags flags )
25 : QDockWidget( parent, flags )
26{
27 connect( this, &QDockWidget::visibilityChanged, this, &QgsDockWidget::handleVisibilityChanged );
28}
29
30QgsDockWidget::QgsDockWidget( const QString &title, QWidget *parent, Qt::WindowFlags flags )
31 : QDockWidget( title, parent, flags )
32{
33 connect( this, &QDockWidget::visibilityChanged, this, &QgsDockWidget::handleVisibilityChanged );
34}
35
37{
38 if ( visible )
39 {
40 show();
41 raise();
42 }
43 else
44 {
45 if ( !mVisibleAndActive )
46 return;
47
48 hide();
49 }
50}
51
56
58{
59 return mVisibleAndActive;
60}
61
63{
64 mAction = action;
65 if ( !mAction->isCheckable() )
66 mAction->setCheckable( true );
67 mAction->setChecked( isUserVisible() );
68 connect( mAction, &QAction::toggled, this, [ = ]( bool visible )
69 {
70 setUserVisible( visible );
71 } );
72 connect( this, &QgsDockWidget::visibilityChanged, mAction, [ = ]( bool visible )
73 {
74 mAction->setChecked( visible );
75 } );
76}
77
79{
80 return mAction;
81}
82
83void QgsDockWidget::closeEvent( QCloseEvent *e )
84{
85 emit closed();
86 emit closedStateChanged( true );
87 emit openedStateChanged( false );
88 QDockWidget::closeEvent( e );
89}
90
91void QgsDockWidget::showEvent( QShowEvent *e )
92{
93 emit opened();
94 emit closedStateChanged( false );
95 emit openedStateChanged( true );
96 QDockWidget::showEvent( e );
97}
98
99void QgsDockWidget::handleVisibilityChanged( bool visible )
100{
101 mVisibleAndActive = visible;
102}
103
void closed()
Emitted when dock widget is closed.
QAction * toggleVisibilityAction()
Returns the action linked to the dock.
void closedStateChanged(bool wasClosed)
Emitted when dock widget is closed (or opened).
QgsDockWidget(QWidget *parent=nullptr, Qt::WindowFlags flags=Qt::WindowFlags())
Constructor for QgsDockWidget.
bool isUserVisible() const
Returns true if the dock is both opened and raised to the front (ie not hidden by any other tabs.
void setUserVisible(bool visible)
Sets the dock widget as visible to a user, ie both shown and raised to the front.
void toggleUserVisible()
Toggles whether the dock is user visible.
void closeEvent(QCloseEvent *) override
void opened()
Emitted when dock widget is opened.
void showEvent(QShowEvent *event) override
void setToggleVisibilityAction(QAction *action)
Links an action to the dock, so that toggling the action will automatically set the dock's visibility...
void openedStateChanged(bool wasOpened)
Emitted when dock widget is opened (or closed).