Krita Source Code Documentation
Loading...
Searching...
No Matches
KoLineStyleModel Class Reference

The line style model managing the style data. More...

#include <KoLineStyleModel_p.h>

+ Inheritance diagram for KoLineStyleModel:

Public Member Functions

bool addCustomStyle (const QVector< qreal > &style)
 adds the given style to the model
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const override
 
 KoLineStyleModel (QObject *parent=0)
 
int rowCount (const QModelIndex &parent=QModelIndex()) const override
 
int setLineStyle (Qt::PenStyle style, const QVector< qreal > &dashes)
 selects the given style
 
 ~KoLineStyleModel () override
 

Private Attributes

bool m_hasTempStyle
 state of the temporary style
 
QList< QVector< qreal > > m_styles
 the added styles
 
QVector< qreal > m_tempStyle
 a temporary added style
 

Detailed Description

The line style model managing the style data.

Definition at line 14 of file KoLineStyleModel_p.h.

Constructor & Destructor Documentation

◆ KoLineStyleModel()

KoLineStyleModel::KoLineStyleModel ( QObject * parent = 0)
explicit

Definition at line 11 of file KoLineStyleModel.cpp.

12 : QAbstractListModel(parent),
13 m_hasTempStyle(false)
14{
15 // add standard dash patterns
16 for (int i = Qt::NoPen; i < Qt::CustomDashLine; i++) {
17 QPen pen(static_cast<Qt::PenStyle>(i));
18 m_styles << pen.dashPattern();
19 }
20}
QList< QVector< qreal > > m_styles
the added styles
bool m_hasTempStyle
state of the temporary style

References m_styles.

◆ ~KoLineStyleModel()

KoLineStyleModel::~KoLineStyleModel ( )
inlineoverride

Definition at line 18 of file KoLineStyleModel_p.h.

18{}

Member Function Documentation

◆ addCustomStyle()

bool KoLineStyleModel::addCustomStyle ( const QVector< qreal > & style)

adds the given style to the model

Definition at line 54 of file KoLineStyleModel.cpp.

55{
56 if (m_styles.contains(style))
57 return false;
58
59 m_styles.append(style);
60 return true;
61}

References m_styles.

◆ data()

QVariant KoLineStyleModel::data ( const QModelIndex & index,
int role = Qt::DisplayRole ) const
override

Definition at line 27 of file KoLineStyleModel.cpp.

28{
29 if (!index.isValid())
30 return QVariant();
31
32 switch(role) {
33 case Qt::DecorationRole: {
34 QPen pen(Qt::black);
35 pen.setWidth(2);
36 if (index.row() < Qt::CustomDashLine)
37 pen.setStyle(static_cast<Qt::PenStyle>(index.row()));
38 else if (index.row() < m_styles.count())
39 pen.setDashPattern(m_styles[index.row()]);
40 else if (m_hasTempStyle)
41 pen.setDashPattern(m_tempStyle);
42 else
43 pen.setStyle(Qt::NoPen);
44
45 return QVariant(pen);
46 }
47 case Qt::SizeHintRole:
48 return QSize(100, 15);
49 default:
50 return QVariant();
51 }
52}
QVector< qreal > m_tempStyle
a temporary added style

References m_hasTempStyle, m_styles, and m_tempStyle.

◆ rowCount()

int KoLineStyleModel::rowCount ( const QModelIndex & parent = QModelIndex()) const
override

Definition at line 22 of file KoLineStyleModel.cpp.

23{
24 return m_styles.count() + (m_hasTempStyle ? 1 : 0);
25}

References m_hasTempStyle, and m_styles.

◆ setLineStyle()

int KoLineStyleModel::setLineStyle ( Qt::PenStyle style,
const QVector< qreal > & dashes )

selects the given style

Definition at line 63 of file KoLineStyleModel.cpp.

64{
65 // check if we select a standard or custom style
66 if (style < Qt::CustomDashLine) {
67 // a standard style
68 m_hasTempStyle = false;
69 beginResetModel();
70 endResetModel();
71
72 return style;
73 } else if (style == Qt::CustomDashLine) {
74 // a custom style -> check if already added
75 int index = m_styles.indexOf(dashes, Qt::CustomDashLine);
76 if (index < 0) {
77 // not already added -> add temporarily
78 m_tempStyle = dashes;
79 m_hasTempStyle = true;
80 beginResetModel();
81 endResetModel();
82
83 return m_styles.count();
84 } else {
85 // already added -> return index
86 m_hasTempStyle = false;
87 beginResetModel();
88 endResetModel();
89
90 return index;
91 }
92 }
93 return -1;
94}

References m_hasTempStyle, m_styles, and m_tempStyle.

Member Data Documentation

◆ m_hasTempStyle

bool KoLineStyleModel::m_hasTempStyle
private

state of the temporary style

Definition at line 29 of file KoLineStyleModel_p.h.

◆ m_styles

QList<QVector<qreal> > KoLineStyleModel::m_styles
private

the added styles

Definition at line 27 of file KoLineStyleModel_p.h.

◆ m_tempStyle

QVector<qreal> KoLineStyleModel::m_tempStyle
private

a temporary added style

Definition at line 28 of file KoLineStyleModel_p.h.


The documentation for this class was generated from the following files: