Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Dropped the Splitter attached properties
Browse files Browse the repository at this point in the history
  • Loading branch information
Znurre committed Mar 28, 2018
1 parent 86bf021 commit 85c8f52
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 96 deletions.
55 changes: 0 additions & 55 deletions src/declarativesplitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,7 @@

#include "declarativesplitter_p.h"

#include <QPointer>
#include <QWidget>
#include <QQmlInfo>

class DeclarativeSplitterAttached::Private
{
public:
Private(QWidget *w)
: stretch(0)
, widget(w)
{
}

int stretch;

QPointer<QWidget> widget;
};

DeclarativeSplitterAttached::DeclarativeSplitterAttached(QWidget *widget, QObject *parent)
: QObject(parent)
, d(new Private(widget))
{
}

DeclarativeSplitterAttached::~DeclarativeSplitterAttached()
{
delete d;
}

void DeclarativeSplitterAttached::setStretch(int stretch)
{
if (stretch == d->stretch)
return;

d->stretch = stretch;

emit stretchChanged(stretch);
}

int DeclarativeSplitterAttached::stretch() const
{
return d->stretch;
}

DeclarativeSplitter::DeclarativeSplitter(QWidget *parent)
: QSplitter(parent)
{
}

DeclarativeSplitterAttached *DeclarativeSplitter::qmlAttachedProperties(QObject *parent)
{
QWidget *widget = qobject_cast<QWidget*>(parent);
if (widget)
return new DeclarativeSplitterAttached(widget, parent);

qmlInfo(parent) << "Can only attach Splitter to widgets";

return Q_NULLPTR;
}
28 changes: 0 additions & 28 deletions src/declarativesplitter_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,12 @@
#ifndef DECLARATIVESPLITTER_P_H
#define DECLARATIVESPLITTER_P_H

#include <QtGlobal>
#include <QObject>
#include <QSplitter>
#include <QtQml>

class DeclarativeSplitterAttached : public QObject
{
Q_OBJECT

Q_PROPERTY(int stretch READ stretch WRITE setStretch NOTIFY stretchChanged)

public:
DeclarativeSplitterAttached(QWidget *widget, QObject *parent);
~DeclarativeSplitterAttached();

void setStretch(int stretch);
int stretch() const;

Q_SIGNALS:
void stretchChanged(int stretch);

private:
class Private;
Private *const d;
};

class DeclarativeSplitter : public QSplitter
{
public:
DeclarativeSplitter(QWidget *parent = Q_NULLPTR);

static DeclarativeSplitterAttached *qmlAttachedProperties(QObject *parent);
};

QML_DECLARE_TYPEINFO(DeclarativeSplitter, QML_HAS_ATTACHED_PROPERTIES)

#endif // DECLARATIVESPLITTER_P_H
4 changes: 2 additions & 2 deletions src/declarativewidgets_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "declarativeseparator_p.h"
#include "declarativesizepolicy_p.h"
#include "declarativespaceritem_p.h"
#include "declarativesplitter_p.h"
#include "declarativestackedlayout_p.h"
#include "declarativestatusbar_p.h"
#include "declarativestringlistmodelextension_p.h"
Expand All @@ -68,10 +69,9 @@
#include "menubarwidgetcontainer_p.h"
#include "menuwidgetcontainer_p.h"
#include "scrollareawidgetcontainer_p.h"
#include "splitterwidgetcontainer_p.h"
#include "stackedwidgetwidgetcontainer_p.h"
#include "toolbarwidgetcontainer_p.h"
#include "splitterwidgetcontainer_p.h"
#include "declarativesplitter_p.h"

#include <QAbstractItemDelegate>
#include <QButtonGroup>
Expand Down
12 changes: 1 addition & 11 deletions src/splitterwidgetcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@

#include "declarativesplitter_p.h"

#include <QSplitter>
#include <QQmlInfo>
#include <QQmlEngine>
#include <QSplitter>

SplitterWidgetContainer::SplitterWidgetContainer(QObject *parent)
: DefaultWidgetContainer(qobject_cast<QSplitter*>(parent))
Expand All @@ -47,15 +46,6 @@ void SplitterWidgetContainer::setLayout(QLayout *layout)

void SplitterWidgetContainer::addWidget(QWidget *widget)
{
QObject *attachedProperties = qmlAttachedPropertiesObject<QSplitter>(widget, false);
DeclarativeSplitterAttached *properties = qobject_cast<DeclarativeSplitterAttached*>(attachedProperties);
if (properties) {
QSizePolicy policy = widget->sizePolicy();
policy.setHorizontalStretch(properties->stretch());
policy.setVerticalStretch(properties->stretch());
widget->setSizePolicy(policy);
}

extendedSplitter()->addWidget(widget);
}

Expand Down

0 comments on commit 85c8f52

Please sign in to comment.