Fix crash : qet crash when element comment (comment item and cross ref item) is bigger than the width of the rectangle where there are displayed.

The rectangle is now adjusted to the size of the comment.


git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4082 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-07-31 14:20:56 +00:00
parent 0fdb244bb5
commit b025830100
2 changed files with 13 additions and 10 deletions

View File

@@ -105,13 +105,14 @@ bool CommentItem::setTextParent() {
* update the content of this item
* (draw this item in a QPicture)
*/
void CommentItem::updateLabel() {
void CommentItem::updateLabel()
{
QString comment = m_element -> elementInformations()["comment"].toString();
if (comment == m_comment && !m_text_parent) return;
if (comment != m_comment) {
if (comment != m_comment)
{
m_comment = comment;
QPen pen(Qt::black);
@@ -121,10 +122,9 @@ void CommentItem::updateLabel() {
painter.setPen (pen);
painter.setFont (QETApp::diagramTextsFont(6));
QRectF drawing_rect(QPointF(0,0), QSizeF(70, 100));
QRectF text_bounding;
QRectF text_bounding = painter.boundingRect(QRectF(QPointF(0,0), QSizeF(70, 1)), Qt::TextWordWrap | Qt::AlignHCenter, m_comment);
painter.drawText(drawing_rect, Qt::TextWordWrap | Qt::AlignHCenter, m_comment, &text_bounding);
painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, m_comment);
text_bounding.adjust(-1,0,1,0); //adjust only for better visual
painter.drawRoundedRect(text_bounding, 2, 2);

View File

@@ -523,19 +523,22 @@ void CrossRefItem::fillCrossRef(QPainter &painter) {
* Add the comment info of the parent item if needed.
* @param painter painter to use for draw the text
*/
void CrossRefItem::AddExtraInfo(QPainter &painter) {
void CrossRefItem::AddExtraInfo(QPainter &painter)
{
QString comment = m_element -> elementInformations()["comment"].toString();
bool must_show = m_element -> elementInformations().keyMustShow("comment");
if (!comment.isEmpty() && must_show) {
if (!comment.isEmpty() && must_show)
{
painter.save();
painter.setFont(QETApp::diagramTextsFont(6));
QRectF r, text_bounding;
qreal center = boundingRect().center().x();
r = QRectF(QPointF(center - 35, boundingRect().bottom()),
QPointF(center + 35, boundingRect().bottom() + 50));
painter.drawText(r, Qt::TextWordWrap | Qt::AlignHCenter, comment, &text_bounding);
QPointF(center + 35, boundingRect().bottom() + 1));
text_bounding = painter.boundingRect(r, Qt::TextWordWrap | Qt::AlignHCenter, comment);
painter.drawText(text_bounding, Qt::TextWordWrap | Qt::AlignHCenter, comment);
text_bounding.adjust(-1,0,1,0); //adjust only for better visual