qml systemtray: small refactorings
Aaron J. Seigo
aseigo at kde.org
Thu Oct 25 20:43:29 UTC 2012
hi...
i suppose this is mostly for Dmitry, but its nice to have these discussions
here :)
so .. system tray plasmoid. works pretty well it seems. :)
started looking through the code a bit more deeply and i think we can start to
tighten it up a bit.
for example, it seems that TasksPool duplicates Manager. the only thing
TasksPool really adds is a QVariantHash and access to the host applet. this
probably could just be a QHash<QString, QObject*> though (skipping all the
QVariant overhead) and added to Manager.
to have this hash work in the QML, it is probably necessary to do sth like:
namespace SystemTray {
typedef QHash<QString, QObject *> ObjectHash;
}
Q_DECLARE_METATYPE(SystemTray::ObjectHash)
qRegisterMetaType<SystemTray::ObjectHash>("ObjectHash")
that should hopefully let it work via QVariant properly. (the first 3 lines go
into headers, the 3 line into C++ somewhere)
UiTask is also ripe for some refactoring, as it's really just a proxy for
Task. the TaskType enum should go into Task itself, and a QString id() const
method should be added to Task as well. that really just leaves how to get at
the host applet pointer so that the widget can be retrieved.
the applet pointer could be made available to the QML and then WidgetItem
could have an applet (or host?) property which it would use to derive its
widget().
then TasksPool is not needed for the host applet pointer. UiTask becomes just
Task, and Manager can be used directly instead of TasksPool in the QML.
something else I don't quite understand from the code is why QObjects, which
import into QML just fine, are turned in QVariants everywhere before being sent
into the QML?
and example is in WidgetItem:
Q_PROPERTY(QVariant widget READ widget WRITE setWidget NOTIFY
changedWidget) ///< widget to embed
all it does is return a QObject pointer.. QML *should* handle that just fine,
and when i changed it to be just a QObject, it indeed continued to work as
expected. (i've even pushed that change)
.. there's probably more, but this is probably a good start. what's there now
is functional and definitely decent code to be certain; it's just nice to make
it as smooth as possible so maintenance later is easier :)
p.s. i'd also like to get rid of all the private pimpl classes; this is not a
library after all :)
--
Aaron J. Seigo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/plasma-devel/attachments/20121025/b60b4ba3/attachment-0001.sig>
More information about the Plasma-devel
mailing list