on master help sign in
unity8/tests/plugins/Dash/organicgridtry.cpp
99 lines 2.5 kB history raw
1/*
2 * Copyright (C) 2014 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 DummyModel : public QAbstractListModel {
32 Q_OBJECT
33public:
34 DummyModel() : m_count(0) {}
36 int rowCount(const QModelIndex & /*parent*/) const override
37 {
38 return m_count;
39 }
41 QVariant data(const QModelIndex & /*index*/, int /*role*/) const override
42 {
43 return QVariant();
44 }
46 void setCount(int count)
47 {
48 beginResetModel();
49 m_count = count;
50 endResetModel();
51 }
53public slots:
54 void addItem()
55 {
56 beginInsertRows(QModelIndex(), m_count, m_count);
57 m_count++;
58 endInsertRows();
59 }
61 void removeLast()
62 {
63 beginRemoveRows(QModelIndex(), m_count - 1, m_count - 1);
64 m_count--;
65 endRemoveRows();
66 }
68private:
69 int m_count;
70};
72int main(int argc, char *argv[])
74 QGuiApplication a(argc, argv);
76 QQuickView *view = new QQuickView();
77 view->setResizeMode(QQuickView::SizeRootObjectToView);
79 DummyModel model;
80 model.setCount(3);
82 QStringListModel listModel;
83 listModel.setStringList(QStringList() << QString());
85 view->rootContext()->setContextProperty("listModel", &listModel);
86 view->rootContext()->setContextProperty("gridModel", &model);
88 view->setSource(QUrl::fromLocalFile(testDataDir() + "/" TEST_DIR "/organicgridtry.qml"));
90 view->show();
91 view->resize(530, 400);
93 QObject::connect(view->rootObject(), SIGNAL(add()), &model, SLOT(addItem()));
94 QObject::connect(view->rootObject(), SIGNAL(remove()), &model, SLOT(removeLast()));
96 return a.exec();
99#include "organicgridtry.moc"