Krita Source Code Documentation
Loading...
Searching...
No Matches
KoMarkerModel.cpp
Go to the documentation of this file.
1/* This file is part of the KDE project
2 * SPDX-FileCopyrightText: 2011 Thorsten Zachmann <zachmann@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#include "KoMarkerModel.h"
8
9// Calligra
10#include <KoMarker.h>
11// Qt
12#include <QSize>
13
14
16 : QAbstractListModel(parent)
17 , m_markerPosition(position)
18 , m_temporaryMarkerPosition(-1)
19{
20 Q_FOREACH (KoMarker *marker, markers) {
21 m_markers.append(QExplicitlySharedDataPointer<KoMarker>(marker));
22 }
23}
24
28
29int KoMarkerModel::rowCount(const QModelIndex &parent) const
30{
31 Q_UNUSED(parent);
32 return m_markers.count();
33}
34
35QVariant KoMarkerModel::data(const QModelIndex &index, int role) const
36{
37 if (!index.isValid()) {
38 return QVariant();
39 }
40
41 switch(role) {
42 case Qt::DecorationRole:
43 if (index.row() < m_markers.size()) {
44 return QVariant::fromValue<KoMarker*>(m_markers.at(index.row()).data());
45 }
46 return QVariant();
47 case Qt::SizeHintRole:
48 return QSize(80,30);
49 default:
50 return QVariant();
51 }
52}
53
55{
56 for (int i = 0; i < m_markers.size(); i++) {
57 if (m_markers[i] == marker) return i;
58 if (m_markers[i] && marker && *m_markers[i] == *marker) return i;
59 }
60
61 return false;
62}
63
65{
68 }
69
70 m_temporaryMarkerPosition = m_markers.size() > 0 ? 1 : 0;
71 beginInsertRows(QModelIndex(), m_temporaryMarkerPosition, m_temporaryMarkerPosition);
72 m_markers.prepend(QExplicitlySharedDataPointer<KoMarker>(marker));
73
74 endInsertRows();
75
77}
78
80{
82 beginRemoveRows(QModelIndex(), m_temporaryMarkerPosition, m_temporaryMarkerPosition);
85 endRemoveRows();
86 }
87}
88
93
94QVariant KoMarkerModel::marker(int index, int role) const
95{
96 if (index < 0){
97 return QVariant();
98 }
99
100 switch(role) {
101 case Qt::DecorationRole:
102 if (index< m_markers.size()) {
103 return QVariant::fromValue<KoMarker*>(m_markers.at(index).data());
104 }
105 return QVariant();
106 case Qt::SizeHintRole:
107 return QSize(80, 30);
108 default:
109 return QVariant();
110 }
111}
112
int m_temporaryMarkerPosition
QList< QExplicitlySharedDataPointer< KoMarker > > m_markers
QVariant marker(int index, int role=Qt::UserRole) const
int temporaryMarkerPosition() const
~KoMarkerModel() override
KoFlake::MarkerPosition m_markerPosition
KoFlake::MarkerPosition position() const
KoMarkerModel(const QList< KoMarker * > markers, KoFlake::MarkerPosition position, QObject *parent=0)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void removeTemporaryMarker()
int addTemporaryMarker(KoMarker *marker)
int markerIndex(KoMarker *marker) const
int rowCount(const QModelIndex &parent=QModelIndex()) const override
MarkerPosition
Definition KoFlake.h:41