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

Create a dialog with all required fields to create a new line pattern. More...

#include <addlinepatterndialog.h>

Inheritance diagram for AddLinePatternDialog:
Collaboration diagram for AddLinePatternDialog:

Public Member Functions

 AddLinePatternDialog (lc::Document_SPtr document, QWidget *parent=0)
 Create empty dialog. More...
 
 AddLinePatternDialog (lc::Document_SPtr document, lc::DxfLinePatternByValue_CSPtr linePattern, QWidget *parent=0)
 Create dialog pre-filled with existing line pattern information. More...
 

Protected Attributes

Ui::AddLinePatternDialog * ui
 
QPushButton * editButton
 
QVBoxLayout * _layout
 

Private Slots

void on_newValueButton_pressed ()
 Create a new entry for the pattern path. More...
 
void on_cancelButton_pressed ()
 Cancel Close the dialog. More...
 
void on_saveButton_pressed ()
 Save Save the line pattern in the document and close the dialog. More...
 
void onEditButtonPressed ()
 Edit Replace the original line pattern with the new one and close the dialog. More...
 
void generatePreview ()
 Generate line pattern preview Create a new QPixmap with a preview of the line pattern and add it in the dialog. More...
 

Private Attributes

lc::Document_SPtr _document
 
lc::DxfLinePatternByValue_CSPtr _linePattern
 
lc::DxfLinePatternByValue_CSPtr _oldLinePattern
 

Detailed Description

Create a dialog with all required fields to create a new line pattern.

Definition at line 27 of file addlinepatterndialog.h.

Constructor & Destructor Documentation

AddLinePatternDialog::AddLinePatternDialog ( lc::Document_SPtr  document,
QWidget *  parent = 0 
)

Create empty dialog.

Parameters
documentDocument which contains the DXFLinePatterns
parentParent widget

Definition at line 4 of file addlinepatterndialog.cpp.

4  :
5  AddLinePatternDialog(document, nullptr, parent) {
6 }
AddLinePatternDialog(lc::Document_SPtr document, QWidget *parent=0)
Create empty dialog.
AddLinePatternDialog::AddLinePatternDialog ( lc::Document_SPtr  document,
lc::DxfLinePatternByValue_CSPtr  linePattern,
QWidget *  parent = 0 
)

Create dialog pre-filled with existing line pattern information.

Parameters
documentDocument which contains the DXFLinePatterns.
linePatternLine pattern to edit
parentParent widget

Definition at line 8 of file addlinepatterndialog.cpp.

8  :
9  QDialog(parent),
10  ui(new Ui::AddLinePatternDialog),
11  _document(document),
12  _oldLinePattern(linePattern) {
13 
14  ui->setupUi(this);
15 
16  _layout = static_cast<QVBoxLayout*>(ui->pathList->layout());
17  if(!_layout) {
18  throw "Unable to cast AddLinePatternDialog pathList layout to QVBoxLayout";
19  }
20 
21  if(linePattern != nullptr) {
22  ui->name->setText(linePattern->name().c_str());
23  ui->description->setText(linePattern->description().c_str());
24 
25  for (auto value : linePattern->path()) {
26  auto pathPart = new LinePatternPathPart(value, this);
28 
29  _layout->insertWidget(_layout->count() - 1, pathPart);
30  }
31 
32  ui->saveButton->setText(SAVE_AS_NEW_TEXT);
33 
34  editButton = new QPushButton(EDIT_TEXT);
35  connect(editButton, &QPushButton::pressed, this, &AddLinePatternDialog::onEditButtonPressed);
36  ui->buttonLayout->addWidget(editButton);
37  }
38 }
Model used to construct line pattern path.
void onEditButtonPressed()
Edit Replace the original line pattern with the new one and close the dialog.
#define EDIT_TEXT
void generatePreview()
Generate line pattern preview Create a new QPixmap with a preview of the line pattern and add it in t...
#define SAVE_AS_NEW_TEXT
lc::DxfLinePatternByValue_CSPtr _oldLinePattern
lc::Document_SPtr _document
Ui::AddLinePatternDialog * ui

Member Function Documentation

void AddLinePatternDialog::generatePreview ( )
privateslot

Generate line pattern preview Create a new QPixmap with a preview of the line pattern and add it in the dialog.

Definition at line 40 of file addlinepatterndialog.cpp.

40  {
41  std::string name = ui->name->text().toStdString();
42  if(name.empty()) {
43  name = "tmp";
44  }
45 
46  std::vector<double> path;
47  double length = 0.0;
48 
49  auto parts = findChildren<LinePatternPathPart*>();
50 
51  for(auto part : parts) {
52  auto type = part->type();
53  auto value = part->value();
54 
55  switch(type) {
57  path.push_back(0);
58  break;
59 
61  path.push_back(value);
62  length += value;
63  break;
64 
66  path.push_back(-value);
67  length += value;
68  break;
69  }
70  }
71 
72  _linePattern = std::make_shared<lc::DxfLinePatternByValue>(
73  name,
74  ui->description->text().toStdString(),
75  path,
76  length);
77 
78  QPixmap previewPixmap(ui->preview->frameSize());
79 
80  LinePatternPainter painter(&previewPixmap, _linePattern);
81  painter.drawLinePattern();
82 
83  ui->preview->setPixmap(previewPixmap);
84 }
lc::DxfLinePatternByValue_CSPtr _linePattern
Painting line patterns on a QPaintDevice.
Ui::AddLinePatternDialog * ui
void AddLinePatternDialog::on_cancelButton_pressed ( )
privateslot

Cancel Close the dialog.

Definition at line 94 of file addlinepatterndialog.cpp.

94  {
95  this->close();
96 }
void AddLinePatternDialog::on_newValueButton_pressed ( )
privateslot

Create a new entry for the pattern path.

Definition at line 87 of file addlinepatterndialog.cpp.

87  {
88  auto pathPart = new LinePatternPathPart(this);
90 
91  _layout->insertWidget(_layout->count() - 1, pathPart);
92 }
Model used to construct line pattern path.
void generatePreview()
Generate line pattern preview Create a new QPixmap with a preview of the line pattern and add it in t...
void AddLinePatternDialog::on_saveButton_pressed ( )
privateslot

Save Save the line pattern in the document and close the dialog.

Definition at line 98 of file addlinepatterndialog.cpp.

98  {
99  auto operation = std::make_shared<lc::operation::AddLinePattern>(_document, _linePattern);
100  operation->execute();
101 
102  this->close();
103 }
lc::DxfLinePatternByValue_CSPtr _linePattern
lc::Document_SPtr _document
void AddLinePatternDialog::onEditButtonPressed ( )
privateslot

Edit Replace the original line pattern with the new one and close the dialog.

Definition at line 105 of file addlinepatterndialog.cpp.

105  {
106  auto operation = std::make_shared<lc::operation::ReplaceLinePattern>(_document, _oldLinePattern, _linePattern);
107  operation->execute();
108 
109  this->close();
110 }
lc::DxfLinePatternByValue_CSPtr _linePattern
lc::DxfLinePatternByValue_CSPtr _oldLinePattern
lc::Document_SPtr _document

Member Data Documentation

lc::Document_SPtr AddLinePatternDialog::_document
private

Definition at line 82 of file addlinepatterndialog.h.

QVBoxLayout* AddLinePatternDialog::_layout
protected

Definition at line 79 of file addlinepatterndialog.h.

lc::DxfLinePatternByValue_CSPtr AddLinePatternDialog::_linePattern
private

Definition at line 84 of file addlinepatterndialog.h.

lc::DxfLinePatternByValue_CSPtr AddLinePatternDialog::_oldLinePattern
private

Definition at line 85 of file addlinepatterndialog.h.

QPushButton* AddLinePatternDialog::editButton
protected

Definition at line 78 of file addlinepatterndialog.h.

Ui::AddLinePatternDialog* AddLinePatternDialog::ui
protected

Definition at line 77 of file addlinepatterndialog.h.


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