on 551c708 help sign in
unity8/tests/plugins/DashViews/verticaljournaltry.cpp
90 lines 2.5 kB history raw
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
17#include <QQuickView>
18#include <QDebug>
19#include <QGuiApplication>
20#include <QQuickView>
21#include <QtQml/qqml.h>
22#include <QStringListModel>
23#include <QQmlContext>
24#include <QQmlEngine>
25#include <QGuiApplication>
27#include "verticaljournal.h"
29class QHeightModel : public QStringListModel {
30 Q_OBJECT
31public:
32 QHash<int, QByteArray> roleNames() const
33 {
34 QHash<int, QByteArray> roles;
35 roles.insert(Qt::DisplayRole, "modelHeight");
36 return roles;
37 }
39public slots:
40 void add(int height)
41 {
42 if (height <= 0) {
43 height = 50 + 50. * qrand() / RAND_MAX ;
44 }
45 QStringList sl = stringList();
46 sl << QString::number(height);
47 setStringList(sl);
48 }
50 void remove()
51 {
52 QStringList sl = stringList();
53 if (!sl.isEmpty()) {
54 sl.removeLast();
55 setStringList(sl);
56 }
57 }
58};
60int main(int argc, char *argv[])
62 QGuiApplication a(argc, argv);
64 QQuickView *view = new QQuickView();
65 view->setResizeMode(QQuickView::SizeRootObjectToView);
66 view->engine()->addImportPath(BUILT_PLUGINS_DIR);
68 QHeightModel model;
69 QStringList heightList;
70 heightList << "100" << "50" << "125";
71 model.setStringList(heightList);
73 QStringListModel listModel;
74 listModel.setStringList(QStringList() << QString());
76 view->rootContext()->setContextProperty("listModel", &listModel);
77 view->rootContext()->setContextProperty("vjModel", &model);
79 view->setSource(QUrl::fromLocalFile(DASHVIEWSTEST_FOLDER "/verticaljournaltry.qml"));
81 view->show();
82 view->resize(530, 400);
84 QObject::connect(view->rootObject(), SIGNAL(add(int)), &model, SLOT(add(int)));
85 QObject::connect(view->rootObject(), SIGNAL(remove()), &model, SLOT(remove()));
87 return a.exec();
90#include "verticaljournaltry.moc"