Permalink
Browse files

Allow creation of new line patterns

  • Loading branch information...
feragon committed Jul 25, 2016
1 parent 14f2d11 commit 01a6d96bbaa30e6edff2a632eba2cd00a35ee3f9
@@ -1,18 +1,19 @@
#include "addlayerdialog.h"
#include "ui_addlayerdialog.h"
AddLayerDialog::AddLayerDialog(std::vector<lc::DxfLinePattern_CSPtr> linePatterns, QWidget* parent) :
AddLayerDialog(nullptr, linePatterns, parent) {
AddLayerDialog::AddLayerDialog(lc::Document_SPtr document, QWidget* parent) :
AddLayerDialog(nullptr, document, parent) {
}
AddLayerDialog::AddLayerDialog(lc::Layer_CSPtr oldLayer, std::vector<lc::DxfLinePattern_CSPtr> linePatterns, QWidget *parent) :
AddLayerDialog::AddLayerDialog(lc::Layer_CSPtr oldLayer, lc::Document_SPtr document, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddLayerDialog),
_document(document),
_oldLayer(oldLayer) {
ui->setupUi(this);
linePatternSelect = new LinePatternSelect(linePatterns, nullptr);
linePatternSelect = new LinePatternSelect(document, nullptr);
auto layout = dynamic_cast<QFormLayout*>(this->layout());
if(layout) {
@@ -9,6 +9,7 @@
#include <cad/meta/layer.h>
#include <cad/meta/metalinewidth.h>
#include <cad/document/document.h>
namespace Ui {
class AddLayerDialog;
@@ -18,8 +19,8 @@ class AddLayerDialog : public QDialog {
Q_OBJECT
public:
AddLayerDialog(std::vector<lc::DxfLinePattern_CSPtr> linePatterns, QWidget* parent = 0);
AddLayerDialog(lc::Layer_CSPtr oldLayer, std::vector<lc::DxfLinePattern_CSPtr> linePatterns, QWidget* parent = 0);
AddLayerDialog(lc::Document_SPtr document, QWidget* parent = 0);
AddLayerDialog(lc::Layer_CSPtr oldLayer, lc::Document_SPtr document, QWidget* parent = 0);
~AddLayerDialog();
signals:
@@ -33,6 +34,7 @@ class AddLayerDialog : public QDialog {
private:
Ui::AddLayerDialog* ui;
lc::Document_SPtr _document;
LinePatternSelect* linePatternSelect;
lc::Layer_CSPtr _oldLayer;
};
@@ -1,14 +1,15 @@
#include "addlinepatterndialog.h"
#include "ui_addlinepatterndialog.h"
AddLinePatternDialog::AddLinePatternDialog(QWidget *parent) :
AddLinePatternDialog(nullptr, parent) {
AddLinePatternDialog::AddLinePatternDialog(lc::Document_SPtr document, QWidget *parent) :
AddLinePatternDialog(document, nullptr, parent) {
}
AddLinePatternDialog::AddLinePatternDialog(lc::DxfLinePattern_CSPtr linePattern, QWidget *parent) :
AddLinePatternDialog::AddLinePatternDialog(lc::Document_SPtr document, lc::DxfLinePattern_CSPtr linePattern, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddLinePatternDialog),
_linePattern(linePattern) {
_document(document),
_oldLinePattern(linePattern) {
ui->setupUi(this);
@@ -17,8 +18,6 @@ AddLinePatternDialog::AddLinePatternDialog(lc::DxfLinePattern_CSPtr linePattern,
throw "Unable to cast AddLinePatternDialog pathList layout to QVBoxLayout";
}
connect(ui->newValueButton, &QPushButton::pressed, this, &AddLinePatternDialog::onNewValuePressed);
if(linePattern != nullptr) {
ui->name->setText(linePattern->name().c_str());
ui->description->setText(linePattern->description().c_str());
@@ -29,6 +28,12 @@ AddLinePatternDialog::AddLinePatternDialog(lc::DxfLinePattern_CSPtr linePattern,
_layout->insertWidget(_layout->count() - 1, pathPart);
}
ui->saveButton->setText(SAVE_AS_NEW_TEXT);
auto editButton = new QPushButton(EDIT_TEXT);
connect(editButton, &QPushButton::pressed, this, &AddLinePatternDialog::onEditButtonPressed);
ui->buttonLayout->addWidget(editButton);
}
}
@@ -79,13 +84,27 @@ void AddLinePatternDialog::generatePreview() {
}
void AddLinePatternDialog::onNewValuePressed() {
void AddLinePatternDialog::on_newValueButton_pressed() {
auto pathPart = new LinePatternPathPart(this);
connect(pathPart, &LinePatternPathPart::update, this, &AddLinePatternDialog::generatePreview);
_layout->insertWidget(_layout->count() - 1, pathPart);
}
lc::DxfLinePattern_CSPtr AddLinePatternDialog::linePattern() {
return _linePattern;
}
void AddLinePatternDialog::on_cancelButton_pressed() {
this->close();
}
void AddLinePatternDialog::on_saveButton_pressed() {
auto operation = std::make_shared<lc::operation::AddLinePattern>(_document, _linePattern);
operation->execute();
this->close();
}
void AddLinePatternDialog::onEditButtonPressed() {
auto operation = std::make_shared<lc::operation::ReplaceLinePattern>(_document, _oldLinePattern, _linePattern);
operation->execute();
this->close();
}
@@ -9,10 +9,15 @@
#include <QPushButton>
#include <cad/meta/dxflinepattern.h>
#include <cad/operations/linepatternops.h>
#include <cad/document/document.h>
#include "widgets/linepatternpathpart.h"
#include "widgets/linepatternpainter.h"
#define SAVE_AS_NEW_TEXT "Save as new"
#define EDIT_TEXT "Edit"
namespace Ui {
class AddLinePatternDialog;
}
@@ -21,18 +26,23 @@ class AddLinePatternDialog : public QDialog {
Q_OBJECT
public:
AddLinePatternDialog(QWidget* parent = 0);
AddLinePatternDialog(lc::DxfLinePattern_CSPtr linePattern, QWidget* parent = 0);
lc::DxfLinePattern_CSPtr linePattern();
AddLinePatternDialog(lc::Document_SPtr document, QWidget* parent = 0);
AddLinePatternDialog(lc::Document_SPtr document, lc::DxfLinePattern_CSPtr linePattern, QWidget* parent = 0);
private slots:
void onNewValuePressed();
void on_newValueButton_pressed();
void on_cancelButton_pressed();
void on_saveButton_pressed();
void onEditButtonPressed();
void generatePreview();
private:
Ui::AddLinePatternDialog* ui;
QVBoxLayout* _layout;
lc::Document_SPtr _document;
lc::DxfLinePattern_CSPtr _linePattern;
lc::DxfLinePattern_CSPtr _oldLinePattern;
};
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>445</width>
<height>344</height>
<width>721</width>
<height>492</height>
</rect>
</property>
<property name="sizePolicy">
@@ -27,6 +27,19 @@
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="preview">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
@@ -47,19 +60,6 @@
<item row="2" column="1">
<widget class="QLineEdit" name="description"/>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="newValueButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>New value</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="pathLabel">
<property name="sizePolicy">
@@ -89,8 +89,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>344</width>
<height>156</height>
<width>620</width>
<height>324</height>
</rect>
</property>
<property name="sizePolicy">
@@ -118,66 +118,38 @@
</widget>
</item>
<item row="6" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>false</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="preview">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
<layout class="QHBoxLayout" name="buttonLayout">
<item>
<widget class="QPushButton" name="newValueButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>New value</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AddLinePatternDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AddLinePatternDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>
View
@@ -43,7 +43,7 @@ lc::Layer_CSPtr Layers::activeLayer() {
}
void Layers::on_newButton_clicked() {
auto dialog = new AddLayerDialog(document->linePatterns(), this);
auto dialog = new AddLayerDialog(document, this);
dialog->show();
connect(dialog, &AddLayerDialog::newLayer, this, &Layers::createLayer);
@@ -93,7 +93,7 @@ void Layers::on_layerList_clicked(const QModelIndex& index) {
break;
case LayerModel::EDIT:
auto dialog = new AddLayerDialog(layer, document->linePatterns(), this);
auto dialog = new AddLayerDialog(layer, document, this);
dialog->show();
connect(dialog, &AddLayerDialog::editLayer, this, &Layers::replaceLayer);
@@ -112,10 +112,6 @@ void Layers::on_layerList_clicked(const QModelIndex& index) {
}
}
void Layers::onSelectionChanged(const QItemSelection& selection, const QItemSelection&) {
}
void Layers::changeLayerName(lc::Layer_CSPtr& layer, const std::string& name) {
if(name.empty()) {
return;
View
@@ -28,7 +28,6 @@ class Layers : public QDockWidget {
void on_newButton_clicked();
void on_deleteButton_clicked();
void on_layerList_clicked(const QModelIndex& index);
void onSelectionChanged(const QItemSelection& selected, const QItemSelection&);
void onSubwindowActivated(QMdiSubWindow *window);
void createLayer(lc::Layer_CSPtr layer);
@@ -19,6 +19,11 @@ void LinePatternPainter::drawLinePattern() {
dashes << a;
}
//Qt always want a space at end
if(dashes.size() % 2 != 0) {
dashes << 0;
}
pen.setDashPattern(dashes);
}
Oops, something went wrong.

0 comments on commit 01a6d96

Please sign in to comment.