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

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

#include <addlayerdialog.h>

Inheritance diagram for AddLayerDialog:
Collaboration diagram for AddLayerDialog:

Signals

void newLayer (lc::Layer_CSPtr)
 
void editLayer (lc::Layer_CSPtr oldLayer, lc::Layer_CSPtr newLayer)
 

Public Member Functions

 AddLayerDialog (lc::Document_SPtr document, QWidget *parent=0)
 Create empty dialog. More...
 
 AddLayerDialog (lc::Layer_CSPtr oldLayer, lc::Document_SPtr document, QWidget *parent=0)
 Create dialog pre-filled with existing Layer information. More...
 
 ~AddLayerDialog ()
 

Protected Attributes

Ui::AddLayerDialog * ui
 
lc::ui::LinePatternSelectlinePatternSelect
 
lc::ui::LineWidthSelectlineWidthSelect
 
lc::ui::ColorSelectcolorSelect
 

Private Slots

void accept ()
 Create layer This function is called when "Ok" button is pressed. It creates the layer according to the entered information and send it back to Layers widget. More...
 

Private Attributes

lc::Layer_CSPtr _oldLayer
 

Detailed Description

Create a dialog with all required fields to create a new layer.

Definition at line 22 of file addlayerdialog.h.

Constructor & Destructor Documentation

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

Create empty dialog.

Parameters
documentDocument which contains the DXFLinePatterns
parentParent widget

Definition at line 5 of file addlayerdialog.cpp.

5  :
6  AddLayerDialog(nullptr, document, parent) {
7 }
AddLayerDialog(lc::Document_SPtr document, QWidget *parent=0)
Create empty dialog.
AddLayerDialog::AddLayerDialog ( lc::Layer_CSPtr  oldLayer,
lc::Document_SPtr  document,
QWidget *  parent = 0 
)

Create dialog pre-filled with existing Layer information.

Parameters
oldLayerLayer to edit
documentDocument which contains the DXFLinePatterns
parentParent widget

Definition at line 9 of file addlayerdialog.cpp.

9  :
10  QDialog(parent),
11  ui(new Ui::AddLayerDialog),
12  _oldLayer(oldLayer) {
13 
14  ui->setupUi(this);
15 
16  linePatternSelect = new lc::ui::LinePatternSelect(document, this, false, false);
17  lineWidthSelect = new lc::ui::LineWidthSelect(nullptr, this, false, false);
18  colorSelect = new lc::ui::ColorSelect(nullptr, this, false, false);
19 
20  auto layout = dynamic_cast<QFormLayout*>(this->layout());
21  if(layout) {
22  layout->setWidget(1, QFormLayout::FieldRole, colorSelect);
23  layout->setWidget(2, QFormLayout::FieldRole, lineWidthSelect);
24  layout->setWidget(3, QFormLayout::FieldRole, linePatternSelect);
25  }
26 
27  if(oldLayer != nullptr) {
28  ui->name->setText(oldLayer->name().c_str());
29  if(oldLayer->linePattern() != nullptr) {
30  linePatternSelect->setCurrentText(oldLayer->linePattern()->name().c_str());
31  }
32  lineWidthSelect->setWidth(std::make_shared<lc::MetaLineWidthByValue>(oldLayer->lineWidth()));
33  colorSelect->setColor(oldLayer->color());
34 
35  if(oldLayer->linePattern() != nullptr) {
36  int linePatternIndex = linePatternSelect->findText(oldLayer->linePattern()->name().c_str());
37 
38  if (linePatternIndex != -1) {
39  linePatternSelect->setCurrentIndex(linePatternIndex);
40  }
41  }
42  }
43 }
lc::ui::ColorSelect * colorSelect
Dropdown select for line widths. Line widths are hardcoded in the constructor.
lc::Layer_CSPtr _oldLayer
void setWidth(lc::MetaLineWidth_CSPtr lineWidth)
Select a new width.
Ui::AddLayerDialog * ui
void setColor(lc::Color color)
Set selected color.
Definition: colorselect.cpp:78
Dropdown select for DxfLinePatterns.
lc::ui::LinePatternSelect * linePatternSelect
lc::ui::LineWidthSelect * lineWidthSelect
AddLayerDialog::~AddLayerDialog ( )

Definition at line 45 of file addlayerdialog.cpp.

45  {
46  delete ui;
47 }
Ui::AddLayerDialog * ui

Member Function Documentation

void AddLayerDialog::accept ( )
privateslot

Create layer This function is called when "Ok" button is pressed. It creates the layer according to the entered information and send it back to Layers widget.

Definition at line 49 of file addlayerdialog.cpp.

49  {
50  if(ui->name->text().isEmpty()) {
51  QToolTip::showText(ui->name->mapToGlobal(QPoint()), tr("Name cannot be empty."));
52  return;
53  }
54 
55  auto linePattern = std::dynamic_pointer_cast<const lc::DxfLinePatternByValue>(linePatternSelect->linePattern());
56  lc::Layer_CSPtr layer;
57 
58  auto lineWidth = std::dynamic_pointer_cast<const lc::MetaLineWidthByValue>(lineWidthSelect->lineWidth());
59  if(lineWidth == nullptr) {
60  return;
61  }
62 
63  if(linePattern == nullptr) {
64  layer = std::make_shared<const lc::Layer>(
65  ui->name->text().toStdString(),
66  *lineWidth,
68  );
69  }
70  else {
71  layer = std::make_shared<const lc::Layer>(
72  ui->name->text().toStdString(),
73  *lineWidth,
74  colorSelect->color(),
75  linePattern,
76  false
77  );
78  }
79 
80  if(_oldLayer == nullptr) {
81  emit newLayer(layer);
82  }
83  else {
84  emit editLayer(_oldLayer, layer);
85  }
86 
87  this->close();
88 }
lc::ui::ColorSelect * colorSelect
void editLayer(lc::Layer_CSPtr oldLayer, lc::Layer_CSPtr newLayer)
lc::Color color()
Returns selected color.
lc::MetaLineWidth_CSPtr lineWidth()
Return selected line width.
lc::Layer_CSPtr _oldLayer
Ui::AddLayerDialog * ui
lc::DxfLinePattern_CSPtr linePattern()
Return selected line pattern.
lc::ui::LinePatternSelect * linePatternSelect
lc::ui::LineWidthSelect * lineWidthSelect
void newLayer(lc::Layer_CSPtr)
void AddLayerDialog::editLayer ( lc::Layer_CSPtr  oldLayer,
lc::Layer_CSPtr  newLayer 
)
signal
void AddLayerDialog::newLayer ( lc::Layer_CSPtr  )
signal

Member Data Documentation

lc::Layer_CSPtr AddLayerDialog::_oldLayer
private

Definition at line 61 of file addlayerdialog.h.

lc::ui::ColorSelect* AddLayerDialog::colorSelect
protected

Definition at line 58 of file addlayerdialog.h.

lc::ui::LinePatternSelect* AddLayerDialog::linePatternSelect
protected

Definition at line 56 of file addlayerdialog.h.

lc::ui::LineWidthSelect* AddLayerDialog::lineWidthSelect
protected

Definition at line 57 of file addlayerdialog.h.

Ui::AddLayerDialog* AddLayerDialog::ui
protected

Definition at line 55 of file addlayerdialog.h.


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