on 16fa310 help sign in
unity8/tests/mocks/Unity/fake_previewmodel.cpp
103 lines 2.6 kB history raw
1/*
2 * Copyright (C) 2014 Canonical, Ltd.
3 *
4 * Authors:
5 * Michał Sawicz <michal.sawicz@canonical.com>
6 * Michal Hruby <michal.hruby@canonical.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 3.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
21// self
22#include "fake_previewmodel.h"
24// local
25#include "fake_scope.h"
26#include "fake_scopes.h"
27#include "fake_previewwidgetmodel.h"
29// Qt
30#include <QDebug>
32PreviewModel::PreviewModel(QObject* parent, Scope* scope)
33 : unity::shell::scopes::PreviewModelInterface(parent)
34 , m_loaded(true)
35 , m_scope(scope)
37 setWidgetColumnCount(1);
38 connect(this, &PreviewModel::triggered, this, &PreviewModel::triggeredSlot);
41void PreviewModel::setWidgetColumnCount(int count)
43 if (count != widgetColumnCount()) {
44 beginResetModel();
46 m_previewWidgetModels.clear();
47 for (int i = 0; i < count; ++i) {
48 PreviewWidgetModel* columnModel = new PreviewWidgetModel(this);
49 m_previewWidgetModels.append(columnModel);
50 }
52 endResetModel();
54 Q_EMIT widgetColumnCountChanged();
55 }
58int PreviewModel::widgetColumnCount() const
60 return m_previewWidgetModels.size();
63bool PreviewModel::loaded() const
65 return m_loaded;
68bool PreviewModel::processingAction() const
70 return false;
73int PreviewModel::rowCount(const QModelIndex&) const
75 return widgetColumnCount();
78QVariant PreviewModel::data(const QModelIndex& index, int role) const
80 switch (role) {
81 case RoleColumnModel:
82 return QVariant::fromValue(m_previewWidgetModels.at(index.row()));
83 default:
84 return QVariant();
85 }
88void PreviewModel::setLoaded(bool loaded)
90 if (m_loaded != loaded) {
91 m_loaded = loaded;
92 Q_EMIT loadedChanged();
93 }
96void PreviewModel::triggeredSlot(QString const&, QString const&, QVariantMap const&) {
97 if (m_scope) {
98 Scopes *scopes = static_cast<Scopes*>(m_scope->parent());
99 Scope* scope = scopes->getScopeFromAll("MockScope9");
100 scopes->addTempScope(scope);
101 Q_EMIT m_scope->openScope(scope);
102 }