mirror of
				https://github.com/fralx/LimeReport.git
				synced 2025-10-31 13:21:22 +03:00 
			
		
		
		
	Qt6 support added
This commit is contained in:
		| @@ -36,7 +36,11 @@ void HorizontalBarChart::paintHorizontalBars(QPainter *painter, QRectF barsRect) | ||||
|     delta = genNextValue(delta); | ||||
|  | ||||
|     qreal vStep = (barsRect.height()-painter->fontMetrics().height()) / valuesCount() / seriesCount(); | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     qreal hStep = (barsRect.width()-painter->fontMetrics().horizontalAdvance(QString::number(maxValue()))) / delta; | ||||
| #else | ||||
|     qreal hStep = (barsRect.width()-painter->fontMetrics().width(QString::number(maxValue()))) / delta; | ||||
| #endif | ||||
|  | ||||
|     if (!m_chartItem->series().isEmpty() && (m_chartItem->itemMode() != DesignMode)){ | ||||
|         int curSeries = 0; | ||||
|   | ||||
| @@ -14,7 +14,13 @@ void PieChart::drawPercent(QPainter *painter, QRectF chartRect, qreal startAngle | ||||
| #ifdef HAVE_QT5 | ||||
|     qreal radAngle = qDegreesToRadians(angle/2+startAngle); | ||||
| #endif | ||||
|  | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     qreal radius = painter->fontMetrics().horizontalAdvance("99,9%"); | ||||
| #else | ||||
|     qreal radius = painter->fontMetrics().width("99,9%"); | ||||
| #endif | ||||
|  | ||||
|     qreal border = chartRect.height()*0.02; | ||||
|     qreal length = (chartRect.height())/2-(radius/2+border); | ||||
|     qreal x,y; | ||||
| @@ -155,14 +161,24 @@ QSizeF PieChart::calcChartLegendSize(const QFont &font) | ||||
|         SeriesItem* si = m_chartItem->series().at(0); | ||||
|         foreach(QString label, si->data()->labels()){ | ||||
|             cw += fm.height(); | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|             if (maxWidth<fm.horizontalAdvance(label)) | ||||
|                 maxWidth = fm.horizontalAdvance(label)+10; | ||||
| #else | ||||
|             if (maxWidth<fm.width(label)) | ||||
|                 maxWidth = fm.width(label)+10; | ||||
| #endif | ||||
|         } | ||||
|     } else { | ||||
|         foreach(QString label, m_designLabels){ | ||||
|             cw += fm.height(); | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|             if (maxWidth<fm.horizontalAdvance(label)) | ||||
|                 maxWidth = fm.horizontalAdvance(label)+10; | ||||
| #else | ||||
|             if (maxWidth<fm.width(label)) | ||||
|                 maxWidth = fm.width(label)+10; | ||||
| #endif | ||||
|         } | ||||
|     } | ||||
|     cw += fm.height(); | ||||
|   | ||||
| @@ -63,7 +63,11 @@ void FontEditorWidget::initEditor() | ||||
|     m_fontSizeEditor = new QComboBox(this); | ||||
|     m_fontSizeEditor->setModel(&m_fontSizeModel); | ||||
|     m_fontSizeEditor->setEditable(true); | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     connect(m_fontSizeEditor,SIGNAL(currentTextChanged(QString)), this, SLOT(slotFontSizeChanged(QString))); | ||||
| #else | ||||
|     connect(m_fontSizeEditor,SIGNAL(currentIndexChanged(QString)),this,SLOT(slotFontSizeChanged(QString))); | ||||
| #endif | ||||
|     addWidget(m_fontSizeEditor); | ||||
|  | ||||
|     addSeparator(); | ||||
|   | ||||
| @@ -348,7 +348,11 @@ void ChartItem::paintChartTitle(QPainter *painter, QRectF titleRect) | ||||
|     painter->save(); | ||||
|     QFont tmpFont = painter->font(); | ||||
|     QFontMetrics fm(tmpFont); | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     while ((fm.height()>titleRect.height() || fm.horizontalAdvance(m_title) > titleRect.width()) | ||||
| #else | ||||
|     while ((fm.height()>titleRect.height() || fm.width(m_title)>titleRect.width()) | ||||
| #endif | ||||
|            && tmpFont.pixelSize()>1) { | ||||
|         tmpFont.setPixelSize(tmpFont.pixelSize()-1); | ||||
|         fm = QFontMetrics(tmpFont); | ||||
| @@ -566,7 +570,21 @@ QSizeF AbstractSeriesChart::calcChartLegendSize(const QFont &font) | ||||
|  | ||||
|     qreal cw = 0; | ||||
|     qreal maxWidth = 0; | ||||
|  | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     if (!m_chartItem->series().isEmpty()){ | ||||
|         foreach(SeriesItem* series, m_chartItem->series()){ | ||||
|             cw += fm.height(); | ||||
|             if (maxWidth<fm.horizontalAdvance(series->name())) | ||||
|                 maxWidth = fm.horizontalAdvance(series->name())+10; | ||||
|         } | ||||
|     } else { | ||||
|         foreach(QString label, m_designLabels){ | ||||
|             cw += fm.height(); | ||||
|             if (maxWidth<fm.horizontalAdvance(label)) | ||||
|                 maxWidth = fm.horizontalAdvance(label)+10; | ||||
|         } | ||||
|     } | ||||
| #else | ||||
|     if (!m_chartItem->series().isEmpty()){ | ||||
|         foreach(SeriesItem* series, m_chartItem->series()){ | ||||
|             cw += fm.height(); | ||||
| @@ -580,6 +598,7 @@ QSizeF AbstractSeriesChart::calcChartLegendSize(const QFont &font) | ||||
|                 maxWidth = fm.width(label)+10; | ||||
|         } | ||||
|     } | ||||
| #endif | ||||
|     cw += fm.height(); | ||||
|     return  QSizeF(maxWidth+fm.height()*2,cw); | ||||
| } | ||||
| @@ -591,9 +610,16 @@ bool AbstractSeriesChart::verticalLabels(QPainter* painter, QRectF labelsRect) | ||||
|     qreal hStep = (labelsRect.width() / valuesCount()); | ||||
|     QFontMetrics fm = painter->fontMetrics(); | ||||
|     foreach(QString label, m_chartItem->labels()){ | ||||
|         if (fm.width(label) > hStep){ | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|         if (fm.horizontalAdvance(label) > hStep){ | ||||
|             return  true; | ||||
|         } | ||||
| #else | ||||
|         if (fm.width(label) > hStep){             | ||||
|             return  true; | ||||
|         } | ||||
| #endif | ||||
|  | ||||
|     } | ||||
|     return false; | ||||
| } | ||||
| @@ -656,7 +682,11 @@ void AbstractSeriesChart::paintHorizontalGrid(QPainter *painter, QRectF gridRect | ||||
|     delta = genNextValue(delta); | ||||
|  | ||||
|     painter->setRenderHint(QPainter::Antialiasing,false); | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     qreal hStep = (gridRect.width() - painter->fontMetrics().horizontalAdvance(QString::number(maxValue()))) / 4; | ||||
| #else | ||||
|     qreal hStep = (gridRect.width() - painter->fontMetrics().width(QString::number(maxValue()))) / 4; | ||||
| #endif | ||||
|  | ||||
|     painter->setFont(adaptValuesFont(hStep-4, painter->font())); | ||||
|  | ||||
| @@ -708,7 +738,11 @@ qreal AbstractSeriesChart::valuesHMargin(QPainter *painter) | ||||
| { | ||||
|     int delta = int(maxValue()-minValue()); | ||||
|     delta = genNextValue(delta); | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     return painter->fontMetrics().horizontalAdvance(QString::number(delta))+4; | ||||
| #else | ||||
|     return painter->fontMetrics().width(QString::number(delta))+4; | ||||
| #endif | ||||
| } | ||||
|  | ||||
| qreal AbstractSeriesChart::valuesVMargin(QPainter *painter) | ||||
| @@ -720,9 +754,23 @@ QFont AbstractSeriesChart::adaptLabelsFont(QRectF rect, QFont font) | ||||
| { | ||||
|     QString maxWord; | ||||
|     QFontMetrics fm(font); | ||||
|  | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     foreach(QString label, m_chartItem->labels()){ | ||||
|         foreach (QString currentWord, label.split(QRegExp("\\W+"))){ | ||||
|         foreach (QString currentWord, label.split(LRRegularExpression("\\W+"))){ | ||||
|             if (fm.horizontalAdvance(maxWord) < fm.horizontalAdvance(currentWord)) maxWord = currentWord; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     qreal curWidth = fm.horizontalAdvance(maxWord); | ||||
|     QFont tmpFont = font; | ||||
|     while (curWidth>rect.width() && tmpFont.pixelSize() > 1){ | ||||
|         tmpFont.setPixelSize(tmpFont.pixelSize() - 1); | ||||
|         QFontMetricsF tmpFM(tmpFont); | ||||
|         curWidth = tmpFM.horizontalAdvance(maxWord); | ||||
|     } | ||||
| #else | ||||
|     foreach(QString label, m_chartItem->labels()){ | ||||
|         foreach (QString currentWord, label.split(LRRegularExpression("\\W+"))){ | ||||
|             if (fm.width(maxWord) < fm.width(currentWord)) maxWord = currentWord; | ||||
|         } | ||||
|     } | ||||
| @@ -734,6 +782,7 @@ QFont AbstractSeriesChart::adaptLabelsFont(QRectF rect, QFont font) | ||||
|         QFontMetricsF tmpFM(tmpFont); | ||||
|         curWidth = tmpFM.width(maxWord); | ||||
|     } | ||||
| #endif | ||||
|     return tmpFont; | ||||
| } | ||||
|  | ||||
| @@ -741,6 +790,15 @@ QFont AbstractSeriesChart::adaptValuesFont(qreal width, QFont font) | ||||
| { | ||||
|     QString strValue = QString::number(maxValue()); | ||||
|     QFont tmpFont = font; | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     QScopedPointer<QFontMetricsF> fm(new QFontMetricsF(tmpFont)); | ||||
|     qreal curWidth = fm->horizontalAdvance(strValue); | ||||
|     while (curWidth > width && tmpFont.pixelSize() > 1){ | ||||
|         tmpFont.setPixelSize(tmpFont.pixelSize() - 1); | ||||
|         fm.reset(new QFontMetricsF(tmpFont)); | ||||
|         curWidth = fm->horizontalAdvance(strValue); | ||||
|     } | ||||
| #else | ||||
|     QScopedPointer<QFontMetricsF> fm(new QFontMetricsF(tmpFont)); | ||||
|     qreal curWidth = fm->width(strValue); | ||||
|     while (curWidth > width && tmpFont.pixelSize() > 1){ | ||||
| @@ -748,6 +806,7 @@ QFont AbstractSeriesChart::adaptValuesFont(qreal width, QFont font) | ||||
|         fm.reset(new QFontMetricsF(tmpFont)); | ||||
|         curWidth = fm->width(strValue); | ||||
|     } | ||||
| #endif | ||||
|     return tmpFont; | ||||
| } | ||||
|  | ||||
| @@ -801,11 +860,17 @@ void AbstractBarChart::paintChartLegend(QPainter *painter, QRectF legendRect) | ||||
| QRectF AbstractBarChart::verticalLabelsRect(QPainter *painter, QRectF labelsRect) | ||||
| { | ||||
|     qreal maxWidth = 0; | ||||
|  | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     foreach (QString label, m_chartItem->labels()) { | ||||
|         if (painter->fontMetrics().horizontalAdvance(label)>maxWidth) | ||||
|             maxWidth = painter->fontMetrics().horizontalAdvance(label); | ||||
|     } | ||||
| #else | ||||
|     foreach (QString label, m_chartItem->labels()) { | ||||
|         if (painter->fontMetrics().width(label)>maxWidth) | ||||
|             maxWidth = painter->fontMetrics().width(label); | ||||
|     } | ||||
| #endif | ||||
|  | ||||
|     if (maxWidth + hPadding(m_chartItem->rect()) * 2 < labelsRect.width()) | ||||
|         return labelsRect; | ||||
| @@ -816,12 +881,17 @@ QRectF AbstractBarChart::verticalLabelsRect(QPainter *painter, QRectF labelsRect | ||||
| QRectF AbstractBarChart::horizontalLabelsRect(QPainter *painter, QRectF labelsRect) | ||||
| { | ||||
|     qreal maxWidth = 0; | ||||
|  | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     foreach (QString label, m_chartItem->labels()) { | ||||
|         if (painter->fontMetrics().horizontalAdvance(label)>maxWidth) | ||||
|             maxWidth = painter->fontMetrics().horizontalAdvance(label); | ||||
|     } | ||||
| #else | ||||
|     foreach (QString label, m_chartItem->labels()) { | ||||
|         if (painter->fontMetrics().width(label)>maxWidth) | ||||
|             maxWidth = painter->fontMetrics().width(label); | ||||
|     } | ||||
|  | ||||
| #endif | ||||
|     if ((maxWidth + vPadding(m_chartItem->rect()) < labelsRect.height()) || !verticalLabels(painter, labelsRect)) | ||||
|         return labelsRect; | ||||
|     else | ||||
|   | ||||
| @@ -10,7 +10,11 @@ ChartItemEditor::ChartItemEditor(LimeReport::ChartItem *item, LimeReport::PageDe | ||||
| { | ||||
|     ui->setupUi(this); | ||||
|     QHBoxLayout* colorLayout = new QHBoxLayout(); | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     colorLayout->setContentsMargins(0, 0, 0, 0); | ||||
| #else | ||||
|     colorLayout->setMargin(0); | ||||
| #endif | ||||
|     m_colorButton = new QToolButton(); | ||||
|     m_colorButton->setText("..."); | ||||
|     m_colorButton->setSizePolicy(QSizePolicy::Minimum,QSizePolicy::Minimum); | ||||
|   | ||||
| @@ -38,7 +38,7 @@ | ||||
| #include "lrdesignelementsfactory.h" | ||||
| #include "lrglobal.h" | ||||
| #include "lrdatasourcemanager.h" | ||||
| #include "lrsimpletagparser.h" | ||||
| //#include "lrsimpletagparser.h" | ||||
| #include "lrtextitemeditor.h" | ||||
| #include "lrreportengine_p.h" | ||||
| #include <QMenu> | ||||
| @@ -59,7 +59,7 @@ namespace LimeReport{ | ||||
| TextItem::TextItem(QObject *owner, QGraphicsItem *parent) | ||||
|     : ContentItemDesignIntf(xmlTag,owner,parent), m_angle(Angle0), m_trimValue(true), m_allowHTML(false), | ||||
|       m_allowHTMLInFields(false), m_replaceCarriageReturns(false), m_followTo(""), m_follower(0), m_textIndent(0), | ||||
|       m_textLayoutDirection(Qt::LayoutDirectionAuto), m_hideIfEmpty(false), m_fontLetterSpacing(0) | ||||
|       m_textLayoutDirection(Qt::LayoutDirectionAuto), m_hideIfEmpty(false), m_fontLetterSpacing(0), m_adaptedFont(0) | ||||
| { | ||||
|     PageItemDesignIntf* pageItem = dynamic_cast<PageItemDesignIntf*>(parent); | ||||
|     BaseDesignIntf* parentItem = dynamic_cast<BaseDesignIntf*>(parent); | ||||
| @@ -75,7 +75,9 @@ TextItem::TextItem(QObject *owner, QGraphicsItem *parent) | ||||
|     Init(); | ||||
| } | ||||
|  | ||||
| TextItem::~TextItem(){} | ||||
| TextItem::~TextItem(){ | ||||
|     if (m_adaptedFont) delete m_adaptedFont; | ||||
| } | ||||
|  | ||||
| int TextItem::fakeMarginSize() const{ | ||||
|     return marginSize()+5; | ||||
| @@ -360,8 +362,14 @@ void TextItem::updateLayout() | ||||
|  | ||||
| bool TextItem::isNeedExpandContent() const | ||||
| { | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|     QRegularExpression rx("\\$[S|V|D]\\s*\\{[^{].*\\}"); | ||||
|     rx.setPatternOptions(QRegularExpression::DotMatchesEverythingOption); | ||||
| #else | ||||
|     QRegExp rx("$*\\{[^{]*\\}"); | ||||
|     return content().contains(rx) || isContentBackedUp(); | ||||
| #endif | ||||
|     bool result = content().contains(rx) || isContentBackedUp(); | ||||
|     return result; | ||||
| } | ||||
|  | ||||
| QString TextItem::replaceBR(QString text) const | ||||
| @@ -448,7 +456,7 @@ QString TextItem::formatNumber(const double value) | ||||
|  | ||||
|     if (m_format.contains("%")) | ||||
|     { | ||||
|         str.sprintf(m_format.toStdString().c_str(), value); | ||||
|         str.asprintf(m_format.toStdString().c_str(), value); | ||||
|         str = str.replace(",", QLocale::system().groupSeparator()); | ||||
|         str = str.replace(".", QLocale::system().decimalPoint()); | ||||
|     } | ||||
| @@ -522,7 +530,12 @@ TextItem::TextPtr TextItem::textDocument() const | ||||
|  | ||||
|     QFont _font = transformToSceneFont(font()); | ||||
|     if (m_adaptFontToSize && (!(m_autoHeight || m_autoWidth))){ | ||||
|         adaptFontSize(text); | ||||
|         if (!m_adaptedFont){ | ||||
|             adaptFontSize(text); | ||||
|             m_adaptedFont = new QFont(text->defaultFont()); | ||||
|         } else { | ||||
|             setTextFont(text, *m_adaptedFont); | ||||
|         } | ||||
|     } else { | ||||
|         setTextFont(text,_font); | ||||
|     } | ||||
| @@ -779,7 +792,12 @@ void TextItem::setTrimValue(bool value) | ||||
|  | ||||
|  | ||||
| void TextItem::geometryChangedEvent(QRectF , QRectF) | ||||
| {} | ||||
| { | ||||
|     if (m_adaptedFont){ | ||||
|         delete  m_adaptedFont; | ||||
|         m_adaptedFont = 0; | ||||
|     } | ||||
| } | ||||
|  | ||||
| bool TextItem::isNeedUpdateSize(RenderPass pass) const | ||||
| { | ||||
| @@ -813,7 +831,11 @@ void TextItem::expandContent(DataSourceManager* dataManager, RenderPass pass) | ||||
| { | ||||
|     QString context=content(); | ||||
|     foreach (QString variableName, dataManager->variableNamesByRenderPass(SecondPass)) { | ||||
| #if QT_VERSION >= QT_VERSION_CHECK(5, 12, 3) | ||||
|         QRegularExpression rx(QString(Const::NAMED_VARIABLE_RX).arg(variableName)); | ||||
| #else | ||||
|         QRegExp rx(QString(Const::NAMED_VARIABLE_RX).arg(variableName)); | ||||
| #endif | ||||
|         if (context.contains(rx) && pass == FirstPass){ | ||||
|             backupContent(); | ||||
|             break; | ||||
|   | ||||
| @@ -232,6 +232,7 @@ private: | ||||
|     Qt::LayoutDirection m_textLayoutDirection; | ||||
|     bool m_hideIfEmpty; | ||||
|     int m_fontLetterSpacing; | ||||
|     QFont mutable *m_adaptedFont; | ||||
| }; | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user