mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-18 13:30:34 +01:00
Fix deprecated QRegExp
Use QRegularExpression instead. https://doc.qt.io/qt-5/qregularexpression.html#notes-for-qregexp-users This function was introduced in Qt 5
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
Copyright 2006-2020 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@@ -38,7 +38,7 @@ DiagramPrintDialog::DiagramPrintDialog(QETProject *project, QWidget *parent) :
|
||||
{
|
||||
// initialise l'imprimante
|
||||
printer_ = new QPrinter();
|
||||
|
||||
|
||||
// orientation paysage par defaut
|
||||
printer_ -> setOrientation(QPrinter::Landscape);
|
||||
backup_diagram_background_color = Diagram::background_color;
|
||||
@@ -95,16 +95,16 @@ QRect DiagramPrintDialog::diagramRect(Diagram *diagram,
|
||||
const ExportProperties &options) const
|
||||
{
|
||||
if (!diagram) return(QRect());
|
||||
|
||||
|
||||
QRectF diagram_rect = diagram -> border_and_titleblock.borderAndTitleBlockRect();
|
||||
if (!options.draw_titleblock) {
|
||||
qreal titleblock_height = diagram -> border_and_titleblock.titleBlockRect().height();
|
||||
diagram_rect.setHeight(diagram_rect.height() - titleblock_height);
|
||||
}
|
||||
|
||||
|
||||
// ajuste la bordure du schema d'un pixel (epaisseur du trait)
|
||||
diagram_rect = diagram_rect.adjusted(0.0, 0.0, 1.0, 1.0);
|
||||
|
||||
|
||||
return(diagram_rect.toAlignedRect());
|
||||
}
|
||||
|
||||
@@ -113,16 +113,16 @@ QRect DiagramPrintDialog::diagramRect(Diagram *diagram,
|
||||
*/
|
||||
void DiagramPrintDialog::exec()
|
||||
{
|
||||
|
||||
|
||||
// prise en compte du nom du document
|
||||
if (!doc_name_.isEmpty()) printer_ -> setDocName(doc_name_);
|
||||
printer_ -> setCreator(QString("QElectroTech %1").arg(QET::displayedVersion));
|
||||
|
||||
|
||||
// affichage d'un premier dialogue demandant a l'utilisateur le type
|
||||
// d'impression qu'il souhaite effectuer
|
||||
buildPrintTypeDialog();
|
||||
if (dialog_ -> exec() == QDialog::Rejected) return;
|
||||
|
||||
|
||||
// parametrage de l'imprimante en fonction du type d'impression choisi
|
||||
if (printer_choice_ -> isChecked()) {
|
||||
// affichage du dialogue d'impression standard pour parametrer l'imprimante
|
||||
@@ -141,7 +141,7 @@ void DiagramPrintDialog::exec()
|
||||
}
|
||||
|
||||
loadPageSetupForCurrentPrinter();
|
||||
|
||||
|
||||
//Preview before print
|
||||
#if defined Q_OS_LINUX
|
||||
//Due to some bug with xfwm, we display this dialog has a windows on linux os (X11)
|
||||
@@ -159,9 +159,9 @@ void DiagramPrintDialog::exec()
|
||||
DiagramsChooser *dc = preview_dialog.diagramsChooser();
|
||||
dc -> setSelectedAllDiagrams();
|
||||
if (preview_dialog.exec() == QDialog::Rejected) return;
|
||||
|
||||
|
||||
savePageSetupForCurrentPrinter();
|
||||
|
||||
|
||||
// effectue l'impression en elle-meme
|
||||
print(
|
||||
dc -> selectedDiagrams(),
|
||||
@@ -194,7 +194,7 @@ int DiagramPrintDialog::horizontalPagesCount(Diagram *diagram, const ExportPrope
|
||||
// note : pageRect et Paper Rect tiennent compte de l'orientation du papier
|
||||
QRect printable_area = fullpage ? printer_ -> paperRect() : printer_ -> pageRect();
|
||||
QRect diagram_rect = diagramRect(diagram, options);
|
||||
|
||||
|
||||
int h_pages_count = int(ceil(qreal(diagram_rect.width()) / qreal(printable_area.width())));
|
||||
return(h_pages_count);
|
||||
}
|
||||
@@ -211,7 +211,7 @@ int DiagramPrintDialog::verticalPagesCount(Diagram *diagram, const ExportPropert
|
||||
// note : pageRect et Paper Rect tiennent compte de l'orientation du papier
|
||||
QRect printable_area = fullpage ? printer_ -> paperRect() : printer_ -> pageRect();
|
||||
QRect diagram_rect = diagramRect(diagram, options);
|
||||
|
||||
|
||||
int v_pages_count = int(ceil(qreal(diagram_rect.height()) / qreal(printable_area.height())));
|
||||
return(v_pages_count);
|
||||
}
|
||||
@@ -227,7 +227,7 @@ void DiagramPrintDialog::buildPrintTypeDialog()
|
||||
#ifdef Q_OS_MACOS
|
||||
dialog_ -> setWindowFlags(Qt::Sheet);
|
||||
#endif
|
||||
|
||||
|
||||
printtype_label_ = new QLabel(tr("Quel type d'impression désirez-vous effectuer ?"));
|
||||
printer_icon_ = new QLabel();
|
||||
pdf_icon_ = new QLabel();
|
||||
@@ -239,7 +239,7 @@ void DiagramPrintDialog::buildPrintTypeDialog()
|
||||
filepath_field_ = new QLineEdit();
|
||||
browse_button_ = new QPushButton("...");
|
||||
buttons_ = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
|
||||
|
||||
dialog_ -> setWindowTitle(tr("Choix du type d'impression"));
|
||||
printer_icon_ -> setPixmap(QET::Icons::Printer.pixmap(32, 32));
|
||||
pdf_icon_ -> setPixmap(QET::Icons::PDF.pixmap(32, 32));
|
||||
@@ -249,19 +249,19 @@ void DiagramPrintDialog::buildPrintTypeDialog()
|
||||
|
||||
printer_choice_ -> setChecked(true);
|
||||
if (!file_name_.isEmpty()) filepath_field_ -> setText(file_name_ + ".pdf");
|
||||
|
||||
|
||||
// connexions signaux / slots
|
||||
connect(printer_choice_, SIGNAL(toggled(bool)), this, SLOT(updatePrintTypeDialog()));
|
||||
connect(pdf_choice_, SIGNAL(toggled(bool)), this, SLOT(updatePrintTypeDialog()));
|
||||
connect(browse_button_, SIGNAL(clicked(bool)), this, SLOT(browseFilePrintTypeDialog()));
|
||||
connect(buttons_, SIGNAL(accepted()), this, SLOT(acceptPrintTypeDialog()));
|
||||
connect(buttons_, SIGNAL(rejected()), dialog_, SLOT(reject()));
|
||||
|
||||
|
||||
// organisation graphique
|
||||
glayout0_ = new QGridLayout();
|
||||
hlayout0_ = new QHBoxLayout();
|
||||
vlayout0_ = new QVBoxLayout();
|
||||
|
||||
|
||||
hlayout0_ -> addWidget(filepath_field_);
|
||||
hlayout0_ -> addWidget(browse_button_);
|
||||
glayout0_ -> addWidget(printer_icon_, 0, 0);
|
||||
@@ -269,13 +269,13 @@ void DiagramPrintDialog::buildPrintTypeDialog()
|
||||
glayout0_ -> addWidget(pdf_icon_, 1, 0);
|
||||
glayout0_ -> addWidget(pdf_choice_, 1, 1);
|
||||
glayout0_ -> addLayout(hlayout0_, 3, 1);
|
||||
|
||||
|
||||
vlayout0_ -> addWidget(printtype_label_);
|
||||
vlayout0_ -> addLayout(glayout0_);
|
||||
vlayout0_ -> addWidget(buttons_);
|
||||
|
||||
|
||||
dialog_ -> setLayout(vlayout0_);
|
||||
|
||||
|
||||
updatePrintTypeDialog();
|
||||
}
|
||||
|
||||
@@ -286,11 +286,11 @@ void DiagramPrintDialog::updatePrintTypeDialog()
|
||||
{
|
||||
// imprime-t-on vers un fichier ?
|
||||
bool file_print = !(printer_choice_ -> isChecked());
|
||||
|
||||
|
||||
// on n'active le champ fichier que pour les impressions vers un fichier
|
||||
filepath_field_ -> setEnabled(file_print);
|
||||
browse_button_ -> setEnabled(file_print);
|
||||
|
||||
|
||||
// on corrige eventuellement l'extension du fichier deja selectionne
|
||||
if (file_print)
|
||||
{
|
||||
@@ -299,7 +299,9 @@ void DiagramPrintDialog::updatePrintTypeDialog()
|
||||
{
|
||||
if (pdf_choice_ -> isChecked() && filepath.endsWith(".ps"))
|
||||
{
|
||||
QRegExp re("\\.ps$", Qt::CaseInsensitive);
|
||||
QRegularExpression re
|
||||
("\\.ps$",
|
||||
QRegularExpression::CaseInsensitiveOption);
|
||||
filepath.replace(re, ".pdf");
|
||||
filepath_field_ -> setText(filepath);
|
||||
}
|
||||
@@ -331,7 +333,7 @@ void DiagramPrintDialog::acceptPrintTypeDialog()
|
||||
}
|
||||
|
||||
/**
|
||||
Permet a l'utilisateur de choisir un fichier
|
||||
Permet a l'utilisateur de choisir un fichier
|
||||
*/
|
||||
void DiagramPrintDialog::browseFilePrintTypeDialog()
|
||||
{
|
||||
@@ -343,14 +345,14 @@ void DiagramPrintDialog::browseFilePrintTypeDialog()
|
||||
extension = ".pdf";
|
||||
filter = tr("Fichiers PDF (*.pdf)", "file filter");
|
||||
}
|
||||
|
||||
|
||||
QString filepath = QFileDialog::getSaveFileName(
|
||||
parentWidget(),
|
||||
QString(),
|
||||
filepath_field_ -> text(),
|
||||
filter
|
||||
);
|
||||
|
||||
|
||||
if (!filepath.isEmpty()) {
|
||||
if (!filepath.endsWith(extension)) filepath += extension;
|
||||
filepath = QDir::toNativeSeparators(QDir::cleanPath(filepath));
|
||||
@@ -390,13 +392,13 @@ void DiagramPrintDialog::print(const QList<Diagram *> &diagrams,
|
||||
#endif
|
||||
// QPainter utiliser pour effectuer le rendu
|
||||
QPainter qp(printer_);
|
||||
|
||||
|
||||
// cas special : il n'y a aucun schema a imprimer
|
||||
if (!diagrams.count()) {
|
||||
qp.end();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// imprime les schemas
|
||||
for (int i = 0 ; i < diagrams.count() ; ++ i) {
|
||||
printDiagram(diagrams[i], fit_page, options, &qp, printer_);
|
||||
@@ -422,18 +424,18 @@ void DiagramPrintDialog::printDiagram(Diagram *diagram,
|
||||
//qDebug() << printer -> paperSize() << printer -> paperRect() << diagram -> title();
|
||||
// l'imprimante utilise-t-elle toute la feuille ?
|
||||
bool full_page = printer -> fullPage();
|
||||
|
||||
|
||||
// impression physique (!= fichier PDF)
|
||||
if (printer -> outputFileName().isEmpty()) {
|
||||
// utiliser cette condition pour agir differemment en cas d'impression physique
|
||||
}
|
||||
|
||||
|
||||
saveReloadDiagramParameters(diagram, options, true);
|
||||
|
||||
|
||||
// deselectionne tous les elements
|
||||
QList<QGraphicsItem *> selected_elmts = diagram -> selectedItems();
|
||||
foreach (QGraphicsItem *qgi, selected_elmts) qgi -> setSelected(false);
|
||||
|
||||
|
||||
// enleve le flag focusable de tous les elements concernes pour eviter toute reprise de focus par un champ de texte editable
|
||||
QList<QGraphicsItem *> focusable_items;
|
||||
foreach (QGraphicsItem *qgi, diagram -> items()) {
|
||||
@@ -442,12 +444,12 @@ void DiagramPrintDialog::printDiagram(Diagram *diagram,
|
||||
qgi -> setFlag(QGraphicsItem::ItemIsFocusable, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// evite toute autre forme d'interaction
|
||||
foreach (QGraphicsView *view, diagram -> views()) {
|
||||
view -> setInteractive(false);
|
||||
}
|
||||
|
||||
|
||||
QRect diagram_rect = diagramRect(diagram, options);
|
||||
if (fit_page) {
|
||||
// impression adaptee sur une seule page
|
||||
@@ -458,19 +460,19 @@ void DiagramPrintDialog::printDiagram(Diagram *diagram,
|
||||
//qDebug() << "impression sur une ou plusieurs pages";
|
||||
//qDebug() << " schema :" << diagram_rect;
|
||||
//qDebug() << " page :" << printed_area;
|
||||
|
||||
|
||||
int used_width = printed_area.width();
|
||||
int used_height = printed_area.height();
|
||||
int h_pages_count = horizontalPagesCount(diagram, options, full_page);
|
||||
int v_pages_count = verticalPagesCount(diagram, options, full_page);
|
||||
|
||||
|
||||
QVector< QVector< QRect > > pages_grid;
|
||||
// le schema est imprime sur une matrice de feuilles
|
||||
// parcourt les lignes de la matrice
|
||||
int y_offset = 0;
|
||||
for (int i = 0 ; i < v_pages_count ; ++ i) {
|
||||
pages_grid << QVector< QRect >();
|
||||
|
||||
|
||||
// parcourt les feuilles de la ligne
|
||||
int x_offset = 0;
|
||||
for (int j = 0 ; j < h_pages_count ; ++ j) {
|
||||
@@ -483,10 +485,10 @@ void DiagramPrintDialog::printDiagram(Diagram *diagram,
|
||||
);
|
||||
x_offset += used_width;
|
||||
}
|
||||
|
||||
|
||||
y_offset += used_height;
|
||||
}
|
||||
|
||||
|
||||
// ne retient que les pages a imprimer
|
||||
QVector<QRect> pages_to_print;
|
||||
for (int i = 0 ; i < v_pages_count ; ++ i) {
|
||||
@@ -495,7 +497,7 @@ void DiagramPrintDialog::printDiagram(Diagram *diagram,
|
||||
}
|
||||
}
|
||||
//qDebug() << " " << pages_to_print.count() << " pages a imprimer :";
|
||||
|
||||
|
||||
// parcourt les pages pour impression
|
||||
for (int i = 0 ; i < pages_to_print.count() ; ++ i) {
|
||||
QRect current_rect(pages_to_print.at(i));
|
||||
@@ -511,20 +513,20 @@ void DiagramPrintDialog::printDiagram(Diagram *diagram,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// remet en place les interactions
|
||||
foreach (QGraphicsView *view, diagram -> views()) {
|
||||
view -> setInteractive(true);
|
||||
}
|
||||
|
||||
|
||||
// restaure les flags focusable
|
||||
foreach (QGraphicsItem *qgi, focusable_items) {
|
||||
qgi -> setFlag(QGraphicsItem::ItemIsFocusable, true);
|
||||
}
|
||||
|
||||
|
||||
// restaure les elements selectionnes
|
||||
foreach (QGraphicsItem *qgi, selected_elmts) qgi -> setSelected(true);
|
||||
|
||||
|
||||
saveReloadDiagramParameters(diagram, options, false);
|
||||
}
|
||||
|
||||
@@ -537,7 +539,7 @@ void DiagramPrintDialog::printDiagram(Diagram *diagram,
|
||||
*/
|
||||
void DiagramPrintDialog::saveReloadDiagramParameters(Diagram *diagram, const ExportProperties& options, bool save) {
|
||||
static ExportProperties state_exportProperties;
|
||||
|
||||
|
||||
if (save) {
|
||||
// memorise les parametres relatifs au schema tout en appliquant les nouveaux
|
||||
state_exportProperties = diagram -> applyProperties(options);
|
||||
@@ -556,11 +558,11 @@ void DiagramPrintDialog::savePageSetupForCurrentPrinter()
|
||||
{
|
||||
QSettings settings;
|
||||
QString printer_section = settingsSectionName(printer_);
|
||||
|
||||
|
||||
while (!settings.group().isEmpty()) settings.endGroup();
|
||||
settings.beginGroup("printers");
|
||||
settings.beginGroup(printer_section);
|
||||
|
||||
|
||||
settings.setValue("orientation", printer_ -> orientation() == QPrinter::Portrait ? "portrait" : "landscape");
|
||||
settings.setValue("papersize", int(printer_ -> paperSize()));
|
||||
if (printer_ -> paperSize() == QPrinter::Custom) {
|
||||
@@ -592,14 +594,14 @@ void DiagramPrintDialog::loadPageSetupForCurrentPrinter()
|
||||
{
|
||||
QSettings settings;
|
||||
QString printer_section = settingsSectionName(printer_);
|
||||
|
||||
|
||||
while (!settings.group().isEmpty()) settings.endGroup();
|
||||
settings.beginGroup("printers");
|
||||
if (!settings.childGroups().contains(printer_section)) {
|
||||
settings.endGroup();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
settings.beginGroup(printer_section);
|
||||
if (settings.contains("orientation")) {
|
||||
QString value = settings.value("orientation", "landscape").toString();
|
||||
@@ -618,7 +620,7 @@ void DiagramPrintDialog::loadPageSetupForCurrentPrinter()
|
||||
printer_ -> setPaperSize(static_cast<QPrinter::PaperSize>(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
qreal margins[4];
|
||||
printer_ -> getPageMargins(&margins[0], &margins[1], &margins[2], &margins[3], QPrinter::Millimeter);
|
||||
QStringList margins_names(QStringList() << "left" << "top" << "right" << "bottom");
|
||||
@@ -629,7 +631,7 @@ void DiagramPrintDialog::loadPageSetupForCurrentPrinter()
|
||||
}
|
||||
printer_ -> setPageMargins(margins[0], margins[1], margins[2], margins[3], QPrinter::Millimeter);
|
||||
printer_ -> setFullPage(settings.value("fullpage", "false").toString() == "true");
|
||||
|
||||
|
||||
settings.endGroup();
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user