qtquick: Move dummy QAction class into the pimpl header

No need for it to be in the public header
This commit is contained in:
Sergio Martins
2021-02-06 18:20:44 +00:00
parent 863691c313
commit 44bf1ef322
3 changed files with 131 additions and 113 deletions

View File

@@ -784,6 +784,51 @@ void DockWidgetBase::Private::forceClose()
close();
}
DockWidgetBase::Private::Private(const QString &dockName, DockWidgetBase::Options options_,
LayoutSaverOptions layoutSaverOptions_, DockWidgetBase *qq)
: name(dockName)
, title(dockName)
, q(qq)
, options(options_)
, layoutSaverOptions(layoutSaverOptions_)
, toggleAction(new QAction(q))
, floatAction(new QAction(q))
{
q->connect(toggleAction, &QAction::toggled, q, [this](bool enabled) {
if (!m_updatingToggleAction) { // guard against recursiveness
toggleAction->blockSignals(true); // and don't emit spurious toggle. Like when a dock
// widget is inserted into a tab widget it might get
// hide events, ignore those. The Dock Widget is open.
m_processingToggleAction = true;
toggle(enabled);
toggleAction->blockSignals(false);
m_processingToggleAction = false;
}
});
q->connect(floatAction, &QAction::toggled, q, [this](bool checked) {
if (!m_updatingFloatAction) { // guard against recursiveness
q->setFloating(checked);
}
Q_EMIT q->isFloatingChanged(checked);
// When floating, we remove from the sidebar
if (checked && q->isOpen()) {
if (SideBar *sb = DockRegistry::self()->sideBarForDockWidget(q)) {
sb->mainWindow()->clearSideBarOverlay(/* deleteFrame=*/false);
sb->removeDockWidget(q);
}
}
});
toggleAction->setCheckable(true);
floatAction->setCheckable(true);
qApp->installEventFilter(this);
}
void DockWidgetBase::Private::addPlaceholderItem(Layouting::Item *item)
{
Q_ASSERT(item);

View File

@@ -29,10 +29,6 @@
// clazy:excludeall=ctor-missing-parent-argument
QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE
class TestDocks;
namespace KDDockWidgets {
@@ -498,73 +494,4 @@ private:
}
Q_DECLARE_METATYPE(KDDockWidgets::Location)
#if defined(QT_WIDGETS_LIB)
# include <QAction>
#else
// A QAction for QtQuick. Just so it compiles, for now
class QAction : public QObject
{
Q_OBJECT
public:
using QObject::QObject;
bool isChecked() const {
return m_isChecked ;
}
void setCheckable(bool is) {
m_isCheckable = is;
}
void setText(const QString &text) {
m_text = text;
}
void setToolTip(const QString &text) {
m_toolTip = text;
}
QString toolTip() const {
returm m_toolTip;
}
bool enabled() const {
return m_enabled;
}
void setEnabled(bool enabled) {
m_enabled = enabled;
}
bool checked() const {
return m_checked;
}
void setChecked(bool checked) {
m_checked = checked;
}
bool isEnabled() const {
return m_enabled;
}
void toggle() {
m_enabled = !m_enabled;
Q_EMIT toggled(m_enabled);
}
Q_SIGNALS:
bool toggled(bool);
private:
QString m_text;
QString m_toolTip;
bool m_isChecked = false;
bool m_isCheckable = false;
bool m_enabled = false;
bool m_checked = false;
};
#endif
#endif

View File

@@ -22,52 +22,17 @@
#include <QString>
#include <QSize>
QT_BEGIN_NAMESPACE
class QAction;
QT_END_NAMESPACE
namespace KDDockWidgets {
class DockWidgetBase::Private : public QObject
{
public:
Private(const QString &dockName, DockWidgetBase::Options options_,
LayoutSaverOptions layoutSaverOptions_, DockWidgetBase *qq)
: name(dockName)
, title(dockName)
, q(qq)
, options(options_)
, layoutSaverOptions(layoutSaverOptions_)
, toggleAction(new QAction(q))
, floatAction(new QAction(q))
{
q->connect(toggleAction, &QAction::toggled, q, [this] (bool enabled) {
if (!m_updatingToggleAction) { // guard against recursiveness
toggleAction->blockSignals(true); // and don't emit spurious toggle. Like when a dock widget is inserted into a tab widget it might get hide events, ignore those. The Dock Widget is open.
m_processingToggleAction = true;
toggle(enabled);
toggleAction->blockSignals(false);
m_processingToggleAction = false;
}
});
q->connect(floatAction, &QAction::toggled, q, [this] (bool checked) {
if (!m_updatingFloatAction) { // guard against recursiveness
q->setFloating(checked);
}
Q_EMIT q->isFloatingChanged(checked);
// When floating, we remove from the sidebar
if (checked && q->isOpen()) {
if (SideBar *sb = DockRegistry::self()->sideBarForDockWidget(q)) {
sb->mainWindow()->clearSideBarOverlay(/* deleteFrame=*/false);
sb->removeDockWidget(q);
}
}
});
toggleAction->setCheckable(true);
floatAction->setCheckable(true);
qApp->installEventFilter(this);
}
LayoutSaverOptions layoutSaverOptions_, DockWidgetBase *qq);
void init()
{
@@ -190,4 +155,85 @@ public:
}
#if defined(QT_WIDGETS_LIB)
#include <QAction>
#else
// A QAction for QtQuick. Just so it compiles, for now
class QAction : public QObject
{
Q_OBJECT
public:
using QObject::QObject;
bool isChecked() const
{
return m_isChecked;
}
void setCheckable(bool is)
{
m_isCheckable = is;
}
void setText(const QString &text)
{
m_text = text;
}
void setToolTip(const QString &text)
{
m_toolTip = text;
}
QString toolTip() const
{
returm m_toolTip;
}
bool enabled() const
{
return m_enabled;
}
void setEnabled(bool enabled)
{
m_enabled = enabled;
}
bool checked() const
{
return m_checked;
}
void setChecked(bool checked)
{
m_checked = checked;
}
bool isEnabled() const
{
return m_enabled;
}
void toggle()
{
m_enabled = !m_enabled;
Q_EMIT toggled(m_enabled);
}
Q_SIGNALS:
bool toggled(bool);
private:
QString m_text;
QString m_toolTip;
bool m_isChecked = false;
bool m_isCheckable = false;
bool m_enabled = false;
bool m_checked = false;
};
#endif
#endif