Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit with the code of the QtCascadesModels sample

  • Loading branch information...
commit 682b034a1d13e159cb10d0508478e9ecb21c1faa 1 parent 726376a
Vladimir Minenko authored
View
38 QtCascadesModels/ColoredItems/ColoredItems.pro
@@ -0,0 +1,38 @@
+#
+# Copyright (c) 2011-2013 Research In Motion Limited.
+# Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+QT += core gui declarative
+
+TARGET = ColoredItems
+
+TEMPLATE = app
+
+
+SOURCES += main.cpp \
+ mydataobject.cpp \
+ mydatamodel.cpp
+
+OTHER_FILES += \
+ main.qml \
+ bar-descriptor.xml
+
+RESOURCES += \
+ colored_items.qrc
+
+HEADERS += \
+ mydataobject.h \
+ mydatamodel.h
View
23 QtCascadesModels/ColoredItems/bar-descriptor.xml
@@ -0,0 +1,23 @@
+<?xml version='1.0' encoding='UTF-8' standalone='no'?>
+<qnx xmlns="http://www.qnx.com/schemas/application/1.0">
+ <id>com.example.ColoredItems</id>
+ <name>ColoredItems</name>
+ <versionNumber>1.0.0</versionNumber>
+ <description>DESCRIPTION</description>
+ <initialWindow>
+ <aspectRatio>landscape</aspectRatio>
+ <autoOrients>false</autoOrients>
+ <systemChrome>none</systemChrome>
+ <transparent>false</transparent>
+ </initialWindow>
+ <author>PUBLISHER</author>
+ <copyright>COPYRIGHT</copyright>
+ <env value="app/native/imports:/usr/lib/qt4/imports" var="QML_IMPORT_PATH"/>
+ <env value="app/native/plugins:/usr/lib/qt4/plugins" var="QT_PLUGIN_PATH"/>
+ <env value="app/native/lib:/usr/lib/qt4/lib/" var="LD_LIBRARY_PATH"/>
+ <arg>-style</arg>
+ <arg>qnxlight</arg>
+ <action system="true">run_native</action>
+ <!-- ColoredItems should point to the project binary, path can be relative -->
+ <asset path="ColoredItems" type="Qnx/Elf" entry="true">ColoredItems</asset>
+</qnx>
View
5 QtCascadesModels/ColoredItems/colored_items.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/">
+ <file>main.qml</file>
+ </qresource>
+</RCC>
View
41 QtCascadesModels/ColoredItems/main.cpp
@@ -0,0 +1,41 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+* Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <QApplication>
+#include <QDeclarativeView>
+#include <QDeclarativeContext>
+
+#include "mydatamodel.h"
+
+int main(int argc, char *argv[])
+{
+ QApplication a(argc, argv);
+ QDeclarativeView view;
+
+ // Create the model
+ MyDataModel *myDataModel = new MyDataModel(view.rootContext());
+
+ // The dataModel needs to added before loading the QML file
+ view.rootContext()->setContextProperty("dataModel", QVariant::fromValue(myDataModel->data()) );
+ view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
+
+ view.setSource(QUrl("qrc:///main.qml"));
+
+ view.show();
+
+ return a.exec();
+}
View
35 QtCascadesModels/ColoredItems/main.qml
@@ -0,0 +1,35 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+* Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import QtQuick 1.1
+
+Rectangle {
+ id: root
+ width: 300
+ height: 600
+ ListView {
+ model: dataModel
+ anchors.fill: parent
+ delegate: Rectangle {
+ height: 40; width: root.width;
+ color: model.modelData.color
+ Text {
+ text: name; anchors.centerIn: parent
+ }
+ }
+ }
+}
View
51 QtCascadesModels/ColoredItems/mydatamodel.cpp
@@ -0,0 +1,51 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+* Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <QList>
+#include <QStringList>
+// needed for the model data with all named colors in Qt
+#include <QColor>
+
+#include "mydatamodel.h"
+#include "mydataobject.h"
+
+MyDataModel::MyDataModel(QObject *parent) :
+ QObject(parent)
+{
+// Creates a data set of all named colors in Qt
+// This colors are not avaialble in Cascades UI
+// We make them available via this C++ backend
+ foreach (QString currentColorName, QColor::colorNames()) {
+ QColor currentColor (currentColorName);
+ m_data.append(new MyDataObject ("\"" + currentColorName + "\" is in hex " + currentColor.name(), currentColor.name()));
+ }
+
+// An alternative, simple data set with three manually created items
+// Boring, but clear... :-)
+// m_data.append(new MyDataObject( "White Item", "#FFFFFF"));
+// m_data.append(new MyDataObject( "Blue Item", "#0000FF"));
+// m_data.append(new MyDataObject( "Green Item", "#00FF00"));
+// m_data.append(new MyDataObject( "Red Item", "#FF0000"));
+}
+
+MyDataModel::~MyDataModel() {
+
+}
+
+QList<QObject*> MyDataModel::data() {
+ return m_data;
+}
View
41 QtCascadesModels/ColoredItems/mydatamodel.h
@@ -0,0 +1,41 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+* Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef MYDATAMODEL_H
+#define MYDATAMODEL_H
+
+#include <QObject>
+#include <QList>
+#include <QMetaType>
+
+class MyDataModel : public QObject
+{
+ Q_OBJECT
+ // read-only property to accessing the data
+ Q_PROPERTY(QList<QObject*> data READ data)
+
+public:
+ explicit MyDataModel(QObject *parent = 0);
+ virtual ~MyDataModel();
+ QList<QObject*> data();
+
+private:
+ QList<QObject*> m_data;
+
+};
+
+#endif // MYDATAMODEL_H
View
36 QtCascadesModels/ColoredItems/mydataobject.cpp
@@ -0,0 +1,36 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+* Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include "mydataobject.h"
+
+MyDataObject::MyDataObject(QString name, QString color, QObject* parent):
+ QObject(parent), m_name(name), m_color(color)
+{
+}
+
+QString MyDataObject::name() const { return m_name; }
+QString MyDataObject::color() const { return m_color; }
+
+void MyDataObject::setName(QString name) {
+ m_name = name;
+ emit nameChanged();
+}
+
+void MyDataObject::setColor(QString color) {
+ m_color = color;
+ emit colorChanged();
+}
View
50 QtCascadesModels/ColoredItems/mydataobject.h
@@ -0,0 +1,50 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+* Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef MYDATAOBJECT_H
+#define MYDATAOBJECT_H
+
+#include <QObject>
+
+class MyDataObject : public QObject
+{
+ Q_OBJECT
+ // Two properties, name and color, that allow access from QML side (through Meta-Object)
+ Q_PROPERTY( QString name READ name WRITE setName NOTIFY nameChanged )
+ Q_PROPERTY( QString color READ color WRITE setColor NOTIFY colorChanged )
+
+public:
+ MyDataObject(QString name, QString color, QObject* parent = 0);
+
+ QString name() const;
+ QString color() const;
+
+public slots:
+ void setName( QString name );
+ void setColor( QString color );
+
+signals:
+ void nameChanged();
+ void colorChanged();
+
+private:
+ QString m_name;
+ QString m_color;
+
+};
+
+#endif // MYDATAOBJECT_H
View
43 QtCascadesModels/ColoredItemsCascades/ColoredItemsCascades.cpp
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <bb/cascades/Application>
+#include <bb/cascades/QmlDocument>
+#include <bb/cascades/AbstractPane>
+#include <bb/cascades/QListDataModel>
+
+#include "ColoredItemsCascades.hpp"
+#include "../ColoredItems/mydatamodel.h"
+
+using namespace bb::cascades;
+
+ColoredItemsCascades::ColoredItemsCascades(bb::cascades::Application *app)
+ : QObject(app)
+{
+
+ // create a new model in the C++ backend
+ MyDataModel *myDataModel = new MyDataModel(app);
+ // create a data model for Cascades UI
+ QListDataModel<QObject*> *cascadesModel = new QListDataModel<QObject*>(myDataModel->data());
+
+ // load QML
+ QmlDocument *qml = QmlDocument::create("asset:///main.qml").parent(this);
+ // make the data model availavle via a property in the context of the loaded QML file
+ qml->documentContext()->setContextProperty("myCasadesDataModel", cascadesModel);
+
+ AbstractPane *root = qml->createRootObject<AbstractPane>();
+ app->setScene(root);
+}
View
17 QtCascadesModels/ColoredItemsCascades/ColoredItemsCascades.hpp
@@ -0,0 +1,17 @@
+#ifndef ColoredItemsCascades_HPP_
+#define ColoredItemsCascades_HPP_
+
+#include <QObject>
+
+namespace bb { namespace cascades { class Application; }}
+
+class ColoredItemsCascades : public QObject
+{
+ Q_OBJECT
+public:
+ ColoredItemsCascades(bb::cascades::Application *app);
+ virtual ~ColoredItemsCascades() {}
+};
+
+#endif /* ColoredItemsCascades_HPP_ */
+
View
42 QtCascadesModels/ColoredItemsCascades/ColoredItemsCascades.pro
@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2011-2013 Research In Motion Limited.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+TEMPLATE = app
+
+# Additional import path used to resolve QML modules in Creator's code model
+
+LIBS += -lbbdata -lbb -lbbcascades
+QT += declarative xml
+
+# The .cpp file which was generated for your project. Feel free to hack it.
+SOURCES += main.cpp \
+ ../ColoredItems/mydataobject.cpp \
+ ../ColoredItems/mydatamodel.cpp \
+ ColoredItemsCascades.cpp
+
+HEADERS += \
+ ../ColoredItems/mydataobject.h \
+ ../ColoredItems/mydatamodel.h \
+ ColoredItemsCascades.hpp
+
+OTHER_FILES += bar-descriptor.xml \
+ assets/main.qml \
+ assets/SecondPage.qml
+
+
+
+
View
3  QtCascadesModels/ColoredItemsCascades/assets/.assets.index
@@ -0,0 +1,3 @@
+1
+1
+main.qml
View
51 QtCascadesModels/ColoredItemsCascades/assets/SecondPage.qml
@@ -0,0 +1,51 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import bb.cascades 1.0
+
+Page {
+ id: seconPage
+ paneProperties: NavigationPaneProperties {
+ backButton: ActionItem {
+ onTriggered: {
+ navigationPane.pop()
+ }
+ }
+ }
+ Container {
+ ListView {
+ dataModel: myCasadesDataModel
+ layout: FlowListLayout {}
+ listItemComponents: [
+ ListItemComponent {
+ Container {
+ background: Color.create(ListItemData.color)
+ layoutProperties: FlowListLayoutProperties {
+ aspectRatio: 15/1
+ fillRatio: 1
+ }
+ Label {
+ text: ListItemData.name
+ horizontalAlignment: HorizontalAlignment.Center
+ }
+ }
+ }
+ ]
+ }
+ }
+}
+
+
View
54 QtCascadesModels/ColoredItemsCascades/assets/main.qml
@@ -0,0 +1,54 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import bb.cascades 1.0
+
+NavigationPane {
+ id: navigationPane
+ Page {
+ Container {
+ layout: DockLayout {}
+ Button {
+ horizontalAlignment: HorizontalAlignment.Center
+ verticalAlignment: VerticalAlignment.Center
+ text: qsTr("Get Colors!")
+ onClicked: {
+ var page = getSecondPage();
+ navigationPane.push(page);
+ }
+ property Page secondPage
+ function getSecondPage() {
+ if (! secondPage) {
+ secondPage = secondPageDefinition.createObject();
+ }
+ return secondPage;
+ }
+ attachedObjects: [
+ ComponentDefinition {
+ id: secondPageDefinition
+ source: "SecondPage.qml"
+ }
+ ]
+ }
+ }
+ }
+ onCreationCompleted: {
+ console.log("NavigationPane - onCreationCompleted()");
+ OrientationSupport.supportedDisplayOrientation = SupportedDisplayOrientation.All;
+ }
+}
+
+
View
25 QtCascadesModels/ColoredItemsCascades/assets/main_old.qml
@@ -0,0 +1,25 @@
+import bb.cascades 1.0
+
+Page {
+ content: Container {
+ ListView {
+ layout: FlowListLayout { }
+ dataModel: myCacsadesDataModel
+ listItemComponents: [
+ ListItemComponent {
+ Container {
+ background: Color.create (ListItemData.color)
+ layoutProperties: FlowListLayoutProperties {
+ aspectRatio: 15/1
+ fillRatio: 1
+ }
+ Label {
+ text: ListItemData.name
+ horizontalAlignment: HorizontalAlignment.Center
+ }
+ }
+ }
+ ]
+ }
+ }
+}
View
17 QtCascadesModels/ColoredItemsCascades/bar-descriptor.xml
@@ -0,0 +1,17 @@
+<?xml version='1.0' encoding='UTF-8' standalone='no'?>
+<qnx xmlns="http://www.qnx.com/schemas/application/1.0">
+ <id>com.example.ColoredItemsCascades</id>
+ <name>ColoredItemsCascades</name>
+ <versionNumber>1.0.0</versionNumber>
+ <description>DESCRIPTION</description>
+ <initialWindow>
+ <aspectRatio>landscape</aspectRatio>
+ <autoOrients>false</autoOrients>
+ <systemChrome>none</systemChrome>
+ <transparent>false</transparent>
+ </initialWindow>
+ <env value="app/native/lib:/usr/lib/qt4/lib/" var="LD_LIBRARY_PATH"/>
+ <action system="true">run_native</action>
+ <asset path="ColoredItemsCascades" type="Qnx/Elf" entry="true">ColoredItemsCascades</asset>
+ <asset path="%SRC_DIR%/assets">assets</asset>
+</qnx>
View
30 QtCascadesModels/ColoredItemsCascades/main.cpp
@@ -0,0 +1,30 @@
+/*
+* Copyright (c) 2011-2013 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include "ColoredItemsCascades.hpp"
+
+#include <bb/cascades/Application>
+#include <Qt/qdeclarativedebug.h>
+
+Q_DECL_EXPORT int main(int argc, char **argv)
+{
+ bb::cascades::Application app(argc, argv);
+
+ new ColoredItemsCascades(&app);
+
+ return bb::cascades::Application::exec();
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.