on f621663 help sign in
unity8/tests/plugins/Dash/organicgridtry.cpp
98 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"
29class DummyModel : public QAbstractListModel {
30 Q_OBJECT
31public:
32 DummyModel() : m_count(0) {}
34 int rowCount(const QModelIndex & /*parent*/) const
35 {
36 return m_count;
37 }
39 QVariant data(const QModelIndex & /*index*/, int /*role*/) const
40 {
41 return QVariant();
42 }
44 void setCount(int count)
45 {
46 beginResetModel();
47 m_count = count;
48 endResetModel();
49 }
51public slots:
52 void addItem()
53 {
54 beginInsertRows(QModelIndex(), m_count, m_count);
55 m_count++;
56 endInsertRows();
57 }
59 void removeLast()
60 {
61 beginRemoveRows(QModelIndex(), m_count - 1, m_count - 1);
62 m_count--;
63 endRemoveRows();
64 }
66private:
67 int m_count;
68};
70int main(int argc, char *argv[])
72 QGuiApplication a(argc, argv);
74 QQuickView *view = new QQuickView();
75 view->setResizeMode(QQuickView::SizeRootObjectToView);
76 view->engine()->addImportPath(BUILT_PLUGINS_DIR);
78 DummyModel model;
79 model.setCount(3);
81 QStringListModel listModel;
82 listModel.setStringList(QStringList() << QString());
84 view->rootContext()->setContextProperty("listModel", &listModel);
85 view->rootContext()->setContextProperty("gridModel", &model);
87 view->setSource(QUrl::fromLocalFile(DASHVIEWSTEST_FOLDER "/organicgridtry.qml"));
89 view->show();
90 view->resize(530, 400);
92 QObject::connect(view->rootObject(), SIGNAL(add()), &model, SLOT(addItem()));
93 QObject::connect(view->rootObject(), SIGNAL(remove()), &model, SLOT(removeLast()));
95 return a.exec();
98#include "organicgridtry.moc"