From 052fc27cfbddec56feb1794424a48f82acb5b61d Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Mon, 18 Apr 2022 22:45:02 +0200 Subject: [PATCH] replaced some deprecated constructs for Qt 5.15 --- .../gui/jkqtpenhancedtableview.cpp | 43 ++++++++++++------ lib/jkqtplotter/jkqtpbaseplotter.cpp | 44 +++++++++---------- 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/lib/jkqtplotter/gui/jkqtpenhancedtableview.cpp b/lib/jkqtplotter/gui/jkqtpenhancedtableview.cpp index 7eaefd4ec2..30da6a05b4 100644 --- a/lib/jkqtplotter/gui/jkqtpenhancedtableview.cpp +++ b/lib/jkqtplotter/gui/jkqtpenhancedtableview.cpp @@ -165,9 +165,17 @@ void JKQTPEnhancedTableView::copySelectionToExcel(int copyrole, bool storeHead) if (r= QT_VERSION_CHECK(5, 14, 0)) + QList rowlist(rows.begin(), rows.end()); +#else QList rowlist=QList::fromSet(rows); +#endif std::sort(rowlist.begin(), rowlist.end()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + QList collist(cols.begin(), cols.end()); +#else QList collist=QList::fromSet(cols); +#endif std::sort(collist.begin(), collist.end()); int rowcnt=rowlist.size(); int colcnt=collist.size(); @@ -284,9 +292,17 @@ void JKQTPEnhancedTableView::copySelectionToCSV(int copyrole, bool storeHead, co if (r= QT_VERSION_CHECK(5, 14, 0)) + QList rowlist(rows.begin(), rows.end()); +#else QList rowlist=QList::fromSet(rows); +#endif std::sort(rowlist.begin(), rowlist.end()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) + QList collist(cols.begin(), cols.end()); +#else QList collist=QList::fromSet(cols); +#endif std::sort(collist.begin(), collist.end()); int rowcnt=rowlist.size(); int colcnt=collist.size(); @@ -405,12 +421,12 @@ void JKQTPEnhancedTableView::print(QPrinter *printer, bool onePageWide, bool one QPrinter* p=printer; - //p->setPageMargins(10,10,10,10,QPrinter::Millimeter); + //p->setPageMargins(10,10,10,10,QPageLayout::Millimeter); /*if (width()>height()) { - p->setOrientation(QPrinter::Landscape); + p->setPageOrientation(QPageLayout::Landscape); } else { - p->setOrientation(QPrinter::Portrait); + p->setPageOrientation(QPageLayout::Portrait); }*/ clearSelection(); @@ -444,13 +460,14 @@ void JKQTPEnhancedTableView::print(QPrinter *printer, bool onePageWide, bool one } double scale=1.0; // adjust scale, so the widest/highest column fits on one page - /*if (maxWidth*scale>p->pageRect().width()) scale=p->pageRect().width()/maxWidth; - if (maxHeight*scale>p->pageRect().height()) scale=p->pageRect().height()/maxHeight;*/ + /*if (maxWidth*scale>p->pageLayout().paintRectPixels(p->resolution()).width()) scale=p->pageLayout().paintRectPixels(p->resolution()).width()/maxWidth; + if (maxHeight*scale>p->pageLayout().paintRectPixels(p->resolution()).height()) scale=p->pageLayout().paintRectPixels(p->resolution()).height()/maxHeight;*/ if (onePageWide) { - if (totalWidth>p->pageRect().width()) scale=p->pageRect().width()/totalWidth; + + if (totalWidth>p->pageLayout().paintRectPixels(p->resolution()).width()) scale=p->pageLayout().paintRectPixels(p->resolution()).width()/totalWidth; } if (onePageHigh) { - if (totalHeight>p->pageRect().height()) scale=qMin(scale, p->pageRect().height()/totalHeight); + if (totalHeight>p->pageLayout().paintRectPixels(p->resolution()).height()) scale=qMin(scale, p->pageLayout().paintRectPixels(p->resolution()).height()/totalHeight); } //qDebug()<p->pageRect().width()/scale) { + if (x+cw>p->pageLayout().paintRectPixels(p->resolution()).width()/scale) { pagesWide++; x=0; pageCols<p->pageRect().height()/scale) { + if (y+rh>p->pageLayout().paintRectPixels(p->resolution()).height()/scale) { pagesHigh++; pageRows<pageRect().topLeft()); + //painter.translate(p->pageLayout().paintRectPixels(p->resolution()).topLeft()); int pageCnt=0; for (int ph=0; phpageRect().topLeft(), pic); + //painter.drawPicture(p->pageLayout().paintRectPixels(p->resolution()).topLeft(), pic); double y=0; if (ph==0) { y=hhh; @@ -607,7 +624,7 @@ void JKQTPEnhancedTableView::paint(QPainter &painter, double scale, int page, do painter.setPen(headerPen); painter.drawText(QRect(rec.x()+4, rec.y()+4, rec.width()-8, rec.height()-8), model()->headerData(c, Qt::Horizontal).toString()); painter.drawRect(rec); - //if (x==vhw &&) painter.drawLine(rec.topLeft(), QPoint(rec.left(), p->pageRect().height())); + //if (x==vhw &&) painter.drawLine(rec.topLeft(), QPoint(rec.left(), p->pageLayout().paintRectPixels(p->resolution()).height())); x=x+columnWidth(c); } @@ -623,7 +640,7 @@ void JKQTPEnhancedTableView::paint(QPainter &painter, double scale, int page, do painter.setFont(headerFont); painter.drawText(QRect(rec.x()+4, rec.y()+4, rec.width()-8, rec.height()-8), model()->headerData(r, Qt::Vertical).toString()); painter.drawRect(rec); - //if (x==vhw &&) painter.drawLine(rec.topLeft(), QPoint(rec.left(), p->pageRect().height())); + //if (x==vhw &&) painter.drawLine(rec.topLeft(), QPoint(rec.left(), p->pageLayout().paintRectPixels(p->resolution()).height())); y=y+rowHeight(r); } diff --git a/lib/jkqtplotter/jkqtpbaseplotter.cpp b/lib/jkqtplotter/jkqtpbaseplotter.cpp index d4489e3c93..b99b4ac40a 100644 --- a/lib/jkqtplotter/jkqtpbaseplotter.cpp +++ b/lib/jkqtplotter/jkqtpbaseplotter.cpp @@ -1485,12 +1485,12 @@ void JKQTBasePlotter::print(QPrinter* printer, bool displayPreview) { delete dialog; } - p->setPageMargins(10,10,10,10,QPrinter::Millimeter); + p->setPageMargins(QMarginsF(10,10,10,10),QPageLayout::Millimeter); if (widgetWidth>widgetHeight) { - p->setOrientation(QPrinter::Landscape); + p->setPageOrientation(QPageLayout::Landscape); } else { - p->setOrientation(QPrinter::Portrait); + p->setPageOrientation(QPageLayout::Portrait); } printpreviewNew(p, false, -1.0, -1.0, displayPreview); @@ -1520,8 +1520,8 @@ bool JKQTBasePlotter::printpreviewNew(QPaintDevice* paintDevice, bool setAbsolut //if (printer) resolution=printer->resolution(); printAspect=gridPrintingSize.height()/gridPrintingSize.width(); - if (printer) printPageSizeMM=printer->pageRect(QPrinter::Millimeter).size(); - else printPageSizeMM=QSizeF(paintDevice->widthMM(), paintDevice->heightMM()); + if (printer) printPageSizeMM=printer->pageLayout().pageSize().size(QPageSize::Millimeter); + else if (paintDevice) printPageSizeMM=QSizeF(paintDevice->widthMM(), paintDevice->heightMM()); printSizeX_Millimeter=double(gridPrintingSize.width())/96.0*25.4;//double(resolution)*25.4; // convert current widget size in pt to millimeters, assuming 96dpi (default screen resolution) printSizeY_Millimeter=double(gridPrintingSize.height())/96.0*25.4;//double(resolution)*25.4; if (printsizeX_inMM>0) printSizeX_Millimeter=printsizeX_inMM; @@ -1554,14 +1554,14 @@ bool JKQTBasePlotter::printpreviewNew(QPaintDevice* paintDevice, bool setAbsolut printer->setColorMode(QPrinter::Color); printer->setOutputFormat(QPrinter::PdfFormat); printer->setResolution(svg->logicalDpiX()); - printer->setPageMargins(0,0,0,0,QPrinter::Millimeter); + printer->setPageMargins(QMarginsF(0,0,0,0),QPageLayout::Millimeter); printer->setColorMode(QPrinter::Color); delPrinter=true; } else if (!printer) { printer=new QPrinter(); printer->setOutputFormat(QPrinter::PdfFormat); printer->setResolution(paintDevice->logicalDpiX()); - printer->setPageMargins(0,0,0,0,QPrinter::Millimeter); + printer->setPageMargins(QMarginsF(0,0,0,0),QPageLayout::Millimeter); printer->setColorMode(QPrinter::Color); delPrinter=true; } @@ -1612,7 +1612,7 @@ bool JKQTBasePlotter::printpreviewNew(QPaintDevice* paintDevice, bool setAbsolut layout->addWidget(spinSizeY, 0,layout->columnCount()); layout->addWidget(chkAspect, 0,layout->columnCount()); if (!setAbsolutePaperSize && printer && !svg) { - layout->addWidget(new QLabel(tr("%1x%2 mm^2").arg(printer->pageRect(QPrinter::Millimeter).width()).arg(printer->pageRect(QPrinter::Millimeter).height())), 1,layout->columnCount()-4, 1, 4); + layout->addWidget(new QLabel(tr("%1x%2 mm^2").arg(printer->pageLayout().pageSize().size(QPageSize::Millimeter).width()).arg(printer->pageLayout().pageSize().size(QPageSize::Millimeter).height())), 1,layout->columnCount()-4, 1, 4); QCheckBox* chkSetMagnification=new QCheckBox(tr("set by magnification: "), dlg); chkSetMagnification->setChecked(false); @@ -1930,9 +1930,9 @@ void JKQTBasePlotter::printpreviewPaintRequested(QPrinter* printer) { #ifdef SHOW_JKQTPLOTTER_DEBUG qDebug()<<"set printing abs. size to "<setPaperSize(QPrinter::Custom); - printer->setOrientation(QPrinter::Portrait); - printer->setPaperSize(QSizeF(printSizeX_Millimeter, printSizeY_Millimeter), QPrinter::Millimeter); + //printer->setPageSize(QPrinter::Custom); + printer->setPageOrientation(QPageLayout::Portrait); + printer->setPageSize(QPageSize(QSizeF(printSizeX_Millimeter, printSizeY_Millimeter), QPageSize::Millimeter)); if (!gridPrinting) widgetHeight=jkqtp_roundTo(widgetWidth*printSizeY_Millimeter/printSizeX_Millimeter); } @@ -1957,8 +1957,8 @@ void JKQTBasePlotter::printpreviewPaintRequested(QPrinter* printer) { qDebug()<<"printScaleToPagesize = "<pageRect().size()<<" "; - QSizeF sl=QSizeF(QSizeF(printer->pageRect().size()).width()/printer->logicalDpiX()*25.4, QSizeF(printer->pageRect().size()).height()/printer->logicalDpiY()*25.4); + qDebug()<<"print with paper size "<pageLayout().paintRectPixels(printer->resolution()).size()<<" "; + QSizeF sl=QSizeF(QSizeF(printer->pageLayout().paintRectPixels(printer->resolution()).size()).width()/printer->logicalDpiX()*25.4, QSizeF(printer->pageLayout().paintRectPixels(printer->resolution()).size()).height()/printer->logicalDpiY()*25.4); qDebug()<<"print with paper size "<pageRect().size(), printScaleToPagesize, printScaleToPagesize); + gridPaint(painter, printer->pageLayout().paintRectPixels(printer->resolution()).size(), printScaleToPagesize, printScaleToPagesize); painter.end(); widgetWidth=oldWidgetWidth; widgetHeight=oldWidgetHeight; @@ -2017,8 +2017,8 @@ void JKQTBasePlotter::printpreviewPaintRequestedNew(QPaintDevice *paintDevice) qDebug()<<"set printing abs. size to "<setOrientation(QPrinter::Portrait); - printer->setPaperSize(QSizeF(printSizeX_Millimeter, printSizeY_Millimeter), QPrinter::Millimeter); + printer->setPageOrientation(QPageLayout::Portrait); + printer->setPageSize(QPageSize(QSizeF(printSizeX_Millimeter, printSizeY_Millimeter), QPageSize::Millimeter)); } else if (svg) { QRectF siz=QRectF(0,0,printSizeX_Millimeter,printSizeY_Millimeter); svg->setSize(QSizeF(ceil(siz.width()*svg->resolution()/25.4), ceil(siz.height()*svg->resolution()/25.4)).toSize()); @@ -2051,8 +2051,8 @@ void JKQTBasePlotter::printpreviewPaintRequestedNew(QPaintDevice *paintDevice) qDebug()<<"printKeepAbsoluteFontSizes = "<pageRect().size()<<" "; - QSizeF sl=QSizeF(QSizeF(printer->pageRect().size()).width()/printer->logicalDpiX()*25.4, QSizeF(printer->pageRect().size()).height()/printer->logicalDpiY()*25.4); + qDebug()<<"print with paper size "<pageLayout().paintRectPixels(printer->resolution()).size()<<" "; + QSizeF sl=QSizeF(QSizeF(printer->pageLayout().paintRectPixels(printer->resolution()).size()).width()/printer->logicalDpiX()*25.4, QSizeF(printer->pageLayout().paintRectPixels(printer->resolution()).size()).height()/printer->logicalDpiY()*25.4); qDebug()<<"print with paper size "<size()<<" "; @@ -2069,7 +2069,7 @@ void JKQTBasePlotter::printpreviewPaintRequestedNew(QPaintDevice *paintDevice) qDebug()<<"x-axis label fontsize = "<getLabelFontSize()<<" pt"; qDebug()<<"y-axis label fontsize = "<getLabelFontSize()<<" pt"; #endif - if (printer) gridPaint(painter, printer->pageRect().size(), printScaleToPagesize, printScaleToPagesize); + if (printer) gridPaint(painter, printer->pageLayout().paintRectPixels(printer->resolution()).size(), printScaleToPagesize, printScaleToPagesize); else if (svg) gridPaint(painter, svg->size(), printScaleToPagesize, printScaleToPagesize); else gridPaint(painter, QSizeF(paintDevice->width(), paintDevice->height()), printScaleToPagesize, printScaleToPagesize); painter.end(); @@ -3577,14 +3577,14 @@ void JKQTBasePlotter::saveAsPDF(const QString& filename, bool displayPreview) { doLandscape=gridPrintingSize.width()>gridPrintingSize.height(); } if (doLandscape) { - printer->setOrientation(QPrinter::Landscape); + printer->setPageOrientation(QPageLayout::Landscape); } else { - printer->setOrientation(QPrinter::Portrait); + printer->setPageOrientation(QPageLayout::Portrait); } printer->setOutputFormat(QPrinter::PdfFormat); printer->setColorMode(QPrinter::Color); printer->setOutputFileName(fn); - printer->setPageMargins(0,0,0,0,QPrinter::Millimeter); + printer->setPageMargins(QMarginsF(0,0,0,0),QPageLayout::Millimeter); printer->setColorMode(QPrinter::Color); printpreviewNew(printer, true, -1.0, -1.0, displayPreview); delete printer;