QGIS API Documentation 3.41.0-Master (cea29feecf2)
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 setUserVisible( visible );
70 } );
71 connect( this, &QgsDockWidget::visibilityChanged, mAction, [=]( bool visible ) {
72 mAction->setChecked( visible );
73 } );
74}
75
77{
78 return mAction;
79}
80
81void QgsDockWidget::closeEvent( QCloseEvent *e )
82{
83 emit closed();
84 emit closedStateChanged( true );
85 emit openedStateChanged( false );
86 QDockWidget::closeEvent( e );
87}
88
89void QgsDockWidget::showEvent( QShowEvent *e )
90{
91 emit opened();
92 emit closedStateChanged( false );
93 emit openedStateChanged( true );
94 QDockWidget::showEvent( e );
95}
96
97void QgsDockWidget::handleVisibilityChanged( bool visible )
98{
99 mVisibleAndActive = visible;
100}
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).