From 294a2ebc9d56dd91c0d05155432283a1aa6d17b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Skowro=C5=84ski?= Date: Sun, 3 Jan 2021 18:43:26 +0100 Subject: [PATCH] Fix Qt deprecation warnings. QPrinter::paperSize() and QPrinter::setPaperSize() are obsolete. --- src/Gui/View3DInventor.cpp | 5 +- src/Mod/Drawing/Gui/DrawingView.cpp | 79 ++++++++++++++++++++++++++-- src/Mod/Drawing/Gui/DrawingView.h | 7 ++- src/Mod/TechDraw/Gui/MDIViewPage.cpp | 48 +++++++++++++++-- src/Mod/TechDraw/Gui/MDIViewPage.h | 8 ++- 5 files changed, 134 insertions(+), 13 deletions(-) diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index 00f3b0d83e..396da77057 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -513,12 +513,11 @@ void View3DInventor::printPreview() { QPrinter printer(QPrinter::ScreenResolution); printer.setFullPage(true); -#if (QT_VERSION > QT_VERSION_CHECK(5, 9, 0)) - printer.setPageSize(QPrinter::A4); -#endif #if QT_VERSION >= 0x050300 + printer.setPageSize(QPageSize(QPageSize::A4)); printer.setPageOrientation(QPageLayout::Landscape); #else + printer.setPageSize(QPrinter::A4); printer.setOrientation(QPrinter::Landscape); #endif diff --git a/src/Mod/Drawing/Gui/DrawingView.cpp b/src/Mod/Drawing/Gui/DrawingView.cpp index 0a97f26a1e..799b24cce7 100644 --- a/src/Mod/Drawing/Gui/DrawingView.cpp +++ b/src/Mod/Drawing/Gui/DrawingView.cpp @@ -260,10 +260,11 @@ DrawingView::DrawingView(Gui::Document* doc, QWidget* parent) //setWindowTitle(tr("SVG Viewer")); #if QT_VERSION >= 0x050300 m_orientation = QPageLayout::Landscape; + m_pageSize = QPageSize::A4; #else m_orientation = QPrinter::Landscape; -#endif m_pageSize = QPrinter::A4; +#endif ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/View"); @@ -319,6 +320,29 @@ void DrawingView::findPrinterSettings(const QString& fileName) #endif } +#if QT_VERSION >= 0x050300 + QMap pageSizes; + pageSizes[QPageSize::A0] = QString::fromLatin1("A0"); + pageSizes[QPageSize::A1] = QString::fromLatin1("A1"); + pageSizes[QPageSize::A2] = QString::fromLatin1("A2"); + pageSizes[QPageSize::A3] = QString::fromLatin1("A3"); + pageSizes[QPageSize::A4] = QString::fromLatin1("A4"); + pageSizes[QPageSize::A5] = QString::fromLatin1("A5"); + pageSizes[QPageSize::A6] = QString::fromLatin1("A6"); + pageSizes[QPageSize::A7] = QString::fromLatin1("A7"); + pageSizes[QPageSize::A8] = QString::fromLatin1("A8"); + pageSizes[QPageSize::A9] = QString::fromLatin1("A9"); + pageSizes[QPageSize::B0] = QString::fromLatin1("B0"); + pageSizes[QPageSize::B1] = QString::fromLatin1("B1"); + pageSizes[QPageSize::B2] = QString::fromLatin1("B2"); + pageSizes[QPageSize::B3] = QString::fromLatin1("B3"); + pageSizes[QPageSize::B4] = QString::fromLatin1("B4"); + pageSizes[QPageSize::B5] = QString::fromLatin1("B5"); + pageSizes[QPageSize::B6] = QString::fromLatin1("B6"); + pageSizes[QPageSize::B7] = QString::fromLatin1("B7"); + pageSizes[QPageSize::B8] = QString::fromLatin1("B8"); + pageSizes[QPageSize::B9] = QString::fromLatin1("B9"); +#else QMap pageSizes; pageSizes[QPrinter::A0] = QString::fromLatin1("A0"); pageSizes[QPrinter::A1] = QString::fromLatin1("A1"); @@ -340,7 +364,12 @@ void DrawingView::findPrinterSettings(const QString& fileName) pageSizes[QPrinter::B7] = QString::fromLatin1("B7"); pageSizes[QPrinter::B8] = QString::fromLatin1("B8"); pageSizes[QPrinter::B9] = QString::fromLatin1("B9"); +#endif +#if QT_VERSION >= 0x050300 + for (QMap::iterator it = pageSizes.begin(); it != pageSizes.end(); ++it) { +#else for (QMap::iterator it = pageSizes.begin(); it != pageSizes.end(); ++it) { +#endif if (fileName.startsWith(it.value(), Qt::CaseInsensitive)) { m_pageSize = it.key(); break; @@ -499,6 +528,20 @@ void DrawingView::printPdf() formLayout->addWidget(groupBox, 0, 0, 1, 1); groupBox->setTitle(tr("Page sizes")); +#if QT_VERSION >= 0x050300 + item = new QListWidgetItem(tr("A0"), listWidget); + item->setData(Qt::UserRole, QVariant(QPageSize::A0)); + item = new QListWidgetItem(tr("A1"), listWidget); + item->setData(Qt::UserRole, QVariant(QPageSize::A1)); + item = new QListWidgetItem(tr("A2"), listWidget); + item->setData(Qt::UserRole, QVariant(QPageSize::A2)); + item = new QListWidgetItem(tr("A3"), listWidget); + item->setData(Qt::UserRole, QVariant(QPageSize::A3)); + item = new QListWidgetItem(tr("A4"), listWidget); + item->setData(Qt::UserRole, QVariant(QPageSize::A4)); + item = new QListWidgetItem(tr("A5"), listWidget); + item->setData(Qt::UserRole, QVariant(QPageSize::A5)); +#else item = new QListWidgetItem(tr("A0"), listWidget); item->setData(Qt::UserRole, QVariant(QPrinter::A0)); item = new QListWidgetItem(tr("A1"), listWidget); @@ -511,6 +554,7 @@ void DrawingView::printPdf() item->setData(Qt::UserRole, QVariant(QPrinter::A4)); item = new QListWidgetItem(tr("A5"), listWidget); item->setData(Qt::UserRole, QVariant(QPrinter::A5)); +#endif int index = 4; // by default A4 for (int i=0; icount(); i++) { if (listWidget->item(i)->data(Qt::UserRole).toInt() == m_pageSize) { @@ -536,7 +580,11 @@ void DrawingView::printPdf() QList items = listWidget->selectedItems(); if (items.size() == 1) { int AX = items.front()->data(Qt::UserRole).toInt(); +#if QT_VERSION >= 0x050300 + printer.setPageSize(QPageSize(QPageSize::PageSizeId(AX))); +#else printer.setPaperSize(QPrinter::PageSize(AX)); +#endif } print(&printer); @@ -547,10 +595,12 @@ void DrawingView::print() { QPrinter printer(QPrinter::HighResolution); printer.setFullPage(true); - printer.setPageSize(m_pageSize); + #if QT_VERSION >= 0x050300 + printer.setPageSize(QPageSize(m_pageSize)); printer.setPageOrientation(m_orientation); #else + printer.setPageSize(m_pageSize); printer.setOrientation(m_orientation); #endif @@ -564,10 +614,12 @@ void DrawingView::printPreview() { QPrinter printer(QPrinter::HighResolution); printer.setFullPage(true); - printer.setPageSize(m_pageSize); + #if QT_VERSION >= 0x050300 + printer.setPageSize(QPageSize(m_pageSize)); printer.setPageOrientation(m_orientation); #else + printer.setPageSize(m_pageSize); printer.setOrientation(m_orientation); #endif @@ -594,8 +646,13 @@ void DrawingView::print(QPrinter* printer) if (printer->outputFormat() == QPrinter::NativeFormat) { int w = printer->widthMM(); int h = printer->heightMM(); +#if QT_VERSION >= 0x050300 + QPageSize::PageSizeId realPaperSize = getPageSize(w, h); + QPageSize::PageSizeId curPaperSize = printer->pageLayout().pageSize().id(); +#else QPrinter::PaperSize realPaperSize = getPageSize(w, h); QPrinter::PaperSize curPaperSize = printer->paperSize(); +#endif // for the preview a 'Picture' paint engine is used which we don't // care if it uses wrong printer settings @@ -658,7 +715,11 @@ void DrawingView::print(QPrinter* printer) p.end(); } +#if QT_VERSION >= 0x050300 +QPageSize::PageSizeId DrawingView::getPageSize(int w, int h) const +#else QPrinter::PageSize DrawingView::getPageSize(int w, int h) const +#endif { static const float paperSizes[][2] = { {210, 297}, // A4 @@ -693,17 +754,29 @@ QPrinter::PageSize DrawingView::getPageSize(int w, int h) const {279.4f, 431.8f} // Tabloid }; +#if QT_VERSION >= 0x050300 + QPageSize::PageSizeId ps = QPageSize::Custom; +#else QPrinter::PageSize ps = QPrinter::Custom; +#endif for (int i=0; i<30; i++) { if (std::abs(paperSizes[i][0]-w) <= 1 && std::abs(paperSizes[i][1]-h) <= 1) { +#if QT_VERSION >= 0x050300 + ps = static_cast(i); +#else ps = static_cast(i); +#endif break; } else if (std::abs(paperSizes[i][0]-h) <= 1 && std::abs(paperSizes[i][1]-w) <= 1) { +#if QT_VERSION >= 0x050300 + ps = static_cast(i); +#else ps = static_cast(i); +#endif break; } } diff --git a/src/Mod/Drawing/Gui/DrawingView.h b/src/Mod/Drawing/Gui/DrawingView.h index 4f746ef1c6..8683a862d8 100644 --- a/src/Mod/Drawing/Gui/DrawingView.h +++ b/src/Mod/Drawing/Gui/DrawingView.h @@ -107,7 +107,11 @@ protected: void contextMenuEvent(QContextMenuEvent *event); void closeEvent(QCloseEvent*); void findPrinterSettings(const QString&); +#if QT_VERSION >= 0x050300 + QPageSize::PageSizeId getPageSize(int w, int h) const; +#else QPrinter::PageSize getPageSize(int w, int h) const; +#endif private: QAction *m_nativeAction; @@ -123,10 +127,11 @@ private: QString m_currentPath; #if QT_VERSION >= 0x050300 QPageLayout::Orientation m_orientation; + QPageSize::PageSizeId m_pageSize; #else QPrinter::Orientation m_orientation; -#endif QPrinter::PageSize m_pageSize; +#endif }; } // namespace DrawingViewGui diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.cpp b/src/Mod/TechDraw/Gui/MDIViewPage.cpp index 71636640c8..771814912d 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.cpp +++ b/src/Mod/TechDraw/Gui/MDIViewPage.cpp @@ -119,10 +119,11 @@ MDIViewPage::MDIViewPage(ViewProviderPage *pageVp, Gui::Document* doc, QWidget* : Gui::MDIView(doc, parent), #if QT_VERSION >= 0x050300 m_orientation(QPageLayout::Landscape), + m_paperSize(QPageSize::A4), #else m_orientation(QPrinter::Landscape), -#endif m_paperSize(QPrinter::A4), +#endif m_vpPage(pageVp) { @@ -675,10 +676,12 @@ void MDIViewPage::printPdf(std::string file) QPrinter printer(QPrinter::HighResolution); printer.setFullPage(true); printer.setOutputFileName(filename); - if (m_paperSize == QPrinter::Ledger) { + #if QT_VERSION >= 0x050300 + if (m_paperSize == QPageSize::Ledger) { printer.setPageOrientation((QPageLayout::Orientation) (1 - m_orientation)); //reverse 0/1 #else + if (m_paperSize == QPrinter::Ledger) { printer.setOrientation((QPrinter::Orientation) (1 - m_orientation)); //reverse 0/1 #endif } else { @@ -688,7 +691,11 @@ void MDIViewPage::printPdf(std::string file) printer.setOrientation(m_orientation); #endif } +#if QT_VERSION >= 0x050300 + printer.setPageSize(QPageSize(m_paperSize)); +#else printer.setPaperSize(m_paperSize); +#endif print(&printer); } @@ -696,10 +703,11 @@ void MDIViewPage::print() { QPrinter printer(QPrinter::HighResolution); printer.setFullPage(true); - printer.setPaperSize(m_paperSize); #if QT_VERSION >= 0x050300 + printer.setPageSize(QPageSize(m_paperSize)); printer.setPageOrientation(m_orientation); #else + printer.setPaperSize(m_paperSize); printer.setOrientation(m_orientation); #endif QPrintDialog dlg(&printer, this); @@ -712,10 +720,11 @@ void MDIViewPage::printPreview() { QPrinter printer(QPrinter::HighResolution); printer.setFullPage(true); - printer.setPaperSize(m_paperSize); #if QT_VERSION >= 0x050300 + printer.setPageSize(QPageSize(m_paperSize)); printer.setPageOrientation(m_orientation); #else + printer.setPaperSize(m_paperSize); printer.setOrientation(m_orientation); #endif @@ -743,8 +752,13 @@ void MDIViewPage::print(QPrinter* printer) if (printer->outputFormat() == QPrinter::NativeFormat) { int w = printer->widthMM(); int h = printer->heightMM(); +#if QT_VERSION >= 0x050300 + QPageSize::PageSizeId psPrtCalcd = getPaperSize(w, h); + QPageSize::PageSizeId psPrtSetting = printer->pageLayout().pageSize().id(); +#else QPrinter::PaperSize psPrtCalcd = getPaperSize(w, h); QPrinter::PaperSize psPrtSetting = printer->paperSize(); +#endif // for the preview a 'Picture' paint engine is used which we don't // care if it uses wrong printer settings @@ -836,8 +850,11 @@ void MDIViewPage::print(QPrinter* printer) static_cast (blockConnection(false)); } - +#if QT_VERSION >= 0x050300 +QPageSize::PageSizeId MDIViewPage::getPaperSize(int w, int h) const +#else QPrinter::PaperSize MDIViewPage::getPaperSize(int w, int h) const +#endif { static const float paperSizes[][2] = { {210, 297}, // A4 @@ -872,25 +889,46 @@ QPrinter::PaperSize MDIViewPage::getPaperSize(int w, int h) const {279.4f, 431.8f} // Tabloid (29) causes trouble with orientation on PDF export }; +#if QT_VERSION >= 0x050300 + QPageSize::PageSizeId ps = QPageSize::Custom; +#else QPrinter::PaperSize ps = QPrinter::Custom; +#endif for (int i=0; i<30; i++) { if (std::abs(paperSizes[i][0]-w) <= 1 && std::abs(paperSizes[i][1]-h) <= 1) { +#if QT_VERSION >= 0x050300 + ps = static_cast(i); +#else ps = static_cast(i); +#endif break; } else //handle landscape & portrait w/h if (std::abs(paperSizes[i][0]-h) <= 1 && std::abs(paperSizes[i][1]-w) <= 1) { +#if QT_VERSION >= 0x050300 + ps = static_cast(i); +#else ps = static_cast(i); +#endif break; } } +#if QT_VERSION >= 0x050300 + if (ps == QPageSize::Ledger) { //check if really Tabloid + if (w < 431) { + ps = QPageSize::Tabloid; + } + } +#else if (ps == QPrinter::Ledger) { //check if really Tabloid if (w < 431) { ps = QPrinter::Tabloid; } } +#endif + return ps; } diff --git a/src/Mod/TechDraw/Gui/MDIViewPage.h b/src/Mod/TechDraw/Gui/MDIViewPage.h index c5061f1b1a..9cf6864b05 100644 --- a/src/Mod/TechDraw/Gui/MDIViewPage.h +++ b/src/Mod/TechDraw/Gui/MDIViewPage.h @@ -128,7 +128,12 @@ protected: void contextMenuEvent(QContextMenuEvent *event); void closeEvent(QCloseEvent*); +#if QT_VERSION >= 0x050300 + QPageSize::PageSizeId getPaperSize(int w, int h) const; +#else QPrinter::PaperSize getPaperSize(int w, int h) const; +#endif + void setDimensionGroups(void); void setBalloonGroups(void); void setLeaderGroups(void); @@ -161,10 +166,11 @@ private: QString m_currentPath; #if QT_VERSION >= 0x050300 QPageLayout::Orientation m_orientation; + QPageSize::PageSizeId m_paperSize; #else QPrinter::Orientation m_orientation; -#endif QPrinter::PaperSize m_paperSize; +#endif ViewProviderPage *m_vpPage; QList m_qgSceneSelected; //items in selection order