This repository has been archived by the owner on Sep 4, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[qml] Merge old and new QML interfaces. Fixes MER#1418
Signed-off-by: Denis Zalevskiy <denis.zalevskiy@jolla.com>
- Loading branch information
Denis Zalevskiy
committed
Nov 12, 2015
1 parent
a152239
commit a30e6e9
Showing
8 changed files
with
245 additions
and
2 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
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,2 @@ | ||
module org.freedesktop.contextkit | ||
plugin contextkit |
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,16 @@ | ||
/** | ||
* @file client.hpp | ||
* @brief Statefs QML plugin | ||
* @copyright (C) 2013-2014 Jolla Ltd. | ||
* @par License: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html | ||
*/ | ||
|
||
#include "contextkit_plugin.hpp" | ||
#include "contextkit_property.hpp" | ||
|
||
#include <qqml.h> | ||
|
||
void ContextkitPlugin::registerTypes(char const* uri) | ||
{ | ||
qmlRegisterType<ContextPropertyDeclarative>(uri, 1, 0, "ContextProperty"); | ||
} |
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,14 @@ | ||
#ifndef _STATEFS_QML_PLUGIN_QT5_HPP_ | ||
#define _STATEFS_QML_PLUGIN_QT5_HPP_ | ||
|
||
#include <QtQml/QQmlExtensionPlugin> | ||
|
||
class ContextkitPlugin : public QQmlExtensionPlugin | ||
{ | ||
Q_OBJECT | ||
Q_PLUGIN_METADATA(IID "org.freedesktop.contextkit") | ||
public: | ||
void registerTypes(char const* uri); | ||
}; | ||
|
||
#endif // _STATEFS_QML_PLUGIN_QT5_HPP_ |
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,98 @@ | ||
/** | ||
* @file qml/property.cpp | ||
* @brief Statefs property binding | ||
* @copyright (C) 2012-2015 Jolla Ltd. | ||
* @par License: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html | ||
*/ | ||
|
||
#include "contextkit_property.hpp" | ||
#include <contextsubscriber/contextproperty.h> | ||
|
||
ContextPropertyDeclarative::ContextPropertyDeclarative(QObject* parent) | ||
: QObject(parent) | ||
, state_(State::Unknown) | ||
, impl_(nullptr) | ||
{ | ||
} | ||
|
||
ContextPropertyDeclarative::~ContextPropertyDeclarative() | ||
{ | ||
} | ||
|
||
void ContextPropertyDeclarative::componentComplete() | ||
{ | ||
if (state_ == State::Unknown) | ||
setSubscribed(true); | ||
else | ||
updateImpl(); | ||
} | ||
|
||
void ContextPropertyDeclarative::updateImpl() | ||
{ | ||
if (state_ == State::Subscribed) { | ||
if (impl_) { | ||
if (impl_->key() != key_) { | ||
delete impl_; | ||
} else { | ||
impl_->subscribe(); | ||
} | ||
} | ||
if (!impl_) { | ||
impl_ = new ContextProperty(key_, this); | ||
connect(impl_, &ContextProperty::valueChanged | ||
, this, &ContextPropertyDeclarative::valueChanged); | ||
} | ||
} else if (state_ == State::Unsubscribed) { | ||
if (impl_) | ||
impl_->unsubscribe(); | ||
} | ||
} | ||
|
||
QString ContextPropertyDeclarative::getKey() const | ||
{ | ||
return key_; | ||
} | ||
|
||
void ContextPropertyDeclarative::setKey(QString const &key) | ||
{ | ||
if (key_ != key) { | ||
key_ = key; | ||
updateImpl(); | ||
emit keyChanged(); | ||
} | ||
} | ||
|
||
QVariant ContextPropertyDeclarative::getValue() const | ||
{ | ||
return impl_ ? impl_->value(default_value_) : default_value_; | ||
} | ||
|
||
void ContextPropertyDeclarative::setDefaultValue(QVariant const &v) | ||
{ | ||
default_value_ = v; | ||
} | ||
|
||
bool ContextPropertyDeclarative::getSubscribed() const | ||
{ | ||
return state_ == State::Subscribed; | ||
} | ||
|
||
void ContextPropertyDeclarative::setSubscribed(bool v) | ||
{ | ||
auto newState = v ? State::Subscribed : State::Unsubscribed; | ||
if (state_ != newState) { | ||
state_ = newState; | ||
updateImpl(); | ||
emit subscribedChanged(); | ||
} | ||
} | ||
|
||
void ContextPropertyDeclarative::subscribe() | ||
{ | ||
setSubscribed(true); | ||
} | ||
|
||
void ContextPropertyDeclarative::unsubscribe() | ||
{ | ||
setSubscribed(false); | ||
} |
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,66 @@ | ||
#ifndef _CONTEXTKIT_QML_PROPERTY_HPP_ | ||
#define _CONTEXTKIT_QML_PROPERTY_HPP_ | ||
/** | ||
* @file qml/context_property.hpp | ||
* @brief Contextkit property binding | ||
* @copyright (C) 2012-2015 Jolla Ltd. | ||
* @par License: LGPL 2.1 http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html | ||
*/ | ||
|
||
#include <QObject> | ||
#include <QVariant> | ||
#include <QString> | ||
#include <QQmlParserStatus> | ||
|
||
class ContextProperty; | ||
|
||
class ContextPropertyDeclarative : public QObject, public QQmlParserStatus | ||
{ | ||
Q_OBJECT; | ||
Q_PROPERTY(QString key READ getKey WRITE setKey | ||
NOTIFY keyChanged); | ||
Q_PROPERTY(QVariant value READ getValue WRITE setDefaultValue | ||
NOTIFY valueChanged); | ||
Q_PROPERTY(bool subscribed READ getSubscribed WRITE setSubscribed | ||
NOTIFY subscribedChanged) | ||
Q_CLASSINFO("DefaultProperty", "value"); | ||
Q_INTERFACES(QQmlParserStatus) | ||
|
||
public: | ||
ContextPropertyDeclarative(QObject* parent = 0); | ||
~ContextPropertyDeclarative(); | ||
|
||
QString getKey() const; | ||
void setKey(QString const&); | ||
|
||
QVariant getValue() const; | ||
void setDefaultValue(QVariant const&); | ||
|
||
bool getSubscribed() const; | ||
void setSubscribed(bool subscribed); | ||
|
||
Q_INVOKABLE void subscribe(); | ||
Q_INVOKABLE void unsubscribe(); | ||
|
||
signals: | ||
void valueChanged(); | ||
void subscribedChanged(); | ||
void keyChanged(); | ||
|
||
protected: | ||
// QQmlParserStatus | ||
virtual void classBegin() {} | ||
virtual void componentComplete(); | ||
|
||
private: | ||
|
||
void updateImpl(); | ||
|
||
QString key_; | ||
QVariant default_value_; | ||
enum class State { Unknown, Subscribed, Unsubscribed }; | ||
State state_; | ||
ContextProperty *impl_; | ||
}; | ||
|
||
#endif |
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