Add GuestWidget.h
The QtWidgets counter-part for GuestInterface. Removing QWidget from Item
This commit is contained in:
@@ -166,6 +166,7 @@ install (FILES ${DOCKS_INSTALLABLE_INCLUDES} DESTINATION include/kddockwidgets)
|
||||
install (FILES ${DOCKS_INSTALLABLE_PRIVATE_INCLUDES} DESTINATION include/kddockwidgets/private)
|
||||
install (FILES private/multisplitter/Item_p.h DESTINATION include/kddockwidgets/multisplitter)
|
||||
install (FILES private/multisplitter/GuestInterface.h DESTINATION include/kddockwidgets/multisplitter)
|
||||
install (FILES private/multisplitter/GuestWidget.h DESTINATION include/kddockwidgets/multisplitter)
|
||||
install (FILES ${DOCKS_INSTALLABLE_PRIVATE_WIDGET_INCLUDES} DESTINATION include/kddockwidgets/private/widgets)
|
||||
|
||||
include(CMakePackageConfigHelpers)
|
||||
|
||||
@@ -59,6 +59,7 @@ static FrameOptions actualOptions(FrameOptions options)
|
||||
|
||||
Frame::Frame(QWidgetOrQuick *parent, FrameOptions options)
|
||||
: QWidgetAdapter(parent)
|
||||
, Layouting::GuestWidget(this)
|
||||
, m_tabWidget(Config::self().frameworkWidgetFactory()->createTabWidget(this))
|
||||
, m_titleBar(Config::self().frameworkWidgetFactory()->createTitleBar(this))
|
||||
, m_options(actualOptions(options))
|
||||
@@ -420,11 +421,6 @@ QString Frame::affinityName() const
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *Frame::asWidget()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
DockWidgetBase *Frame::dockWidgetAt(int index) const
|
||||
{
|
||||
return qobject_cast<DockWidgetBase *>(m_tabWidget->dockwidgetAt(index));
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "docks_export.h"
|
||||
#include "QWidgetAdapter.h"
|
||||
#include "LayoutSaver_p.h"
|
||||
#include "multisplitter/GuestInterface.h"
|
||||
#include "multisplitter/GuestWidget.h"
|
||||
#include "multisplitter/Item_p.h"
|
||||
|
||||
#include <QWidget>
|
||||
@@ -58,7 +58,7 @@ class FloatingWindow;
|
||||
* to a FloatingWindow.
|
||||
*/
|
||||
class DOCKS_EXPORT Frame : public QWidgetAdapter
|
||||
, public Layouting::GuestInterface
|
||||
, public Layouting::GuestWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -203,9 +203,6 @@ public:
|
||||
///@brief sets the layout item that either contains this Frame in the layout or is a placeholder
|
||||
void setLayoutItem(Layouting::Item *item) override;
|
||||
|
||||
///@brief Overriden from GuestInterface
|
||||
QWidget *asWidget() override;
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentDockWidgetChanged(KDDockWidgets::DockWidgetBase *);
|
||||
void numDockWidgetsChanged();
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#pragma once
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
@@ -22,6 +21,8 @@
|
||||
///@file
|
||||
///@brief An abstraction so the layout can host QWidget or QQuickItem or something else
|
||||
|
||||
#pragma once
|
||||
|
||||
class QWidget; // TODO: Remove
|
||||
|
||||
namespace Layouting {
|
||||
|
||||
44
src/private/multisplitter/GuestWidget.h
Normal file
44
src/private/multisplitter/GuestWidget.h
Normal file
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
This file is part of KDDockWidgets.
|
||||
|
||||
Copyright (C) 2018-2020 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
|
||||
Author: Sérgio Martins <sergio.martins@kdab.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.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GuestInterface.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Layouting {
|
||||
class GuestWidget : public GuestInterface
|
||||
{
|
||||
public:
|
||||
explicit GuestWidget(QWidget *thisWidget)
|
||||
: m_thisWidget(thisWidget)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget * asWidget() override {
|
||||
return m_thisWidget;
|
||||
}
|
||||
|
||||
private:
|
||||
QWidget *const m_thisWidget;
|
||||
Q_DISABLE_COPY(GuestWidget)
|
||||
};
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "Item_p.h"
|
||||
#include "Separator_p.h"
|
||||
#include "GuestInterface.h"
|
||||
#include "GuestWidget.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QtTest/QtTest>
|
||||
@@ -40,16 +40,20 @@ static QString s_expectedWarning;
|
||||
class TestMultiSplitter;
|
||||
static TestMultiSplitter* s_testObject = nullptr;
|
||||
|
||||
class GuestWidget : public QWidget
|
||||
, public GuestInterface
|
||||
class MyGuestWidget : public QWidget
|
||||
, public GuestWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
void setLayoutItem(Item *) override {}
|
||||
QWidget * asWidget() override {
|
||||
return this;
|
||||
|
||||
MyGuestWidget()
|
||||
: QWidget()
|
||||
, GuestWidget(this)
|
||||
{
|
||||
}
|
||||
|
||||
void setLayoutItem(Item *) override {}
|
||||
|
||||
QSize minimumSizeHint() const override
|
||||
{
|
||||
return m_minSize;
|
||||
@@ -202,7 +206,7 @@ static bool serializeDeserializeTest(const std::unique_ptr<ItemContainer> &root)
|
||||
QHash<QString, GuestInterface*> widgets;
|
||||
const Item::List originalItems = root->items_recursive();
|
||||
for (Item *item : originalItems)
|
||||
if (auto w = static_cast<GuestWidget*>(item->widget()))
|
||||
if (auto w = static_cast<MyGuestWidget*>(item->widget()))
|
||||
widgets.insert(QString::number(qint64(w)), w);
|
||||
|
||||
root2.fillFromVariantMap(serialized, widgets);
|
||||
@@ -230,7 +234,7 @@ static Item* createItem(QSize minSz = {})
|
||||
auto item = new Item(hostWidget);
|
||||
item->setGeometry(QRect(0, 0, 200, 200));
|
||||
item->setObjectName(QStringLiteral("%1").arg(count));
|
||||
auto guest = new GuestWidget();
|
||||
auto guest = new MyGuestWidget();
|
||||
if (!minSz.isNull())
|
||||
guest->setMinSize(minSz);
|
||||
guest->setObjectName(item->objectName());
|
||||
@@ -1092,7 +1096,7 @@ void TestMultiSplitter::tst_minSizeChanges()
|
||||
root->setSize_recursive(QSize(200, 200));
|
||||
QVERIFY(root->checkSanity());
|
||||
|
||||
auto w1 = static_cast<GuestWidget*>(item1->widget()); // TODO: Static cast not required ?
|
||||
auto w1 = static_cast<MyGuestWidget*>(item1->widget()); // TODO: Static cast not required ?
|
||||
w1->setMinSize(QSize(300, 300));
|
||||
QVERIFY(root->checkSanity());
|
||||
QCOMPARE(root->size(), QSize(300, 300));
|
||||
@@ -1478,7 +1482,7 @@ void TestMultiSplitter::tst_minSizeChangedBeforeRestore()
|
||||
root->insertItem(item2, Item::Location_OnBottom);
|
||||
const QSize originalSize2 = item2->size();
|
||||
|
||||
auto guest2 = qobject_cast<GuestWidget*>(item2->guest()->asWidget());
|
||||
auto guest2 = qobject_cast<MyGuestWidget*>(item2->guest()->asWidget());
|
||||
const QSize newMinSize = originalSize2 + QSize(10, 10);
|
||||
|
||||
item2->turnIntoPlaceholder();
|
||||
|
||||
Reference in New Issue
Block a user