Details
-
Suggestion
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.1.0
-
None
Description
QTextBlockUserData is not moved with its QTextBlock if all of its QTextBlocks are moved down a row
To reproduce:
#include <QtGui>
struct Data : public QTextBlockUserData
{
int id;
};
class TextEdit : public QTextEdit
{
Q_OBJECT
public:
TextEdit(QWidget *parent = 0)
: QTextEdit(parent)
{
}
void paintEvent(QPaintEvent *e)
void drawUserData(QPainter *painter)
{
QTextDocument *doc = document();
QTextBlock currentBlock = doc->begin();
for (; currentBlock.isValid(); currentBlock = currentBlock.next())
}
public slots:
void populateUserData()
{
QTextDocument *doc = document();
QTextBlock currentBlock = doc->begin();
for (; currentBlock.isValid(); currentBlock = currentBlock.next()) {
if (currentBlock.userData() == 0)
}
update();
}
private:
static int idPool;
};
int TextEdit::idPool = 0;
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDialog dialog;
QVBoxLayout *layout = new QVBoxLayout;
QPushButton *populateButton = new QPushButton;
populateButton->setText(QObject::tr("Populate with QTextBlockUserData"));
TextEdit *edit = new TextEdit;
layout->addWidget(populateButton);
layout->addWidget(edit);
dialog.setLayout(layout);
QObject::connect(populateButton, SIGNAL(clicked()), edit, SLOT(populateUserData()));
dialog.show();
return app.exec();
}
What the attached example does is make a blue rectangle around any QTextBlocks that have QTextBlockUserData set on them through QTextBlock::setUserData(...). If they don't have any set then they're colored red. There's a button which gives all QTextBlocks some user data.
The value isn't important in this example, since it shows the issue with the red and blue rectangles.
The attached screen shots that show the issue using a QTextEdit with an overridden paint event to draw rectangles around the QTextBlocks.
==========================
Note the red box means that the empty QTextBlock has no QTextBlockUserData set for it. I.e., userData() returns a
null pointer for that QTextBlock.
Type some text "ooooo........ooooo" in the first block.
Press the button so all blocks get some QTextBlockUserData.
Notice that the rectangle is now blue, which means userData() does not return null.
Move to the beginning of the line containing "ooooo......oooooo".
Press enter so that "oooo.....ooooo" is moved down a row.
Note that the "oooo..ooooo" text has a red rectangle around it, so its userData() returns null. However the blue rectangle is still there above it for the newly inserted, empty block.