From 9c6d3626377b866799a36400237171b74fb7b86b Mon Sep 17 00:00:00 2001 From: blacksun Date: Sun, 21 Jun 2015 20:16:41 +0000 Subject: [PATCH] QetShapeItem can be edited via the properties editor dock git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4024 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- dev_doc/ID_of_QUndoCommand.txt | 1 + sources/qetgraphicsitem/qetshapeitem.cpp | 74 +------ sources/qetgraphicsitem/qetshapeitem.h | 77 ++++---- .../ui/diagrampropertieseditordockwidget.cpp | 14 ++ .../ui/shapegraphicsitempropertieswidget.cpp | 181 ++++++++++++++++++ .../ui/shapegraphicsitempropertieswidget.h | 64 +++++++ .../ui/shapegraphicsitempropertieswidget.ui | 147 ++++++++++++++ .../undocommand/changeshapestylecommand.cpp | 74 +++++++ sources/undocommand/changeshapestylecommand.h | 44 +++++ sources/undocommand/itemresizercommand.cpp | 4 +- sources/undocommand/itemresizercommand.h | 2 +- 11 files changed, 575 insertions(+), 107 deletions(-) create mode 100644 sources/ui/shapegraphicsitempropertieswidget.cpp create mode 100644 sources/ui/shapegraphicsitempropertieswidget.h create mode 100644 sources/ui/shapegraphicsitempropertieswidget.ui create mode 100644 sources/undocommand/changeshapestylecommand.cpp create mode 100644 sources/undocommand/changeshapestylecommand.h diff --git a/dev_doc/ID_of_QUndoCommand.txt b/dev_doc/ID_of_QUndoCommand.txt index d89ee1d32..572defc9f 100755 --- a/dev_doc/ID_of_QUndoCommand.txt +++ b/dev_doc/ID_of_QUndoCommand.txt @@ -1,3 +1,4 @@ ChangeElementInformationCommand = 1 LinkElementCommand = 2 ItemResizerCommand = 3 +ChangeShapeStyleCommand = 4 diff --git a/sources/qetgraphicsitem/qetshapeitem.cpp b/sources/qetgraphicsitem/qetshapeitem.cpp index 274425bef..d5d4f5e5f 100644 --- a/sources/qetgraphicsitem/qetshapeitem.cpp +++ b/sources/qetgraphicsitem/qetshapeitem.cpp @@ -16,11 +16,10 @@ along with QElectroTech. If not, see . */ #include "qetshapeitem.h" -#include "itemresizercommand.h" -#include "diagramcommands.h" #include "createdxf.h" #include "diagram.h" #include "qet.h" +#include "shapegraphicsitempropertieswidget.h" /** @@ -57,6 +56,7 @@ void QetShapeItem::setStyle(Qt::PenStyle newStyle) { m_shapeStyle = newStyle; update(); + emit styleChanged(); } /** @@ -303,7 +303,6 @@ QDomElement QetShapeItem::toXml(QDomDocument &document) const { result.setAttribute("type", QString::number(m_shapeType)); result.setAttribute("style", QString::number(m_shapeStyle)); result.setAttribute("is_movable", bool(is_movable_)); - if (m_shapeType != Polyline) { result.setAttribute("x1", mapToScene(m_P1).x()); result.setAttribute("y1", mapToScene(m_P1).y()); @@ -365,55 +364,8 @@ void QetShapeItem::editProperty() property_dialog.setWindowTitle(tr("Éditer les propriétés d'une shape, Zone ", "window title")); //the main layout QVBoxLayout dialog_layout(&property_dialog); - - //GroupBox for resizer image - QGroupBox restyle_groupe(QObject::tr("Type de trait", "shape style")); - dialog_layout.addWidget(&restyle_groupe); - QHBoxLayout restyle_layout(&restyle_groupe); - - QComboBox style_combo(&property_dialog); - style_combo.addItem(QObject::tr("Normal")); - style_combo.addItem(QObject::tr("Tiret")); - style_combo.addItem(QObject::tr("Pointillé")); - style_combo.addItem(QObject::tr("Traits et points")); - style_combo.addItem(QObject::tr("Traits points points")); - - // The items have been added in order accordance with Qt::PenStyle. - style_combo.setCurrentIndex(int(m_shapeStyle) - 1); - - restyle_layout.addWidget(&style_combo); - - //check box for disable move - QCheckBox cb(tr("Verrouiller la position"), &property_dialog); - cb.setChecked(!is_movable_); - dialog_layout.addWidget(&cb); - - //GroupBox for Scaling - QGroupBox scale_groupe(QObject::tr("Échelle", "shape scale")); - dialog_layout.addWidget(&scale_groupe); - QHBoxLayout scale_layout(&scale_groupe); - - int min_range = 1; - int max_range = 200; - int factor_range = 100; - - //slider - QSlider slider(Qt::Horizontal, &property_dialog); - slider.setRange(min_range, max_range); - qreal scale_= scale(); - slider.setValue(scale_*factor_range); - //spinbox - QSpinBox spin_box(&property_dialog); - spin_box.setRange(min_range, max_range); - spin_box.setValue(scale_*factor_range); - spin_box.setSuffix(" %"); - //synchro slider with spinbox - connect(&slider, SIGNAL(valueChanged(int)), &spin_box, SLOT(setValue(int))); - connect(&slider, SIGNAL(valueChanged(int)), this, SLOT(previewScale(int))); - connect(&spin_box, SIGNAL(valueChanged(int)), &slider, SLOT(setValue(int))); - //add slider and spinbox to layout - scale_layout.addWidget(&slider); - scale_layout.addWidget(&spin_box); + ShapeGraphicsItemPropertiesWidget *sgipw = new ShapeGraphicsItemPropertiesWidget(this, &property_dialog); + dialog_layout.addWidget(sgipw); //dialog button, box QDialogButtonBox dbb(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); @@ -421,20 +373,10 @@ void QetShapeItem::editProperty() connect(&dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept())); connect(&dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject())); - //dialog is accepted... - if (property_dialog.exec() == QDialog::Accepted) { - cb.isChecked() ? is_movable_=false : is_movable_=true; - - Qt::PenStyle new_style = Qt::PenStyle(style_combo.currentIndex() + 1); - if (new_style != m_shapeStyle) diagram()->undoStack().push(new ChangeShapeStyleCommand(this, m_shapeStyle, new_style)); - - qreal scale_factor = slider.value(); - scale_factor /= factor_range; - if (scale_ != scale_factor) diagram()->undoStack().push(new ItemResizerCommand(this, scale_, scale_factor, tr("une shape"))); - return; - } - //...or not - setScale(scale_); + if (property_dialog.exec() == QDialog::Accepted) + sgipw->apply(); + else + sgipw->reset(); } /** diff --git a/sources/qetgraphicsitem/qetshapeitem.h b/sources/qetgraphicsitem/qetshapeitem.h index db0f3d8b4..c00224349 100644 --- a/sources/qetgraphicsitem/qetshapeitem.h +++ b/sources/qetgraphicsitem/qetshapeitem.h @@ -32,61 +32,62 @@ class QetShapeItem : public QetGraphicsItem { Q_OBJECT + signals: + void styleChanged(); + public: - Q_ENUMS(ShapeType) - enum ShapeType {Line =0, - Rectangle =1, - Ellipse =2, - Polyline =3 }; + Q_ENUMS(ShapeType) + enum ShapeType {Line =0, + Rectangle =1, + Ellipse =2, + Polyline =3 }; - enum { Type = UserType + 1008 }; + enum { Type = UserType + 1008 }; - QetShapeItem(QPointF, QPointF = QPointF(0,0), ShapeType = Line, QGraphicsItem *parent = 0); - virtual ~QetShapeItem(); + QetShapeItem(QPointF, QPointF = QPointF(0,0), ShapeType = Line, QGraphicsItem *parent = 0); + virtual ~QetShapeItem(); - /** - Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a QetShapeItem - @return the QGraphicsItem type - */ - virtual int type() const { return Type; } + //Enable the use of qgraphicsitem_cast to safely cast a QGraphicsItem into a QetShapeItem @return the QGraphicsItem type + virtual int type() const { return Type; } - ///METHODS - void setStyle(Qt::PenStyle); + ///METHODS + void setStyle(Qt::PenStyle); + Qt::PenStyle penStyle() const { return m_shapeStyle;} - virtual bool fromXml (const QDomElement &); - virtual QDomElement toXml (QDomDocument &document) const; - virtual bool toDXF (const QString &filepath); + virtual bool fromXml (const QDomElement &); + virtual QDomElement toXml (QDomDocument &document) const; + virtual bool toDXF (const QString &filepath); - virtual void editProperty(); - virtual QString name() const; + virtual void editProperty(); + virtual QString name() const; - void setP2 (QPointF P2); + void setP2 (QPointF P2); - //Methods available for polygon shape - int pointsCount () const; - void setNextPoint (QPointF P); - void removePoints (int number = 1); + //Methods available for polygon shape + int pointsCount () const; + void setNextPoint (QPointF P); + void removePoints (int number = 1); - QRectF boundingRect() const; - QPainterPath shape() const; + QRectF boundingRect() const; + QPainterPath shape() const; protected: - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event); - virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event); + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); + virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event); + virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event); private: - void changeGraphicsItem (const ShapeType &newtype); + void changeGraphicsItem (const ShapeType &newtype); private slots: - void previewScale(int factor); + void previewScale(int factor); - ///ATTRIBUTES + ///ATTRIBUTES private: - ShapeType m_shapeType; - Qt::PenStyle m_shapeStyle; - QPointF m_P1, m_P2; - QPolygonF m_polygon; - bool m_hovered; + ShapeType m_shapeType; + Qt::PenStyle m_shapeStyle; + QPointF m_P1, m_P2; + QPolygonF m_polygon; + bool m_hovered; }; #endif // QETSHAPEITEM_H diff --git a/sources/ui/diagrampropertieseditordockwidget.cpp b/sources/ui/diagrampropertieseditordockwidget.cpp index 8f3bd2a63..8b95df62b 100644 --- a/sources/ui/diagrampropertieseditordockwidget.cpp +++ b/sources/ui/diagrampropertieseditordockwidget.cpp @@ -21,6 +21,8 @@ #include "element.h" #include "diagramimageitem.h" #include "imagepropertieswidget.h" +#include "qetshapeitem.h" +#include "shapegraphicsitempropertieswidget.h" /** * @brief DiagramPropertiesEditorDockWidget::DiagramPropertiesEditorDockWidget @@ -108,6 +110,18 @@ void DiagramPropertiesEditorDockWidget::selectionChanged() addEditor(new ImagePropertiesWidget(static_cast(item), this)); break; } + case QetShapeItem::Type: { + if (m_edited_qgi_type == type_) + { + static_cast(editors().first())->setItem(static_cast(item)); + return; + } + + clear(); + m_edited_qgi_type = type_; + addEditor(new ShapeGraphicsItemPropertiesWidget(static_cast(item), this)); + break; } + default: m_edited_qgi_type = -1; clear(); diff --git a/sources/ui/shapegraphicsitempropertieswidget.cpp b/sources/ui/shapegraphicsitempropertieswidget.cpp new file mode 100644 index 000000000..2150842cf --- /dev/null +++ b/sources/ui/shapegraphicsitempropertieswidget.cpp @@ -0,0 +1,181 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "shapegraphicsitempropertieswidget.h" +#include "ui_shapegraphicsitempropertieswidget.h" +#include "qetshapeitem.h" +#include "diagram.h" +#include "itemresizercommand.h" +#include "changeshapestylecommand.h" + +/** + * @brief ShapeGraphicsItemPropertiesWidget::ShapeGraphicsItemPropertiesWidget + * Constructor + * @param item : shape to edit + * @param parent : parent widget + */ +ShapeGraphicsItemPropertiesWidget::ShapeGraphicsItemPropertiesWidget(QetShapeItem *item, QWidget *parent) : + PropertiesEditorWidget(parent), + ui(new Ui::ShapeGraphicsItemPropertiesWidget), + m_shape(nullptr) +{ + ui->setupUi(this); + setItem(item); +} + +/** + * @brief ShapeGraphicsItemPropertiesWidget::~ShapeGraphicsItemPropertiesWidget + * Destructor + */ +ShapeGraphicsItemPropertiesWidget::~ShapeGraphicsItemPropertiesWidget() +{ + delete ui; +} + +/** + * @brief ShapeGraphicsItemPropertiesWidget::setItem + * Set @shape as the current edited item + * @param shape + */ +void ShapeGraphicsItemPropertiesWidget::setItem(QetShapeItem *shape) +{ + if (!shape) return; + if (shape == m_shape) return; + + if (m_shape) + { + disconnect(m_shape, &QGraphicsObject::scaleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi); + disconnect(m_shape, &QetShapeItem::styleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi); + } + + m_shape = shape; + connect(m_shape, &QGraphicsObject::scaleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi); + connect(m_shape, &QetShapeItem::styleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi); + + m_old_pen_style = m_shape->penStyle(); + m_old_scale = m_shape->scale(); + updateUi(); +} + +/** + * @brief ShapeGraphicsItemPropertiesWidget::apply + * Apply the current change, by pushing an undo command to the + * undo stack of the shape diagram. + */ +void ShapeGraphicsItemPropertiesWidget::apply() +{ + if (m_live_edit) + { + disconnect(m_shape, &QGraphicsObject::scaleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi); + disconnect(m_shape, &QetShapeItem::styleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi); + } + + if (m_shape->diagram()) + if (QUndoCommand *undo = associatedUndo()) + m_shape->diagram()->undoStack().push(undo); + + m_old_pen_style = m_shape->penStyle(); + m_old_scale = m_shape->scale(); + + if (m_live_edit) + { + connect(m_shape, &QGraphicsObject::scaleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi); + connect(m_shape, &QetShapeItem::styleChanged, this, &ShapeGraphicsItemPropertiesWidget::updateUi); + } +} + +/** + * @brief ShapeGraphicsItemPropertiesWidget::reset + * Reset the change + */ +void ShapeGraphicsItemPropertiesWidget::reset() +{ + m_shape->setStyle(m_old_pen_style); + m_shape->setScale(m_old_scale); + updateUi(); +} + +/** + * @brief ShapeGraphicsItemPropertiesWidget::associatedUndo + * @return an undo command that represent the change edited by this widget. + * The returned undo command can be a ChangeShapeStyleCommand, ItemResizerCommand or + * a ChangeShapeStyleCommand with a ItemResizerCommand as child. + * If there isn't change, return nullptr + */ +QUndoCommand* ShapeGraphicsItemPropertiesWidget::associatedUndo() const +{ + QUndoCommand *undo = nullptr; + Qt::PenStyle new_style = Qt::PenStyle(ui->m_style_cb->currentIndex() + 1); + if (new_style != m_old_pen_style) undo = new ChangeShapeStyleCommand(m_shape, m_old_pen_style, new_style); + + qreal value = ui->m_scale_slider->value(); + value /= 100; + if (value != m_old_scale) + { + if (undo) + new ItemResizerCommand(m_shape, m_old_scale, value, tr("une shape"), undo); + else + undo = new ItemResizerCommand(m_shape, m_old_scale, value, tr("une shape")); + } + + return undo; +} + +/** + * @brief ShapeGraphicsItemPropertiesWidget::updateUi + */ +void ShapeGraphicsItemPropertiesWidget::updateUi() +{ + ui->m_style_cb->setCurrentIndex(static_cast(m_shape->penStyle()) - 1); + ui->m_lock_pos_cb->setChecked(!m_shape->isMovable()); + ui->m_scale_slider->setValue(m_shape->scale() * 100); +} + +/** + * @brief ShapeGraphicsItemPropertiesWidget::setLiveEdit + * @param live_edit + * @return always true + */ +bool ShapeGraphicsItemPropertiesWidget::setLiveEdit(bool live_edit) +{ + if (live_edit == m_live_edit) return true; + m_live_edit = live_edit; + + if (m_live_edit) + { + connect (ui->m_scale_slider, &QSlider::sliderReleased, this, &ShapeGraphicsItemPropertiesWidget::apply); + connect (ui->m_scale_sb, &QSpinBox::editingFinished, this, &ShapeGraphicsItemPropertiesWidget::apply); + connect (ui->m_style_cb, SIGNAL(activated(int)), this, SLOT(apply())); + } + else + { + disconnect (ui->m_scale_slider, &QSlider::sliderReleased, this, &ShapeGraphicsItemPropertiesWidget::apply); + disconnect (ui->m_scale_sb, &QSpinBox::editingFinished, this, &ShapeGraphicsItemPropertiesWidget::apply); + disconnect (ui->m_style_cb, SIGNAL(activated(int)), this, SLOT(apply())); + } + + return true; +} + +void ShapeGraphicsItemPropertiesWidget::on_m_scale_slider_valueChanged(int value) { + qreal scale = value; + m_shape->setScale(scale / 100); +} + +void ShapeGraphicsItemPropertiesWidget::on_m_lock_pos_cb_clicked() { + m_shape->setMovable(!ui->m_lock_pos_cb->isChecked()); +} diff --git a/sources/ui/shapegraphicsitempropertieswidget.h b/sources/ui/shapegraphicsitempropertieswidget.h new file mode 100644 index 000000000..082287766 --- /dev/null +++ b/sources/ui/shapegraphicsitempropertieswidget.h @@ -0,0 +1,64 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef SHAPEGRAPHICSITEMPROPERTIESWIDGET_H +#define SHAPEGRAPHICSITEMPROPERTIESWIDGET_H + +#include "PropertiesEditor/propertieseditorwidget.h" + +namespace Ui { + class ShapeGraphicsItemPropertiesWidget; +} + +class QetShapeItem; + +/** + * @brief The ShapeGraphicsItemPropertiesWidget class + * Provide a widget to edit the properties of a QetShapeItem + */ +class ShapeGraphicsItemPropertiesWidget : public PropertiesEditorWidget +{ + Q_OBJECT + + public: + explicit ShapeGraphicsItemPropertiesWidget(QetShapeItem *item, QWidget *parent = 0); + ~ShapeGraphicsItemPropertiesWidget(); + + void setItem(QetShapeItem *shape); + + public slots: + virtual void apply(); + virtual void reset(); + public: + virtual QUndoCommand* associatedUndo() const; + virtual QString title() const { return tr("Éditer les propriétés d'une primitive "); } + virtual void updateUi(); + virtual bool setLiveEdit(bool live_edit); + + private slots: + void on_m_scale_slider_valueChanged(int value); + void on_m_lock_pos_cb_clicked(); + + private: + Ui::ShapeGraphicsItemPropertiesWidget *ui; + QetShapeItem *m_shape; + + Qt::PenStyle m_old_pen_style; + qreal m_old_scale; +}; + +#endif // SHAPEGRAPHICSITEMPROPERTIESWIDGET_H diff --git a/sources/ui/shapegraphicsitempropertieswidget.ui b/sources/ui/shapegraphicsitempropertieswidget.ui new file mode 100644 index 000000000..f02f6b5ca --- /dev/null +++ b/sources/ui/shapegraphicsitempropertieswidget.ui @@ -0,0 +1,147 @@ + + + ShapeGraphicsItemPropertiesWidget + + + + 0 + 0 + 175 + 174 + + + + Form + + + + + + Type de trait + + + + + + + Normal + + + + + Tiret + + + + + Pointillé + + + + + Traits et points + + + + + Traits points points + + + + + + + + + + + Verrouiller la position + + + + + + + Échelle + + + false + + + + + + 1 + + + 200 + + + Qt::Horizontal + + + + + + + 1 + + + 200 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + m_scale_slider + valueChanged(int) + m_scale_sb + setValue(int) + + + 174 + 234 + + + 355 + 234 + + + + + m_scale_sb + valueChanged(int) + m_scale_slider + setValue(int) + + + 355 + 234 + + + 174 + 234 + + + + + diff --git a/sources/undocommand/changeshapestylecommand.cpp b/sources/undocommand/changeshapestylecommand.cpp new file mode 100644 index 000000000..ee854c406 --- /dev/null +++ b/sources/undocommand/changeshapestylecommand.cpp @@ -0,0 +1,74 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "changeshapestylecommand.h" +#include "qetshapeitem.h" +#include "diagram.h" + +/** + * @brief ChangeShapeStyleCommand::ChangeShapeStyleCommand + * Constructor + * @param item : shape to change + * @param old_ps : old style + * @param new_ps : new style + * @param parent : parent undo + */ +ChangeShapeStyleCommand::ChangeShapeStyleCommand(QetShapeItem *item, const Qt::PenStyle &old_ps, const Qt::PenStyle new_ps, QUndoCommand *parent): + QUndoCommand(parent), + m_shape(item), + m_old_ps(old_ps), + m_new_ps(new_ps) +{ + setText(QObject::tr("Changer le style d'une primitive")); +} + +/** + * @brief ChangeShapeStyleCommand::mergeWith + * Try to merge this command with other + * @param other + * @return true if was merged + */ +bool ChangeShapeStyleCommand::mergeWith(const QUndoCommand *other) +{ + if (id() != other->id() || other->childCount()) return false; + ChangeShapeStyleCommand const *undo = static_cast(other); + if(m_shape != undo->m_shape) return false; + m_new_ps = undo->m_new_ps; + return true; +} + +/** + * @brief ChangeShapeStyleCommand::undo + * undo this command + */ +void ChangeShapeStyleCommand::undo() +{ + if (m_shape->diagram()) m_shape->diagram()->showMe(); + m_shape->setStyle(m_old_ps); + QUndoCommand::undo(); +} + +/** + * @brief ChangeShapeStyleCommand::redo + * redo this command + */ +void ChangeShapeStyleCommand::redo() +{ + if (m_shape->diagram()) m_shape->diagram()->showMe(); + m_shape->setStyle(m_new_ps); + QUndoCommand::redo(); +} diff --git a/sources/undocommand/changeshapestylecommand.h b/sources/undocommand/changeshapestylecommand.h new file mode 100644 index 000000000..173aa4cad --- /dev/null +++ b/sources/undocommand/changeshapestylecommand.h @@ -0,0 +1,44 @@ +/* + Copyright 2006-2015 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef CHANGESHAPESTYLECOMMAND_H +#define CHANGESHAPESTYLECOMMAND_H + +#include + +class QetShapeItem; + +/** + * @brief The ChangeShapeStyleCommand class + * This class manage undo/redo to change the shape style. + */ +class ChangeShapeStyleCommand : public QUndoCommand +{ + public: + ChangeShapeStyleCommand(QetShapeItem *item, const Qt::PenStyle &old_ps, const Qt::PenStyle new_ps, QUndoCommand *parent = nullptr); + + int id() const {return 4;} + bool mergeWith(const QUndoCommand *other); + void undo(); + void redo(); + + private: + QetShapeItem *m_shape; + Qt::PenStyle m_old_ps, m_new_ps; +}; + +#endif // CHANGESHAPESTYLECOMMAND_H diff --git a/sources/undocommand/itemresizercommand.cpp b/sources/undocommand/itemresizercommand.cpp index 955007d85..1724da1a3 100644 --- a/sources/undocommand/itemresizercommand.cpp +++ b/sources/undocommand/itemresizercommand.cpp @@ -28,7 +28,7 @@ * @param text text to display * @param parent undo parent */ -ItemResizerCommand::ItemResizerCommand (QetGraphicsItem *qgi, qreal &old_, qreal &new_, const QString &text, QUndoCommand *parent): +ItemResizerCommand::ItemResizerCommand (QetGraphicsItem *qgi, const qreal &old_, const qreal &new_, const QString &text, QUndoCommand *parent): QUndoCommand(parent), m_qgi (qgi), m_old_size (old_), @@ -56,7 +56,7 @@ ItemResizerCommand::~ItemResizerCommand() {} */ bool ItemResizerCommand::mergeWith(const QUndoCommand *other) { - if (id() != other->id()) return false; + if (id() != other->id() || other->childCount()) return false; ItemResizerCommand const *undo = static_cast(other); if (m_qgi != undo->m_qgi) return false; m_new_size = undo->m_new_size; diff --git a/sources/undocommand/itemresizercommand.h b/sources/undocommand/itemresizercommand.h index 258376bea..6e9bac338 100644 --- a/sources/undocommand/itemresizercommand.h +++ b/sources/undocommand/itemresizercommand.h @@ -31,7 +31,7 @@ class Diagram; class ItemResizerCommand : public QUndoCommand { public: - ItemResizerCommand (QetGraphicsItem *qgi, qreal &old_, qreal &new_,const QString &text, QUndoCommand *parent = 0); + ItemResizerCommand (QetGraphicsItem *qgi, const qreal &old_, const qreal &new_,const QString &text, QUndoCommand *parent = 0); virtual ~ItemResizerCommand(); public: