on dbb8563 help sign in
unity8/tests/plugins/Dash/verticaljournaltry.cpp
91 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"
29#include <paths.h>
31class QHeightModel : public QStringListModel {
32 Q_OBJECT
33public:
34 QHash<int, QByteArray> roleNames() const override
35 {
36 QHash<int, QByteArray> roles;
37 roles.insert(Qt::DisplayRole, "modelHeight");
38 return roles;
39 }
41public slots:
42 void add(int height)
43 {
44 if (height <= 0) {
45 height = 50 + 50. * qrand() / RAND_MAX ;
46 }
47 QStringList sl = stringList();
48 sl << QString::number(height);
49 setStringList(sl);
50 }
52 void remove()
53 {
54 QStringList sl = stringList();
55 if (!sl.isEmpty()) {
56 sl.removeLast();
57 setStringList(sl);
58 }
59 }
60};
62int main(int argc, char *argv[])
64 QGuiApplication a(argc, argv);
66 QQuickView *view = new QQuickView();
67 view->setResizeMode(QQuickView::SizeRootObjectToView);
69 QHeightModel model;
70 QStringList heightList;
71 heightList << "100" << "50" << "125";
72 model.setStringList(heightList);
74 QStringListModel listModel;
75 listModel.setStringList(QStringList() << QString());
77 view->rootContext()->setContextProperty("listModel", &listModel);
78 view->rootContext()->setContextProperty("vjModel", &model);
80 view->setSource(QUrl::fromLocalFile(testDataDir() + "/" TEST_DIR "/verticaljournaltry.qml"));
82 view->show();
83 view->resize(530, 400);
85 QObject::connect(view->rootObject(), SIGNAL(add(int)), &model, SLOT(add(int)));
86 QObject::connect(view->rootObject(), SIGNAL(remove()), &model, SLOT(remove()));
88 return a.exec();
91#include "verticaljournaltry.moc"