LibreCAD
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
lc::ui::LinePatternSelect Class Reference

Dropdown select for DxfLinePatterns. More...

#include <linepatternselect.h>

Inheritance diagram for lc::ui::LinePatternSelect:
Collaboration diagram for lc::ui::LinePatternSelect:

Public Slots

void onLayerChanged (lc::Layer_CSPtr layer)
 Event when a new layer is selected. More...
 

Public Member Functions

 LinePatternSelect (lc::Document_SPtr document=nullptr, QWidget *parent=0, bool showByLayer=false, bool showByBlock=false)
 Create widget. More...
 
 LinePatternSelect (CadMdiChild *mdiChild=nullptr, QWidget *parent=0, bool showByLayer=false, bool showByBlock=false)
 Create widget (for drawing) More...
 
void setDocument (lc::Document_SPtr document=nullptr)
 Change document. More...
 
void setMdiChild (CadMdiChild *mdiChild=nullptr)
 Set the window on which line pattern is applied. More...
 
lc::DxfLinePattern_CSPtr linePattern ()
 Return selected line pattern. More...
 

Private Slots

void onActivated (const QString &text)
 

Private Member Functions

void createEntries ()
 
QIcon generateQIcon (lc::DxfLinePatternByValue_CSPtr linePattern)
 
void on_addLinePatternEvent (const lc::AddLinePatternEvent &)
 
void on_removeLinePatternEvent (const lc::RemoveLinePatternEvent &)
 
void on_replaceLinePatternEvent (const lc::ReplaceLinePatternEvent &)
 

Private Attributes

QSize qIconSize
 
bool _showByLayer
 
bool _showByBlock
 
lc::Document_SPtr _document
 
lc::ui::MetaInfoManager_SPtr _metaInfoManager
 

Detailed Description

Dropdown select for DxfLinePatterns.

Definition at line 23 of file linepatternselect.h.

Constructor & Destructor Documentation

LinePatternSelect::LinePatternSelect ( lc::Document_SPtr  document = nullptr,
QWidget *  parent = 0,
bool  showByLayer = false,
bool  showByBlock = false 
)

Create widget.

Parameters
documentDocument containing the line patterns
parentPointer to parent widget
showByLayerAdd "ByLayer" option
showByBlockAdd "ByBlock" option

Definition at line 6 of file linepatternselect.cpp.

6  :
7  QComboBox(parent),
8  _showByLayer(showByLayer),
9  _showByBlock(showByBlock) {
10 
11  qIconSize = QSize(128, 32);
12  setIconSize(qIconSize);
13 
14  setMaximumHeight(32);
15 
16  setDocument(document);
17 
18  connect(this, SIGNAL(activated(const QString&)), this, SLOT(onActivated(const QString&)));
19 }
void setDocument(lc::Document_SPtr document=nullptr)
Change document.
void onActivated(const QString &text)
LinePatternSelect::LinePatternSelect ( CadMdiChild mdiChild = nullptr,
QWidget *  parent = 0,
bool  showByLayer = false,
bool  showByBlock = false 
)

Create widget (for drawing)

Parameters
documentDocument containing the line patterns
parentPointer to parent widget
showByLayerAdd "ByLayer" option
showByBlockAdd "ByBlock" option

Definition at line 21 of file linepatternselect.cpp.

21  :
22  LinePatternSelect((lc::Document_SPtr) nullptr, parent, showByLayer, showByBlock) {
23 
24  setMdiChild(mdiChild);
25 }
void setMdiChild(CadMdiChild *mdiChild=nullptr)
Set the window on which line pattern is applied.
LinePatternSelect(lc::Document_SPtr document=nullptr, QWidget *parent=0, bool showByLayer=false, bool showByBlock=false)
Create widget.

Member Function Documentation

void LinePatternSelect::createEntries ( )
private

Definition at line 109 of file linepatternselect.cpp.

109  {
110  clear();
111 
112  if(_document != nullptr) {
113  addItem(NEW_LP);
114  addItem(MANAGE_LP);
115  insertSeparator(2);
116 
117  if(_showByLayer) {
118  addItem(BY_LAYER);
119  setCurrentText(BY_LAYER);
120  }
121  if(_showByBlock) {
122  addItem(BY_BLOCK);
123  }
124 
125  auto linePatterns = _document->linePatterns();
126  for (auto linePattern : linePatterns) {
127  auto lp = std::dynamic_pointer_cast<const lc::DxfLinePatternByValue>(linePattern);
128 
129  if(lp == nullptr) {
130  continue;
131  }
132 
133  auto icon = generateQIcon(lp);
134  addItem(icon, linePattern->name().c_str());
135  }
136  }
137 }
#define MANAGE_LP
#define BY_BLOCK
Definition: colorselect.h:12
#define BY_LAYER
Definition: colorselect.h:13
lc::Document_SPtr _document
QIcon generateQIcon(lc::DxfLinePatternByValue_CSPtr linePattern)
#define NEW_LP
lc::DxfLinePattern_CSPtr linePattern()
Return selected line pattern.
QIcon LinePatternSelect::generateQIcon ( lc::DxfLinePatternByValue_CSPtr  linePattern)
private

Definition at line 78 of file linepatternselect.cpp.

78  {
79  QPixmap pixmap(qIconSize);
80 
81  LinePatternPainter painter(&pixmap, linePattern);
82  painter.drawLinePattern();
83 
84  return QIcon(pixmap);
85 }
Painting line patterns on a QPaintDevice.
lc::DxfLinePattern_CSPtr linePattern()
Return selected line pattern.
lc::DxfLinePattern_CSPtr LinePatternSelect::linePattern ( )

Return selected line pattern.

Returns
Pointer to DxfLinePattern

Definition at line 56 of file linepatternselect.cpp.

56  {
57  if(currentText() == BY_LAYER) {
58  return nullptr;
59  }
60 
61  if(currentText() == BY_BLOCK) {
62  return std::make_shared<const lc::DxfLinePatternByBlock>();
63  }
64 
65  auto linePatterns = _document->linePatterns();
66  auto position = std::find_if(linePatterns.begin(), linePatterns.end(), [&](const lc::DxfLinePattern_CSPtr& item) {
67  return item->name() == currentText().toStdString();
68  });
69 
70  if(position != linePatterns.end()) {
71  return *position;
72  }
73  else {
74  return nullptr;
75  }
76 }
#define BY_BLOCK
Definition: colorselect.h:12
#define BY_LAYER
Definition: colorselect.h:13
lc::Document_SPtr _document
void LinePatternSelect::on_addLinePatternEvent ( const lc::AddLinePatternEvent &  event)
private

Definition at line 139 of file linepatternselect.cpp.

139  {
140  createEntries();
141 
142  setCurrentText(event.linePattern()->name().c_str());
143 }
void LinePatternSelect::on_removeLinePatternEvent ( const lc::RemoveLinePatternEvent &  event)
private

Definition at line 145 of file linepatternselect.cpp.

145  {
146  createEntries();
147 }
void LinePatternSelect::on_replaceLinePatternEvent ( const lc::ReplaceLinePatternEvent &  event)
private

Definition at line 149 of file linepatternselect.cpp.

149  {
150  createEntries();
151 
152  setCurrentText(event.newLinePattern()->name().c_str());
153 }
void LinePatternSelect::onActivated ( const QString &  text)
privateslot

Definition at line 87 of file linepatternselect.cpp.

87  {
88  if(text.toStdString() == NEW_LP) {
89  auto dialog = new AddLinePatternDialog(_document, this);
90  dialog->show();
91 
92  if(_showByLayer) {
93  setCurrentText(BY_LAYER);
94  }
95  }
96  else if(text == MANAGE_LP) {
97  auto dialog = new LinePatternManager(_document, this);
98  dialog->show();
99 
100  if(_showByLayer) {
101  setCurrentText(BY_LAYER);
102  }
103  }
104  else if(_metaInfoManager != nullptr) {
105  _metaInfoManager->setLinePattern(linePattern());
106  }
107 }
#define MANAGE_LP
#define BY_LAYER
Definition: colorselect.h:13
Create a new window which shows a list of line patterns.
Create a dialog with all required fields to create a new line pattern.
lc::Document_SPtr _document
lc::ui::MetaInfoManager_SPtr _metaInfoManager
#define NEW_LP
lc::DxfLinePattern_CSPtr linePattern()
Return selected line pattern.
void LinePatternSelect::onLayerChanged ( lc::Layer_CSPtr  layer)
slot

Event when a new layer is selected.

Parameters
layerNew selected layer This function update the "ByLayer" preview

Definition at line 155 of file linepatternselect.cpp.

155  {
156  auto index = findText(BY_LAYER);
157 
158  if(index != -1) {
159  auto icon = generateQIcon(layer->linePattern());
160  setItemIcon(index, icon);
161  }
162 }
#define BY_LAYER
Definition: colorselect.h:13
QIcon generateQIcon(lc::DxfLinePatternByValue_CSPtr linePattern)
void LinePatternSelect::setDocument ( lc::Document_SPtr  document = nullptr)

Change document.

Parameters
documentNew document

Definition at line 38 of file linepatternselect.cpp.

38  {
39  if(_document != nullptr) {
40  _document->addLinePatternEvent().disconnect<LinePatternSelect, &LinePatternSelect::on_addLinePatternEvent>(this);
41  _document->removeLinePatternEvent().disconnect<LinePatternSelect, &LinePatternSelect::on_removeLinePatternEvent>(this);
42  _document->replaceLinePatternEvent().disconnect<LinePatternSelect, &LinePatternSelect::on_replaceLinePatternEvent>(this);
43  }
44 
45  _document = document;
46 
47  if(_document != nullptr) {
48  _document->addLinePatternEvent().connect<LinePatternSelect, &LinePatternSelect::on_addLinePatternEvent>(this);
49  _document->removeLinePatternEvent().connect<LinePatternSelect, &LinePatternSelect::on_removeLinePatternEvent>(this);
50  _document->replaceLinePatternEvent().connect<LinePatternSelect, &LinePatternSelect::on_replaceLinePatternEvent>(this);
51  }
52 
53  createEntries();
54 }
void on_removeLinePatternEvent(const lc::RemoveLinePatternEvent &)
LinePatternSelect(lc::Document_SPtr document=nullptr, QWidget *parent=0, bool showByLayer=false, bool showByBlock=false)
Create widget.
void on_replaceLinePatternEvent(const lc::ReplaceLinePatternEvent &)
lc::Document_SPtr _document
void on_addLinePatternEvent(const lc::AddLinePatternEvent &)
void LinePatternSelect::setMdiChild ( CadMdiChild mdiChild = nullptr)

Set the window on which line pattern is applied.

Parameters
mdiChildor nullptr

Definition at line 27 of file linepatternselect.cpp.

27  {
28  if(mdiChild == nullptr) {
29  setDocument(nullptr);
30  }
31  else {
32  setDocument(mdiChild->document());
33 
34  _metaInfoManager = mdiChild->metaInfoManager();
35  }
36 }
lc::ui::MetaInfoManager_SPtr metaInfoManager() const
Get the MetaInfo manager.
void setDocument(lc::Document_SPtr document=nullptr)
Change document.
lc::ui::MetaInfoManager_SPtr _metaInfoManager
std::shared_ptr< lc::Document > document() const

Member Data Documentation

lc::Document_SPtr lc::ui::LinePatternSelect::_document
private

Definition at line 88 of file linepatternselect.h.

lc::ui::MetaInfoManager_SPtr lc::ui::LinePatternSelect::_metaInfoManager
private

Definition at line 89 of file linepatternselect.h.

bool lc::ui::LinePatternSelect::_showByBlock
private

Definition at line 86 of file linepatternselect.h.

bool lc::ui::LinePatternSelect::_showByLayer
private

Definition at line 85 of file linepatternselect.h.

QSize lc::ui::LinePatternSelect::qIconSize
private

Definition at line 83 of file linepatternselect.h.


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