From e4f3f284eab96fbce0c7aa920429efcd4408b7a8 Mon Sep 17 00:00:00 2001 From: blacksun Date: Thu, 23 Aug 2018 20:58:41 +0000 Subject: [PATCH] fix bug : if a xml definition of an element haven't got a uuid, the generated pixmap is false. this commit it. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5493 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/factory/elementpicturefactory.cpp | 55 +++++++++++++++++------ sources/factory/elementpicturefactory.h | 2 +- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/sources/factory/elementpicturefactory.cpp b/sources/factory/elementpicturefactory.cpp index 1fed8ff00..92d51512e 100644 --- a/sources/factory/elementpicturefactory.cpp +++ b/sources/factory/elementpicturefactory.cpp @@ -45,6 +45,11 @@ void ElementPictureFactory::getPictures(const ElementsLocation &location, QPictu } QUuid uuid = location.uuid(); + if(Q_UNLIKELY(uuid.isNull())) + { + build(location, &picture, &low_picture); + return; + } if(m_pictures_H.keys().contains(uuid)) { @@ -70,6 +75,7 @@ void ElementPictureFactory::getPictures(const ElementsLocation &location, QPictu QPixmap ElementPictureFactory::pixmap(const ElementsLocation &location) { QUuid uuid = location.uuid(); + if (m_pixmap_H.contains(uuid)) { return m_pixmap_H.value(uuid); } @@ -95,7 +101,9 @@ QPixmap ElementPictureFactory::pixmap(const ElementsLocation &location) painter.translate(hsx, hsy); painter.drawPicture(0, 0, m_pictures_H.value(uuid)); - m_pixmap_H.insert(uuid, pix); + if (!uuid.isNull()) { + m_pixmap_H.insert(uuid, pix); + } return pix; } @@ -116,8 +124,17 @@ ElementPictureFactory::primitives ElementPictureFactory::getPrimitives(const Ele return m_primitives_H.value(location.uuid()); } - -bool ElementPictureFactory::build(const ElementsLocation &location) +/** + * @brief ElementPictureFactory::build + * Build the picture from location. + * @param location + * @param picture + * @param low_picture + * if @picture and/or @low_picture are not null this function draw on it and don't store it. + * if null, this function create a QPicture for normal and low zoom, draw on it and store it in m_pictures_H and m_low_pictures_H + * @return + */ +bool ElementPictureFactory::build(const ElementsLocation &location, QPicture *picture, QPicture *low_picture) { QDomElement dom = location.xml(); @@ -146,26 +163,36 @@ bool ElementPictureFactory::build(const ElementsLocation &location) return(false); } - QPicture pic; - QPicture low_pic; - primitives primitives_; - - m_pictures_H.insert(location.uuid(), pic); - m_low_pictures_H.insert(location.uuid(), low_pic); - m_primitives_H.insert(location.uuid(), primitives_); - QPainter painter; - painter.begin(&pic); + QPicture pic; + primitives primitives_; + if (picture) { + painter.begin(picture); + } + else { + m_pictures_H.insert(location.uuid(), pic); + m_primitives_H.insert(location.uuid(), primitives_); + painter.begin(&pic); + } painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::TextAntialiasing, true); painter.setRenderHint(QPainter::SmoothPixmapTransform,true); - + QPainter low_painter; - low_painter.begin(&low_pic); + QPicture low_pic; + if (low_picture) { + low_painter.begin(low_picture); + } + else { + m_low_pictures_H.insert(location.uuid(), low_pic); + m_primitives_H.insert(location.uuid(), primitives_); + low_painter.begin(&low_pic); + } low_painter.setRenderHint(QPainter::Antialiasing, true); low_painter.setRenderHint(QPainter::TextAntialiasing, true); low_painter.setRenderHint(QPainter::SmoothPixmapTransform,true); + QPen tmp; tmp.setWidthF(1.0); //Vaudoo line to take into account the setCosmetic - don't remove tmp.setCosmetic(true); diff --git a/sources/factory/elementpicturefactory.h b/sources/factory/elementpicturefactory.h index f031b8e0b..dc81bea9b 100644 --- a/sources/factory/elementpicturefactory.h +++ b/sources/factory/elementpicturefactory.h @@ -90,7 +90,7 @@ class ElementPictureFactory ElementPictureFactory operator= (const ElementPictureFactory &); ~ElementPictureFactory() {} - bool build(const ElementsLocation &location); + bool build(const ElementsLocation &location, QPicture *picture=nullptr, QPicture *low_picture=nullptr); void parseElement(const QDomElement &dom, QPainter &painter, primitives &prim) const; void parseLine (const QDomElement &dom, QPainter &painter, primitives &prim) const; void parseRect (const QDomElement &dom, QPainter &painter, primitives &prim) const;