Commit fcc38b5b authored by jean lima andrade's avatar jean lima andrade
Browse files

Create a new painter instance just when needed

parent 849f372b
......@@ -8,6 +8,8 @@ ImagePainter::ImagePainter(Container* parent) :
m_shape(Shape::Polygon)
{
m_parent->setCurrentObject(new Polygon(m_parent->currentObject()->objClass()));
m_parent->viewport()->installEventFilter(m_parent);
m_parent->viewport()->setMouseTracking(false);
}
ImagePainter::~ImagePainter()
......
......@@ -52,21 +52,21 @@ void Container::changeItem(const QString& path)
scene()->setSceneRect(0, 0, 850, 640);
scene()->clear();
//IMPROVEME: only change painter when a different type
// of file is loaded, and not always
if (path.endsWith(".txt") || path.endsWith(".TXT")) {
emit painterChanged(false);
Painter *oldPainter = m_painter;
m_painter = new TextPainter(this);
delete oldPainter;
if (!dynamic_cast<TextPainter*>(m_painter)) {
emit painterChanged(false);
Painter *oldPainter = m_painter;
m_painter = new TextPainter(this);
delete oldPainter;
}
}
else {
emit painterChanged();
Painter *oldPainter = m_painter;
m_painter = new ImagePainter(this);
viewport()->installEventFilter(this);
viewport()->setMouseTracking(false);
delete oldPainter;
if (!dynamic_cast<ImagePainter*>(m_painter)) {
emit painterChanged();
Painter *oldPainter = m_painter;
m_painter = new ImagePainter(this);
delete oldPainter;
}
}
m_painter->changeItem(path);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment