-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix style dock button not synced to dock state (fix #14862)
Add a new class QgsDockWidget which has finer control over setting and retrieving the dock visibility, to account for dock widgets which are open but hidden by other docks
- Loading branch information
1 parent
a033e81
commit cb4dacf
Showing
9 changed files
with
402 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** \ingroup gui | ||
* \class QgsDockWidget | ||
* QDockWidget subclass with more fine-grained control over how the widget is closed or opened. | ||
* \note added in 2.16 | ||
*/ | ||
|
||
class QgsDockWidget : QDockWidget | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsdockwidget.h> | ||
%End | ||
|
||
public: | ||
|
||
/** Constructor for QgsDockWidget. | ||
* @param parent parent widget | ||
*/ | ||
explicit QgsDockWidget( QWidget* parent /TransferThis/ = nullptr ); | ||
|
||
public slots: | ||
|
||
/** Sets the dock widget as visible to a user, ie both shown and raised to the front. | ||
* @param visible set to true to show the dock to the user, or false to hide the dock. | ||
* When setting a dock as user visible, the dock will be opened (if it is not already | ||
* opened) and raised to the front. | ||
* When setting as hidden, the following logic is used: | ||
* - hiding a dock which is open but not raised (ie hidden by another tab) will have no | ||
* effect, and the dock will still be opened and hidden by the other tab | ||
* - hiding a dock which is open and raised (ie, user visible) will cause the dock to | ||
* be closed | ||
* - hiding a dock which is closed has no effect and raises no signals | ||
* @see isUserVisible() | ||
*/ | ||
void setUserVisible( bool visible ); | ||
|
||
/** Returns true if the dock is both opened and raised to the front (ie not hidden by | ||
* any other tabs. | ||
* @see setUserVisible() | ||
*/ | ||
bool isUserVisible() const; | ||
|
||
protected: | ||
|
||
virtual void closeEvent( QCloseEvent * ); | ||
virtual void showEvent( QShowEvent* event ); | ||
|
||
signals: | ||
|
||
/** Emitted when dock widget is closed (or opened). | ||
* @param wasClosed will be true if dock widget was closed, or false if dock widget was opened | ||
* @see opened() | ||
*/ | ||
void closed( bool wasClosed ); | ||
|
||
/** Emitted when dock widget is opened (or closed). | ||
* @param wasOpened will be true if dock widget was opened, or false if dock widget was closed | ||
* @see closed() | ||
*/ | ||
void opened( bool wasOpened ); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/*************************************************************************** | ||
qgsdockwidget.cpp | ||
----------------- | ||
begin : June 2016 | ||
copyright : (C) 2016 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
|
||
#include "qgsdockwidget.h" | ||
|
||
|
||
QgsDockWidget::QgsDockWidget( QWidget* parent ) | ||
: QDockWidget( parent ) | ||
, mVisibleAndActive( false ) | ||
{ | ||
connect( this, SIGNAL( visibilityChanged( bool ) ), this, SLOT( handleVisibilityChanged( bool ) ) ); | ||
} | ||
|
||
void QgsDockWidget::setUserVisible( bool visible ) | ||
{ | ||
if ( visible ) | ||
{ | ||
if ( mVisibleAndActive ) | ||
return; | ||
|
||
show(); | ||
raise(); | ||
} | ||
else | ||
{ | ||
if ( !mVisibleAndActive ) | ||
return; | ||
|
||
hide(); | ||
} | ||
} | ||
|
||
bool QgsDockWidget::isUserVisible() const | ||
{ | ||
return mVisibleAndActive; | ||
} | ||
|
||
void QgsDockWidget::closeEvent( QCloseEvent* e ) | ||
{ | ||
emit closed( true ); | ||
emit opened( false ); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
QDockWidget::closeEvent( e ); | ||
} | ||
|
||
void QgsDockWidget::showEvent( QShowEvent* e ) | ||
{ | ||
emit closed( false ); | ||
emit opened( true ); | ||
QDockWidget::showEvent( e ); | ||
} | ||
|
||
void QgsDockWidget::handleVisibilityChanged( bool visible ) | ||
{ | ||
mVisibleAndActive = visible; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/*************************************************************************** | ||
qgsdockwidget.h | ||
--------------- | ||
begin : June 2016 | ||
copyright : (C) 2016 by Nyall Dawson | ||
email : nyall dot dawson at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include <QDockWidget> | ||
|
||
/** \ingroup gui | ||
* \class QgsDockWidget | ||
* QDockWidget subclass with more fine-grained control over how the widget is closed or opened. | ||
* \note added in 2.16 | ||
*/ | ||
|
||
class GUI_EXPORT QgsDockWidget : public QDockWidget | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
/** Constructor for QgsDockWidget. | ||
* @param parent parent widget | ||
*/ | ||
explicit QgsDockWidget( QWidget* parent = nullptr ); | ||
|
||
public slots: | ||
|
||
/** Sets the dock widget as visible to a user, ie both shown and raised to the front. | ||
* @param visible set to true to show the dock to the user, or false to hide the dock. | ||
* When setting a dock as user visible, the dock will be opened (if it is not already | ||
* opened) and raised to the front. | ||
* When setting as hidden, the following logic is used: | ||
* - hiding a dock which is open but not raised (ie hidden by another tab) will have no | ||
* effect, and the dock will still be opened and hidden by the other tab | ||
* - hiding a dock which is open and raised (ie, user visible) will cause the dock to | ||
* be closed | ||
* - hiding a dock which is closed has no effect and raises no signals | ||
* @see isUserVisible() | ||
*/ | ||
void setUserVisible( bool visible ); | ||
|
||
/** Returns true if the dock is both opened and raised to the front (ie not hidden by | ||
* any other tabs. | ||
* @see setUserVisible() | ||
*/ | ||
bool isUserVisible() const; | ||
|
||
protected: | ||
|
||
virtual void closeEvent( QCloseEvent * ) override; | ||
virtual void showEvent( QShowEvent* event ) override; | ||
|
||
signals: | ||
|
||
/** Emitted when dock widget is closed (or opened). | ||
* @param wasClosed will be true if dock widget was closed, or false if dock widget was opened | ||
* @see opened() | ||
*/ | ||
void closed( bool wasClosed ); | ||
|
||
/** Emitted when dock widget is opened (or closed). | ||
* @param wasOpened will be true if dock widget was opened, or false if dock widget was closed | ||
* @see closed() | ||
*/ | ||
void opened( bool wasOpened ); | ||
|
||
private slots: | ||
|
||
void handleVisibilityChanged( bool visible ); | ||
|
||
private: | ||
|
||
bool mVisibleAndActive; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
2 comments
on commit cb4dacf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
It'd be good to seize of the opportunity to refactor the layer panel's toolbar buttons (I'm mostly thinking of the "filter legend by map content" and "filter legend by expression" buttons). Merging those two would make space for the style dock button to be moved there instead of floating to the right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. That is a good fix.
What do you think about just emitting
closed()
here andopened()
below?That would make it easier to react without custom logic like
We can still introduce a signal
openStateChanged( bool open )
.