LibreCAD
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
LinePatternModel Class Reference

Model to display a list of DxfLinePatterns in a QTableView. Show preview, name and description. More...

#include <linepatternmodel.h>

Inheritance diagram for LinePatternModel:
Collaboration diagram for LinePatternModel:

Public Types

enum  columns { PREVIEW, NAME, DESCRIPTION, LAST }
 

Public Member Functions

 LinePatternModel (QObject *parent=0)
 Create widget. More...
 
void setLinePatterns (std::vector< lc::DxfLinePatternByValue_CSPtr > linePatterns)
 Set the new list of line patterns. More...
 
lc::DxfLinePattern_CSPtr linePatternAt (const int index) const
 Return line pattern at specific row. More...
 
int rowCount (const QModelIndex &parent=QModelIndex()) const
 
int columnCount (const QModelIndex &parent=QModelIndex()) const
 
QVariant data (const QModelIndex &index, int role=Qt::DisplayRole) const
 
QVariant headerData (int section, Qt::Orientation orientation, int role) const
 

Private Attributes

std::vector
< lc::DxfLinePatternByValue_CSPtr > 
_linePatterns
 

Detailed Description

Model to display a list of DxfLinePatterns in a QTableView. Show preview, name and description.

Definition at line 18 of file linepatternmodel.h.

Member Enumeration Documentation

Enumerator
PREVIEW 
NAME 
DESCRIPTION 
LAST 

Definition at line 22 of file linepatternmodel.h.

Constructor & Destructor Documentation

LinePatternModel::LinePatternModel ( QObject *  parent = 0)

Create widget.

Parameters
parentPointer to parent object

Definition at line 3 of file linepatternmodel.cpp.

3  :
4  QAbstractTableModel(parent) {
5 }

Member Function Documentation

int LinePatternModel::columnCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 23 of file linepatternmodel.cpp.

23  {
24  return LAST;
25 }
QVariant LinePatternModel::data ( const QModelIndex &  index,
int  role = Qt::DisplayRole 
) const

Definition at line 27 of file linepatternmodel.cpp.

27  {
28  if (!index.isValid()) {
29  return QVariant();
30  }
31 
32  auto linePattern = _linePatterns.at(index.row());
33 
34  if(role == Qt::DecorationRole && index.column() == PREVIEW) {
35  QPixmap pixmap(PREVIEW_WIDTH, PREVIEW_HEIGHT);
36 
37  auto linePatternByValue = std::dynamic_pointer_cast<const lc::DxfLinePatternByValue>(linePattern);
38 
39  if(linePatternByValue != nullptr) {
40  auto painter = LinePatternPainter(&pixmap, linePatternByValue);
41  painter.drawLinePattern();
42  }
43 
44  return pixmap;
45  }
46 
47  if(role == Qt::SizeHintRole && index.column() == PREVIEW) {
48  return QSize(PREVIEW_WIDTH, PREVIEW_HEIGHT);
49  }
50 
51  if(role == Qt::DisplayRole) {
52  switch (index.column()) {
53  case NAME:
54  return linePattern->name().c_str();
55 
56  case DESCRIPTION:
57  return linePattern->description().c_str();
58  }
59  }
60 
61  return QVariant();
62 }
#define PREVIEW_HEIGHT
#define PREVIEW_WIDTH
std::vector< lc::DxfLinePatternByValue_CSPtr > _linePatterns
Painting line patterns on a QPaintDevice.
QVariant LinePatternModel::headerData ( int  section,
Qt::Orientation  orientation,
int  role 
) const

Definition at line 64 of file linepatternmodel.cpp.

64  {
65  if (orientation == Qt::Horizontal) {
66  if(role == Qt::DisplayRole) {
67  switch(section) {
68  case PREVIEW:
69  return "Preview";
70 
71  case NAME:
72  return "Name";
73 
74  case DESCRIPTION:
75  return "Description";
76  }
77  }
78  }
79 
80  return QAbstractTableModel::headerData(section, orientation, role);
81 }
lc::DxfLinePattern_CSPtr LinePatternModel::linePatternAt ( const int  index) const

Return line pattern at specific row.

Parameters
indexRow
Returns
Shared pointer to DxfLinePattern

Definition at line 15 of file linepatternmodel.cpp.

15  {
16  return _linePatterns.at(index);
17 }
std::vector< lc::DxfLinePatternByValue_CSPtr > _linePatterns
int LinePatternModel::rowCount ( const QModelIndex &  parent = QModelIndex()) const

Definition at line 19 of file linepatternmodel.cpp.

19  {
20  return _linePatterns.size();
21 }
std::vector< lc::DxfLinePatternByValue_CSPtr > _linePatterns
void LinePatternModel::setLinePatterns ( std::vector< lc::DxfLinePatternByValue_CSPtr >  linePatterns)

Set the new list of line patterns.

Parameters
linePatternsNew list of DxfLinePatterns Update the list

Definition at line 7 of file linepatternmodel.cpp.

7  {
8  beginResetModel();
9 
10  _linePatterns = linePatterns;
11 
12  endResetModel();
13 }
std::vector< lc::DxfLinePatternByValue_CSPtr > _linePatterns

Member Data Documentation

std::vector<lc::DxfLinePatternByValue_CSPtr> LinePatternModel::_linePatterns
private

Definition at line 56 of file linepatternmodel.h.


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