diff --git a/src/Base/baseitem.h b/src/Base/baseitem.h index 090ddb1..67b3ad5 100644 --- a/src/Base/baseitem.h +++ b/src/Base/baseitem.h @@ -10,6 +10,11 @@ class BaseItem: public QGraphicsItem // Q_OBJECT public: + enum + { + Type = UserType + 1 + }; + explicit BaseItem(QObject *parent = nullptr); QRectF rect() const; @@ -24,6 +29,11 @@ class BaseItem: public QGraphicsItem void setColor(const QColor &color); + int type() const override + { + return Type; + } + private: QRectF _rect = QRectF(0, 0, 100, 100); QBrush _brush = Qt::yellow; diff --git a/src/Base/diagrambase.cpp b/src/Base/diagrambase.cpp index 85661fa..0eb2222 100644 --- a/src/Base/diagrambase.cpp +++ b/src/Base/diagrambase.cpp @@ -385,6 +385,7 @@ DiagramBase::DiagramBase(QWidget *parent): connect(_menuBar, &MenuBar::doRedo, ObjectKeeper::instance()->getUndoStack(), &QUndoStack::redo); } + cmd = new ShapeCommand(); } DiagramBase::~DiagramBase() @@ -642,6 +643,10 @@ void DiagramBase::InsertDiagramText() _textItem->setZValue(101); _textItem->setFont(font); + cmd->setItem(_textItem); + + ObjectKeeper::instance()->createCommand(cmd); + scene->addItem(_textItem); } diff --git a/src/Base/diagrambase.h b/src/Base/diagrambase.h index 5a31df6..66c0589 100644 --- a/src/Base/diagrambase.h +++ b/src/Base/diagrambase.h @@ -88,6 +88,7 @@ private slots: QAction *undoAction; QAction *redoAction; DiagramTextItem *_textItem; + ShapeCommand *cmd; }; #endif // DIAGRAMBASE_H diff --git a/src/Base/diagramscene.cpp b/src/Base/diagramscene.cpp index 5a1af6c..5bc5150 100644 --- a/src/Base/diagramscene.cpp +++ b/src/Base/diagramscene.cpp @@ -10,6 +10,7 @@ #include #include #include +#include DiagramScene *DiagramScene::sInstance = nullptr; @@ -26,6 +27,7 @@ DiagramScene::DiagramScene(QObject *parent): if (item) { + qDebug() << "Item Type " << item->type(); resizer = QSharedPointer::create(item); resizer->setBrush(QColor(64, 64, 64)); resizer->setMinSize(QSizeF(30, 30)); diff --git a/src/Base/diagramtextitem.h b/src/Base/diagramtextitem.h index a3f0d64..fc181d7 100644 --- a/src/Base/diagramtextitem.h +++ b/src/Base/diagramtextitem.h @@ -16,7 +16,7 @@ class DiagramTextItem: public QGraphicsTextItem Type = UserType + 3 }; - DiagramTextItem( QGraphicsItem *parent = nullptr); + DiagramTextItem(QGraphicsItem *parent = nullptr); int type() const override { @@ -29,8 +29,6 @@ class DiagramTextItem: public QGraphicsTextItem void selectedChange(QGraphicsItem *item); protected: - - QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; void focusOutEvent(QFocusEvent *event) override;