24 #include <QAbstractTextDocumentLayout>
30 : m_usesTabPositions(false)
36 ChartTextObject::registerChartTextObjectHandler(&m_document);
44 void KDReports::TextDocumentData::dumpTextValueCursors()
const
46 qDebug() <<
"Text value cursors: (document size=" << m_document.characterCount() <<
")";
48 while (it != m_textValueCursors.end()) {
49 const TextValueData &data = *it;
50 if (data.cursor.isNull()) {
51 qDebug() << it.
key() <<
"unresolved cursor at pos" << data.initialPosition;
53 qDebug() << it.
key() <<
"QTextCursor currently at pos" << data.cursor.position() <<
"length" << data.valueLength;
61 resolveCursorPositions(mode);
64 void KDReports::TextDocumentData::resolveCursorPositions(ModificationMode mode)
70 auto it = m_textValueCursors.
begin();
71 for (; it != m_textValueCursors.
end(); ++it) {
72 TextValueData &data = *it;
73 if (data.cursor.isNull()) {
76 if (mode == Append && data.initialPosition >= m_document.characterCount() - 1) {
80 data.cursor.setPosition(data.initialPosition);
91 val.valueLength = valueLength;
92 val.elementType = html ? ElementTypeHtml : ElementTypeText;
93 val.initialPosition = pos;
94 m_textValueCursors.insert(
id, val);
99 aboutToModifyContents(Modify);
104 while (it != m_textValueCursors.
end() && it.
key() ==
id) {
105 TextValueData &data = *it;
109 const int oldPos = data.cursor.position();
111 const bool html = data.elementType == ElementTypeHtml;
117 data.valueLength = c.
position() - oldPos;
118 data.cursor.setPosition(oldPos);
129 if (!m_hasResizableImages && !m_usesTabPositions) {
134 if (m_hasResizableImages) {
141 updatePercentSize(imageFormat, size);
147 }
while (!c.
atEnd());
150 if (m_usesTabPositions) {
159 for (
int i = 0; i < tabs.
count(); ++i) {
164 tab.position = size.
width() - rootFrameMargins;
166 tab.position = (size.
width() - rootFrameMargins) / 2;
175 block = block.
next();
183 if (w != m_document.textWidth()) {
185 m_document.setTextWidth(w);
186 updatePercentSizes(m_document.size());
192 if (size != m_document.pageSize()) {
194 m_document.setPageSize(size);
195 updatePercentSizes(size);
203 const qreal imageRatio = imageFormat.
height() / imageFormat.
width();
204 const qreal pageWidth = size.
width();
205 const qreal pageHeight = size.
height();
206 const qreal pageRatio = pageWidth ? pageHeight / pageWidth : 0;
209 if (imageRatio < pageRatio) {
210 prop = QStringLiteral(
"W100");
212 prop = QStringLiteral(
"H100");
216 switch (prop[0].toLatin1()) {
218 const qreal newWidth = pageWidth * percent / 100.0;
220 imageFormat.
setHeight(newWidth * imageRatio);
222 if (percent == 100.0)
226 imageFormat.
setHeight(pageHeight * percent / 100.0);
230 if (percent == 100.0)
232 imageFormat.
setWidth(imageRatio ? imageFormat.
height() / imageRatio : 0);
236 qWarning(
"Unhandled image format property type - internal error");
242 m_tables.append(table);
248 qreal currentPointSize = -1.0;
253 if (cursorFontPointSize != currentPointSize) {
254 if (currentPointSize != -1.0) {
255 setFontSizeHelper(lastCursor, cursor.
position() - 1, currentPointSize, factor);
258 currentPointSize = cursorFontPointSize;
264 if (currentPointSize != -1.0) {
265 setFontSizeHelper(lastCursor, cursor.
position(), currentPointSize, factor);
275 for (
int i = 0; i < constraints.
size(); ++i) {
286 void KDReports::TextDocumentData::setFontSizeHelper(
QTextCursor &lastCursor,
int endPosition, qreal pointSize, qreal factor)
288 if (pointSize == 0) {
289 pointSize = m_document.defaultFont().pointSize();
302 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
303 QString htmlText = m_document.toHtml(
"utf-8");
305 QString htmlText = m_document.toHtml();
307 htmlText.
remove(
QLatin1String(
"margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; "));
318 registerTable(table);
319 m_autoTables.insert(table, *element);
326 for (AutoTablesMaps::iterator it = m_autoTables.begin(); it != m_autoTables.end(); ++it)
334 if (m_autoTables.isEmpty())
336 aboutToModifyContents(Modify);
339 AutoTablesMaps autoTables = m_autoTables;
340 m_autoTables.clear();
341 AutoTablesMaps::const_iterator it = autoTables.
constBegin();
342 for (; it != autoTables.constEnd(); ++it) {
345 regenerateOneTable(tableElement, table);
353 aboutToModifyContents(Modify);
355 AutoTablesMaps::iterator it = m_autoTables.begin();
356 for (; it != m_autoTables.end(); ++it) {
360 m_autoTables.erase(it);
361 regenerateOneTable(tableElement, table);
380 m_tables.removeAll(table);
382 ReportBuilder builder(*
this, cursor,
nullptr );
386 builder.setDefaultFont(font);
388 tableElement.
build(builder);
396 Q_FOREACH (
const QString &name, m_resourceNames) {
407 m_resourceNames.append(resourceName);
412 m_hasResizableImages =
true;
417 m_usesTabPositions = usesTabs;