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
This commit is contained in:
blacksun
2015-06-21 20:16:41 +00:00
parent 33b637e6bf
commit 9c6d362637
11 changed files with 575 additions and 107 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#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<const ChangeShapeStyleCommand*>(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();
}

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef CHANGESHAPESTYLECOMMAND_H
#define CHANGESHAPESTYLECOMMAND_H
#include <QUndoCommand>
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

View File

@@ -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<const ItemResizerCommand *>(other);
if (m_qgi != undo->m_qgi) return false;
m_new_size = undo->m_new_size;

View File

@@ -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: