mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Fix bug report N° 122, and fix a memory leak
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4829 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -44,24 +44,32 @@ ElementScene::ElementScene(QETElementEditor *editor, QObject *parent) :
|
|||||||
QGraphicsScene(parent),
|
QGraphicsScene(parent),
|
||||||
m_elmt_type("simple"),
|
m_elmt_type("simple"),
|
||||||
qgi_manager(this),
|
qgi_manager(this),
|
||||||
m_event_interface(nullptr),
|
element_editor(editor)
|
||||||
element_editor(editor),
|
|
||||||
decorator_(0)
|
|
||||||
{
|
{
|
||||||
behavior = Normal;
|
behavior = Normal;
|
||||||
setItemIndexMethod(NoIndex);
|
setItemIndexMethod(NoIndex);
|
||||||
setGrid(1, 1);
|
setGrid(1, 1);
|
||||||
initPasteArea();
|
initPasteArea();
|
||||||
undo_stack.setClean();
|
undo_stack.setClean();
|
||||||
decorator_lock_ = new QMutex(QMutex::NonRecursive);
|
m_decorator_lock = new QMutex(QMutex::NonRecursive);
|
||||||
connect(&undo_stack, SIGNAL(indexChanged(int)), this, SLOT(managePrimitivesGroups()));
|
connect(&undo_stack, SIGNAL(indexChanged(int)), this, SLOT(managePrimitivesGroups()));
|
||||||
connect(this, SIGNAL(selectionChanged()), this, SLOT(managePrimitivesGroups()));
|
connect(this, SIGNAL(selectionChanged()), this, SLOT(managePrimitivesGroups()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Destructeur
|
/**
|
||||||
ElementScene::~ElementScene() {
|
* @brief ElementScene::~ElementScene
|
||||||
delete decorator_lock_;
|
*/
|
||||||
if (m_event_interface) delete m_event_interface;
|
ElementScene::~ElementScene()
|
||||||
|
{
|
||||||
|
//Disconnect to avoid crash, see bug report N° 122.
|
||||||
|
disconnect(&undo_stack, SIGNAL(indexChanged(int)), this, SLOT(managePrimitivesGroups()));
|
||||||
|
delete m_decorator_lock;
|
||||||
|
|
||||||
|
if (m_event_interface)
|
||||||
|
delete m_event_interface;
|
||||||
|
|
||||||
|
if (m_decorator)
|
||||||
|
delete m_decorator;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -782,15 +790,19 @@ void ElementScene::getPasteArea(const QRectF &to_paste) {
|
|||||||
* @brief ElementScene::reset
|
* @brief ElementScene::reset
|
||||||
* Remove all QGraphicsItems in the scene and clear the undo stack.
|
* Remove all QGraphicsItems in the scene and clear the undo stack.
|
||||||
*/
|
*/
|
||||||
void ElementScene::reset() {
|
void ElementScene::reset()
|
||||||
|
{
|
||||||
clearSelection();
|
clearSelection();
|
||||||
undoStack().clear();
|
undoStack().clear();
|
||||||
|
|
||||||
foreach (QGraphicsItem *qgi, items()) {
|
foreach (QGraphicsItem *qgi, items())
|
||||||
|
{
|
||||||
removeItem(qgi);
|
removeItem(qgi);
|
||||||
qgiManager().release(qgi);
|
qgiManager().release(qgi);
|
||||||
}
|
}
|
||||||
decorator_ = 0;
|
|
||||||
|
delete m_decorator;
|
||||||
|
m_decorator = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1016,35 +1028,39 @@ void ElementScene::centerElementToOrigine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Ensure the decorator is adequately shown, hidden or updated so it always
|
* @brief ElementScene::managePrimitivesGroups
|
||||||
represents the current selection.
|
* Ensure the decorator is adequately shown, hidden or updated so it always
|
||||||
*/
|
* represents the current selection.
|
||||||
void ElementScene::managePrimitivesGroups() {
|
*/
|
||||||
// this function is not supposed to be reentrant
|
void ElementScene::managePrimitivesGroups()
|
||||||
if (!decorator_lock_ -> tryLock()) return;
|
{
|
||||||
|
//this function is not supposed to be reentrant
|
||||||
|
if (!m_decorator_lock->tryLock())
|
||||||
|
return;
|
||||||
|
|
||||||
if (!decorator_) {
|
if (!m_decorator)
|
||||||
decorator_ = new ElementPrimitiveDecorator();
|
{
|
||||||
connect(decorator_, SIGNAL(actionFinished(ElementEditionCommand*)), this, SLOT(stackAction(ElementEditionCommand *)));
|
m_decorator = new ElementPrimitiveDecorator();
|
||||||
addItem(decorator_);
|
connect(m_decorator, SIGNAL(actionFinished(ElementEditionCommand*)), this, SLOT(stackAction(ElementEditionCommand *)));
|
||||||
decorator_ -> hide();
|
addItem(m_decorator);
|
||||||
|
m_decorator -> hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
// should we hide the decorator?
|
// should we hide the decorator?
|
||||||
QList<QGraphicsItem *> selected_items = zItems(ElementScene::Selected | ElementScene::IncludeTerminals);
|
QList<QGraphicsItem *> selected_items = zItems(ElementScene::Selected | ElementScene::IncludeTerminals);
|
||||||
if (selected_items.size() == 0)
|
if (selected_items.size() == 0)
|
||||||
decorator_ -> hide();
|
m_decorator -> hide();
|
||||||
else if (selected_items.size() == 1 &&
|
else if (selected_items.size() == 1 &&
|
||||||
selected_items.first()->type() != PartText::Type &&
|
selected_items.first()->type() != PartText::Type &&
|
||||||
selected_items.first()->type() != PartTextField::Type)
|
selected_items.first()->type() != PartTextField::Type)
|
||||||
decorator_->hide();
|
m_decorator->hide();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
decorator_ -> setZValue(1000000);
|
m_decorator -> setZValue(1000000);
|
||||||
decorator_ -> setPos(0, 0);
|
m_decorator -> setPos(0, 0);
|
||||||
decorator_ -> setItems(selected_items);
|
m_decorator -> setItems(selected_items);
|
||||||
}
|
}
|
||||||
decorator_lock_ -> unlock();
|
m_decorator_lock -> unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -82,24 +82,24 @@ class ElementScene : public QGraphicsScene {
|
|||||||
QPointF fsi_pos;
|
QPointF fsi_pos;
|
||||||
QPointF moving_press_pos;
|
QPointF moving_press_pos;
|
||||||
|
|
||||||
/// Variables related to drawing
|
/// Variables related to drawing
|
||||||
ESEventInterface *m_event_interface;
|
ESEventInterface *m_event_interface = nullptr;
|
||||||
Behavior behavior;
|
Behavior behavior;
|
||||||
QETElementEditor *element_editor;
|
QETElementEditor *element_editor = nullptr;
|
||||||
|
|
||||||
/// Variables to manage the paste area on the scene
|
/// Variables to manage the paste area on the scene
|
||||||
QGraphicsRectItem *paste_area_;
|
QGraphicsRectItem *paste_area_;
|
||||||
QRectF defined_paste_area_;
|
QRectF defined_paste_area_;
|
||||||
|
|
||||||
/// Variables to handle copy/paste with offset
|
/// Variables to handle copy/paste with offset
|
||||||
QString last_copied_;
|
QString last_copied_;
|
||||||
|
|
||||||
/// Decorator item displayed when at least one item is selected
|
/// Decorator item displayed when at least one item is selected
|
||||||
ElementPrimitiveDecorator *decorator_;
|
ElementPrimitiveDecorator *m_decorator = nullptr;
|
||||||
|
|
||||||
///< Size of the horizontal grid step
|
///< Size of the horizontal grid step
|
||||||
int x_grid;
|
int x_grid;
|
||||||
///< Size of the vertical grid step
|
///< Size of the vertical grid step
|
||||||
int y_grid;
|
int y_grid;
|
||||||
|
|
||||||
// methods
|
// methods
|
||||||
@@ -153,7 +153,7 @@ class ElementScene : public QGraphicsScene {
|
|||||||
void addPrimitive(QGraphicsItem *);
|
void addPrimitive(QGraphicsItem *);
|
||||||
void initPasteArea();
|
void initPasteArea();
|
||||||
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
|
static bool zValueLessThan(QGraphicsItem *, QGraphicsItem *);
|
||||||
QMutex *decorator_lock_;
|
QMutex *m_decorator_lock;
|
||||||
void centerElementToOrigine();
|
void centerElementToOrigine();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|||||||
Reference in New Issue
Block a user