Permalink
Browse files

Layer edition dialog

  • Loading branch information...
feragon committed Jul 22, 2016
1 parent bbdbb80 commit 14f2d111851968cbabb5b170369a938051425711
@@ -2,8 +2,13 @@
#include "ui_addlayerdialog.h"
AddLayerDialog::AddLayerDialog(std::vector<lc::DxfLinePattern_CSPtr> linePatterns, QWidget* parent) :
QDialog(parent),
ui(new Ui::AddLayerDialog){
AddLayerDialog(nullptr, linePatterns, parent) {
}
AddLayerDialog::AddLayerDialog(lc::Layer_CSPtr oldLayer, std::vector<lc::DxfLinePattern_CSPtr> linePatterns, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddLayerDialog),
_oldLayer(oldLayer) {
ui->setupUi(this);
@@ -13,6 +18,25 @@ AddLayerDialog::AddLayerDialog(std::vector<lc::DxfLinePattern_CSPtr> linePattern
if(layout) {
layout->setWidget(3, QFormLayout::FieldRole, linePatternSelect);
}
if(oldLayer != nullptr) {
ui->name->setText(oldLayer->name().c_str());
ui->r->setValue(oldLayer->color().redI());
ui->g->setValue(oldLayer->color().greenI());
ui->b->setValue(oldLayer->color().blueI());
ui->a->setValue(oldLayer->color().alphaI());
ui->width->setValue(oldLayer->lineWidth().width());
if(oldLayer->linePattern() != nullptr) {
int linePatternIndex = linePatternSelect->findText(oldLayer->linePattern()->name().c_str());
if (linePatternIndex != -1) {
linePatternSelect->setCurrentIndex(linePatternIndex);
}
}
}
}
AddLayerDialog::~AddLayerDialog() {
@@ -53,7 +77,12 @@ void AddLayerDialog::accept() {
);
}
emit newLayer(layer);
if(_oldLayer == nullptr) {
emit newLayer(layer);
}
else {
emit editLayer(_oldLayer, layer);
}
this->close();
}
@@ -19,10 +19,12 @@ class AddLayerDialog : public QDialog {
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();
signals:
void newLayer(lc::Layer_CSPtr);
void editLayer(lc::Layer_CSPtr oldLayer, lc::Layer_CSPtr newLayer);
private slots:
void accept();
@@ -32,4 +34,5 @@ class AddLayerDialog : public QDialog {
private:
Ui::AddLayerDialog* ui;
LinePatternSelect* linePatternSelect;
lc::Layer_CSPtr _oldLayer;
};
View
Binary file not shown.
View
@@ -24,5 +24,6 @@
<file alias="modifytrim.png">icons/modifytrim.png</file>
<file alias="locked.svg">icons/locked.svg</file>
<file alias="unlocked.svg">icons/unlocked.svg</file>
<file alias="layeredit">icons/layeredit.png</file>
</qresource>
</RCC>
@@ -3,6 +3,7 @@
LayerModel::LayerModel(QObject *parent) :
QAbstractTableModel(parent) {
_editIcon = QIcon(":/icons/layeredit");
_lockedIcon = QIcon(":/icons/locked.svg");
_unlockedIcon = QIcon(":/icons/unlocked.svg");
}
@@ -35,6 +36,9 @@ QVariant LayerModel::data(const QModelIndex& index, int role) const {
}
else if(role == Qt::DecorationRole) {
switch (index.column()) {
case EDIT:
return _editIcon;
case LOCKED:
if (layer->isFrozen()) {
return _lockedIcon;
@@ -50,10 +54,12 @@ Qt::ItemFlags LayerModel::flags(const QModelIndex& index) const {
if(index.column() == NAME) {
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
}
return Qt::ItemIsEnabled;
}
bool LayerModel::setData(const QModelIndex& index, const QVariant& value, int role) {
bool LayerModel::setData(const QModelIndex& index, const QVariant& value, int) {
if(!index.isValid()) {
return false;
}
@@ -11,6 +11,7 @@ class LayerModel : public QAbstractTableModel {
public:
enum columns {
NAME,
EDIT,
LOCKED,
LAST
};
@@ -34,6 +35,7 @@ class LayerModel : public QAbstractTableModel {
std::vector<lc::Layer_CSPtr> _layers;
lc::Layer_CSPtr _selectedLayer;
QIcon _editIcon;
QIcon _lockedIcon;
QIcon _unlockedIcon;
};
View
@@ -91,6 +91,13 @@ void Layers::on_layerList_clicked(const QModelIndex& index) {
case LayerModel::LOCKED:
locked = !locked;
break;
case LayerModel::EDIT:
auto dialog = new AddLayerDialog(layer, document->linePatterns(), this);
dialog->show();
connect(dialog, &AddLayerDialog::editLayer, this, &Layers::replaceLayer);
return;
}
auto newLayer = std::make_shared<const lc::Layer>(

0 comments on commit 14f2d11

Please sign in to comment.