Changeset View
Changeset View
Standalone View
Standalone View
plugins/textshape/TextDocumentStructureModel.cpp
Show First 20 Lines • Show All 289 Lines • ▼ Show 20 Line(s) | 268 | { | |||
---|---|---|---|---|---|
290 | } | 290 | } | ||
291 | 291 | | |||
292 | return false; | 292 | return false; | ||
293 | } | 293 | } | ||
294 | 294 | | |||
295 | 295 | | |||
296 | void TextDocumentStructureModel::setTextDocument(QTextDocument* textDocument) | 296 | void TextDocumentStructureModel::setTextDocument(QTextDocument* textDocument) | ||
297 | { | 297 | { | ||
298 | beginResetModel(); | ||||
298 | if (m_textDocument) { | 299 | if (m_textDocument) { | ||
299 | m_textDocument->disconnect(this); | 300 | m_textDocument->disconnect(this); | ||
300 | } | 301 | } | ||
301 | 302 | | |||
302 | m_textDocument = textDocument; | 303 | m_textDocument = textDocument; | ||
303 | 304 | | |||
304 | if (m_textDocument) { | 305 | if (m_textDocument) { | ||
305 | connect(m_textDocument, SIGNAL(contentsChanged()), SLOT(onContentsChanged())); | 306 | connect(m_textDocument, SIGNAL(contentsChanged()), SLOT(onContentsChanged())); | ||
306 | } | 307 | } | ||
307 | 308 | | |||
308 | reset(); | 309 | endResetModel(); | ||
dcaliste: I did the same changes in https://phabricator.kde.org/D15102 at another place and I put the… | |||||
Wouldn't expect much risk. modelAboutToBeReset is rarely used, grepping Calligra returns only text shape style dialog thing which only repeats the action, and relying on state between begin&end doesn't soud like a good idea. pvuorela: Wouldn't expect much risk. modelAboutToBeReset is rarely used, grepping Calligra returns only… | |||||
Hmmm, cannot find the diff either, but I *think* it was about an emit, wasn' it? danders: Hmmm, cannot find the diff either, but I *think* it was about an emit, wasn' it? | |||||
309 | } | 310 | } | ||
310 | 311 | | |||
311 | int TextDocumentStructureModel::lineIndex(const QTextBlock &block, const QTextLine &line) const | 312 | int TextDocumentStructureModel::lineIndex(const QTextBlock &block, const QTextLine &line) const | ||
312 | { | 313 | { | ||
313 | int index; | 314 | int index; | ||
314 | 315 | | |||
315 | const int blockNumber = block.blockNumber(); | 316 | const int blockNumber = block.blockNumber(); | ||
316 | QHash<int, BlockData>::Iterator blockIt = m_blockNumberTable.find(blockNumber); | 317 | QHash<int, BlockData>::Iterator blockIt = m_blockNumberTable.find(blockNumber); | ||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | 360 | } else { | |||
360 | index = it.value(); | 361 | index = it.value(); | ||
361 | } | 362 | } | ||
362 | 363 | | |||
363 | return index; | 364 | return index; | ||
364 | } | 365 | } | ||
365 | 366 | | |||
366 | void TextDocumentStructureModel::onContentsChanged() | 367 | void TextDocumentStructureModel::onContentsChanged() | ||
367 | { | 368 | { | ||
368 | reset(); | 369 | beginResetModel(); | ||
370 | endResetModel(); | ||||
369 | } | 371 | } | ||
370 | 372 | | |||
371 | void TextDocumentStructureModel::onModelReset() | 373 | void TextDocumentStructureModel::onModelReset() | ||
372 | { | 374 | { | ||
373 | debugTextShape << "-------------------------- "<<m_textDocument; | 375 | debugTextShape << "-------------------------- "<<m_textDocument; | ||
374 | m_nodeDataTable.clear(); | 376 | m_nodeDataTable.clear(); | ||
375 | m_blockNumberTable.clear(); | 377 | m_blockNumberTable.clear(); | ||
376 | m_frameTable.clear(); | 378 | m_frameTable.clear(); | ||
377 | 379 | | |||
378 | // prefill table with root node | 380 | // prefill table with root node | ||
379 | if (m_textDocument) { | 381 | if (m_textDocument) { | ||
380 | QTextFrame *rootFrame = m_textDocument->rootFrame(); | 382 | QTextFrame *rootFrame = m_textDocument->rootFrame(); | ||
381 | m_frameTable.insert(rootFrame, 0); | 383 | m_frameTable.insert(rootFrame, 0); | ||
382 | m_nodeDataTable.append(NodeData::fromFrame(rootFrame)); | 384 | m_nodeDataTable.append(NodeData::fromFrame(rootFrame)); | ||
383 | } | 385 | } | ||
384 | } | 386 | } |
I did the same changes in https://phabricator.kde.org/D15102 at another place and I put the begin and end at the start and end of the routine, like you did. But I remember that I got review asking not to risk to change signal order emission, in case, and put the begin/end just around the m_textDocument assignment.
I'm not completely sure that I remember correctly and I cannot find it in Phabricator anymore...