Git commit cc7f4fe0575cbfcbd724ab003e9e58141823e2dc by Friedrich W. H. Koss= ebau. Committed on 30/06/2013 at 21:52. Pushed by kossebau into branch 'calligra/2.7'. Fix memory leak in sidewinder code by not called destructor on incomplete t= ype of QTextDocument REVIEW: 111043 thanks ingwa for review M +8 -8 filters/sheets/excel/import/ODrawClient.cpp M +70 -17 filters/sheets/excel/sidewinder/excel.cpp M +10 -6 filters/sheets/excel/sidewinder/excel.h M +1 -1 filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp http://commits.kde.org/calligra/cc7f4fe0575cbfcbd724ab003e9e58141823e2dc diff --git a/filters/sheets/excel/import/ODrawClient.cpp b/filters/sheets/e= xcel/import/ODrawClient.cpp index c558d73..6db63b9 100644 --- a/filters/sheets/excel/import/ODrawClient.cpp +++ b/filters/sheets/excel/import/ODrawClient.cpp @@ -147,7 +147,7 @@ bool ODrawClient::onlyClientData(const MSO::OfficeArtCl= ientData &o) { Q_UNUSED(o); qDebug() << "NOT YET IMPLEMENTED" << __PRETTY_FUNCTION__; - return !m_shapeText.m_text.isEmpty(); + return !m_shapeText.text().isEmpty(); } = void ODrawClient::processClientData(const MSO::OfficeArtClientTextBox *ct, @@ -155,8 +155,8 @@ void ODrawClient::processClientData(const MSO::OfficeAr= tClientTextBox *ct, { Q_UNUSED(ct); Q_UNUSED(o); - if (m_shapeText.m_doc) { // rich-text - KoTextDocument doc(m_shapeText.m_doc); + if (m_shapeText.richText()) { // rich-text + KoTextDocument doc(m_shapeText.richText()); Q_ASSERT(!doc.styleManager()); Q_ASSERT(m_styleManager); doc.setStyleManager(m_styleManager); @@ -164,11 +164,11 @@ void ODrawClient::processClientData(const MSO::Office= ArtClientTextBox *ct, KoEmbeddedDocumentSaver embeddedSaver; KoShapeSavingContext context(out.xml, out.styles, embeddedSaver); KoTextWriter textWriter(context); - textWriter.write(m_shapeText.m_doc.data(), 0); + textWriter.write(m_shapeText.richText(), 0); = doc.setStyleManager(0); } else { // plain-text - QStringList lines =3D m_shapeText.m_text.split(QRegExp("[\n\r]")); + QStringList lines =3D m_shapeText.text().split(QRegExp("[\n\r]")); foreach (const QString& line, lines) { out.xml.startElement("text:p", false); int pos =3D 0; @@ -209,8 +209,8 @@ KoGenStyle ODrawClient::createGraphicStyle(const MSO::O= fficeArtClientTextBox *ct Q_UNUSED(cd); Q_UNUSED(ds); KoGenStyle style =3D KoGenStyle(KoGenStyle::GraphicAutoStyle, "graphic= "); - if (!m_shapeText.m_text.isEmpty()) { - switch (m_shapeText.halign) { + if (!m_shapeText.text().isEmpty()) { + switch (m_shapeText.hAlign()) { case Swinder::TxORecord::Left: style.addProperty("draw:textarea-horizontal-align", "left"); break; @@ -221,7 +221,7 @@ KoGenStyle ODrawClient::createGraphicStyle(const MSO::O= fficeArtClientTextBox *ct style.addProperty("draw:textarea-horizontal-align", "right"); break; } - switch (m_shapeText.valign) { + switch (m_shapeText.vAlign()) { case Swinder::TxORecord::Top: style.addProperty("draw:textarea-vertical-align", "top"); break; diff --git a/filters/sheets/excel/sidewinder/excel.cpp b/filters/sheets/exc= el/sidewinder/excel.cpp index 50f54c0..b22ff04 100644 --- a/filters/sheets/excel/sidewinder/excel.cpp +++ b/filters/sheets/excel/sidewinder/excel.cpp @@ -1630,23 +1630,58 @@ void ObjRecord::setData(unsigned size, const unsign= ed char* data, const unsigned = // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D TxO =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = +class TxORecord::Private +{ +public: + QString text; + QSharedPointer richText; // NULL if plainText else it d= efines the richText + + TxORecord::HorizontalAlignment hAlign; + TxORecord::VerticalAlignment vAlign; +}; + + const unsigned TxORecord::id =3D 0x1B6; = -TxORecord::TxORecord(Workbook *book) : Record(book) {} -TxORecord::~TxORecord() {} +TxORecord::TxORecord(Workbook *book) + : Record(book) +{ + d =3D new TxORecord::Private(); +} + +TxORecord::TxORecord(const TxORecord& other) + : Record(other) +{ + d =3D new TxORecord::Private(); + operator=3D(other); +} + +TxORecord::~TxORecord() +{ + delete d; +} + +TxORecord& TxORecord::operator=3D(const TxORecord &other) +{ + d->text =3D other.d->text; + d->richText =3D other.d->richText; + d->hAlign =3D other.d->hAlign; + d->vAlign =3D other.d->vAlign; + return *this; +} = void TxORecord::dump(std::ostream& out) const { out << "TxO" << std::endl; - out << " " << m_text << " " << halign << " " << valign; + out << " " << d->text << " " << d->hAlign << " " << d->vAlign; } = void TxORecord::setData(unsigned size, const unsigned char* data, const un= signed* continuePositions) { const unsigned long opts1 =3D readU16(data); //const bool reserved1 =3D opts1 & 0x01; - halign =3D static_cast((opts1 & 0x000e) >> 1); //= 3 bits - valign =3D static_cast((opts1 & 0x0070) >> 4); // 3= bits + d->hAlign =3D static_cast((opts1 & 0x000e) >> 1);= // 3 bits + d->vAlign =3D static_cast((opts1 & 0x0070) >> 4); /= / 3 bits //const unsigned long rot =3D readU16(data + 2); // 4 bytes reserved = @@ -1676,31 +1711,31 @@ void TxORecord::setData(unsigned size, const unsign= ed char* data, const unsigned //Q_ASSERT((opts << 1) =3D=3D 0x0); = // XLUnicodeStringNoCch - m_text.clear(); + d->text.clear(); unsigned k =3D 1; if(fHighByte) { for (; startPict + k + 1 < endPict; k +=3D 2) { unsigned zc =3D readU16(startPict + k); if (!zc) break; if (!QChar(zc).isPrint() && zc !=3D 10) { - m_text.clear(); + d->text.clear(); break; } - m_text.append(QChar(zc)); + d->text.append(QChar(zc)); } } else { for (; startPict + k < endPict; k +=3D 1) { unsigned char uc =3D readU8(startPict + k) + 0x0*256; if (!uc) break; if (!QChar(uc).isPrint() && uc !=3D 10) { - m_text.clear(); + d->text.clear(); break; } - m_text.append(QChar(uc)); + d->text.append(QChar(uc)); } } = - m_doc.clear(); + d->richText.clear(); = // Now look for TxORun structures that specify the formatting run info= rmation for the TxO record. int ToXRunsPositionIndex =3D 0; @@ -1716,11 +1751,11 @@ void TxORecord::setData(unsigned size, const unsign= ed char* data, const unsigned ++ToXRunsPositionIndex; } while(true); if (ToXRunsPositionIndex > 0) { - m_doc =3D QSharedPointer(new QTextDocument()); + d->richText =3D QSharedPointer(new QTextDocument()); // also add a textrangemanager, as KoTextWriter assumes one - KoTextDocument(m_doc).setTextRangeManager(new KoTextRangeManager); - m_doc->setPlainText(m_text); - QTextCursor cursor(m_doc.data()); + KoTextDocument(d->richText).setTextRangeManager(new KoTextRangeMan= ager); + d->richText->setPlainText(d->text); + QTextCursor cursor(d->richText.data()); //cursor.setVisualNavigation(true); QTextCharFormat format; unsigned pos =3D continuePositions[ToXRunsPositionIndex]; @@ -1734,7 +1769,7 @@ void TxORecord::setData(unsigned size, const unsigned= char* data, const unsigned cursor.setPosition(ich, QTextCursor::MoveAnchor); } = - if (ich >=3D unsigned(m_text.length())) { + if (ich >=3D unsigned(d->text.length())) { break; } = @@ -1752,8 +1787,26 @@ void TxORecord::setData(unsigned size, const unsigne= d char* data, const unsigned } } = - std::cout << "TxORecord::setData size=3D" << size << " text=3D" << qPr= intable(m_text) << std::endl; + std::cout << "TxORecord::setData size=3D" << size << " text=3D" << qPr= intable(d->text) << std::endl; +} + +const QString& TxORecord::text() const +{ + return d->text; } +TxORecord::HorizontalAlignment TxORecord::hAlign() const +{ + return d->hAlign; +} +TxORecord::VerticalAlignment TxORecord::vAlign() const +{ + return d->vAlign; +} +const QTextDocument* TxORecord::richText() const +{ + return d->richText.data(); +} + = // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D MsoDrawing =3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D = diff --git a/filters/sheets/excel/sidewinder/excel.h b/filters/sheets/excel= /sidewinder/excel.h index 5b0076c..47f2d54 100644 --- a/filters/sheets/excel/sidewinder/excel.h +++ b/filters/sheets/excel/sidewinder/excel.h @@ -796,15 +796,12 @@ public: VDistributed =3D 7 }; = - QString m_text; - QSharedPointer m_doc; // NULL if plainText else it defi= nes the richText - - HorizontalAlignment halign; - VerticalAlignment valign; - static const unsigned id; explicit TxORecord(Workbook *book=3D0); + // allowing copies for the hack for text support in shapes + TxORecord(const TxORecord&); virtual ~TxORecord(); + TxORecord& operator=3D(const TxORecord&); virtual unsigned rtti() const { return this->id; } @@ -813,6 +810,13 @@ public: } virtual void dump(std::ostream&) const; virtual void setData(unsigned size, const unsigned char* data, const u= nsigned* continuePositions); + const QString &text() const; + TxORecord::HorizontalAlignment hAlign() const; + TxORecord::VerticalAlignment vAlign() const; + const QTextDocument *richText() const; +private: + class Private; + Private *d; }; = class MsoDrawingRecord : public Record diff --git a/filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp = b/filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp index bd66048..383bd0d 100644 --- a/filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp +++ b/filters/sheets/excel/sidewinder/worksheetsubstreamhandler.cpp @@ -738,7 +738,7 @@ void WorksheetSubStreamHandler::handleTxO(TxORecord* re= cord) if (d->sharedObjects.rbegin() !=3D d->sharedObjects.rend()) { NoteObject* no =3D dynamic_cast(d->sharedObjects.rbeg= in()->second); if (no) { - no->setNote(record->m_text); + no->setNote(record->text()); } } if (d->lastOfficeArtObject) {