From be42e729c5b497507354a3c93366e098e3796c26 Mon Sep 17 00:00:00 2001 From: "Jason E. Hale" Date: Wed, 22 Nov 2023 17:06:01 -0500 Subject: [PATCH] Port away from deprecated Qt6 methods and constuctors Fixes #375 (part 2) --- qucs/components/component.cpp | 12 ++++++++++++ qucs/diagrams/diagram.cpp | 4 ++++ qucs/diagrams/graph.cpp | 4 ++++ qucs/extsimkernels/abstractspicekernel.cpp | 2 +- qucs/extsimkernels/qucs2spice.cpp | 20 ++++++++++---------- qucs/extsimkernels/spicecompat.cpp | 2 +- qucs/imagewriter.cpp | 4 ++-- qucs/main.cpp | 17 +++++++++++++++-- qucs/mouseactions.cpp | 5 +++++ qucs/paintings/arrow.cpp | 4 ++++ qucs/paintings/ellipse.cpp | 8 ++++++++ qucs/paintings/ellipsearc.cpp | 4 ++++ qucs/paintings/graphicline.cpp | 4 ++++ qucs/paintings/graphictext.cpp | 4 ++++ qucs/paintings/rectangle.cpp | 8 ++++++++ qucs/schematic.cpp | 8 +++++--- qucs/symbolwidget.cpp | 14 +++++++++++++- 17 files changed, 104 insertions(+), 20 deletions(-) diff --git a/qucs/components/component.cpp b/qucs/components/component.cpp index 025c56235..4f99f5362 100644 --- a/qucs/components/component.cpp +++ b/qucs/components/component.cpp @@ -1290,7 +1290,11 @@ int Component::analyseLine(const QString &Row, int numProps) { return 1; } else if (s == "Text") { // must be last in order to reuse "s" ********* if (!getIntegers(Row, &i1, &i2, &i3, 0, &i4)) return -1; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + Color.fromString(Row.section(' ', 4, 4)); +#else Color.setNamedColor(Row.section(' ', 4, 4)); +#endif if (!Color.isValid()) return -1; s = Row.mid(Row.indexOf('"') + 1); // Text (can contain " !!!) @@ -1373,7 +1377,11 @@ bool Component::getPen(const QString &s, QPen &Pen, int i) { n = s.section(' ', i, i); // color QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Pen.setColor(co); if (!Pen.color().isValid()) return false; @@ -1397,7 +1405,11 @@ bool Component::getBrush(const QString &s, QBrush &Brush, int i) { n = s.section(' ', i, i); // fill color QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Brush.setColor(co); if (!Brush.color().isValid()) return false; diff --git a/qucs/diagrams/diagram.cpp b/qucs/diagrams/diagram.cpp index f66d4bb5f..ee2e4be87 100644 --- a/qucs/diagrams/diagram.cpp +++ b/qucs/diagrams/diagram.cpp @@ -1323,7 +1323,11 @@ bool Diagram::load(const QString &Line, QTextStream *stream) { n = s.section(' ', 6, 6); // color for GridPen QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif GridPen.setColor(co); if (!GridPen.color().isValid()) return false; diff --git a/qucs/diagrams/graph.cpp b/qucs/diagrams/graph.cpp index 5e8efa5bd..e567288df 100644 --- a/qucs/diagrams/graph.cpp +++ b/qucs/diagrams/graph.cpp @@ -123,7 +123,11 @@ bool Graph::load(const QString& _s) QString n; n = s.section(' ',1,1); // Color +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + Color.fromString(n); +#else Color.setNamedColor(n); +#endif if(!Color.isValid()) return false; n = s.section(' ',2,2); // Thick diff --git a/qucs/extsimkernels/abstractspicekernel.cpp b/qucs/extsimkernels/abstractspicekernel.cpp index ee2fca690..090b09ae0 100644 --- a/qucs/extsimkernels/abstractspicekernel.cpp +++ b/qucs/extsimkernels/abstractspicekernel.cpp @@ -1332,7 +1332,7 @@ void AbstractSpiceKernel::normalizeVarsNames(QStringList &var_list) if ((*it).startsWith('I')) suffix = ".Ib"; else suffix = ".Vb"; int idx = it->indexOf('('); - int cnt = it->count(); + int cnt = it->size(); *it = it->right(cnt-idx-1); it->remove(')'); *it += suffix; diff --git a/qucs/extsimkernels/qucs2spice.cpp b/qucs/extsimkernels/qucs2spice.cpp index c6ed2b597..714fd8bb5 100644 --- a/qucs/extsimkernels/qucs2spice.cpp +++ b/qucs/extsimkernels/qucs2spice.cpp @@ -132,7 +132,7 @@ QString qucs2spice::convert_rcl(const QString& line) s += " " + lst.takeFirst() + " "; s1 = lst.takeFirst().remove("\""); int idx = s1.indexOf('='); - s += s1.right(s1.count()-idx-1); + s += s1.right(s1.size()-idx-1); s += "\n"; return s; } @@ -154,7 +154,7 @@ QString qucs2spice::convert_diode(QString line,bool xyce) QStringList lst = line.split(" ",qucs::SkipEmptyParts); QString name = lst.takeFirst(); int idx = name.indexOf(':'); - name = name.right(name.count()-idx-1); // name + name = name.right(name.size()-idx-1); // name QString K = lst.takeFirst(); QString A = lst.takeFirst(); s += QString("D%1 %2 %3 DMOD_%4 \n").arg(name).arg(A).arg(K).arg(name); @@ -171,7 +171,7 @@ QString qucs2spice::convert_mosfet(QString line, bool xyce) QStringList lst = line.split(" ",qucs::SkipEmptyParts); QString name = lst.takeFirst(); int idx = name.indexOf(':'); - name = name.right(name.count()-idx-1); // name + name = name.right(name.size()-idx-1); // name QString G = lst.takeFirst(); QString D = lst.takeFirst(); QString S = lst.takeFirst(); @@ -213,7 +213,7 @@ QString qucs2spice::convert_jfet(QString line, bool xyce) QStringList lst = line.split(" ",qucs::SkipEmptyParts); QString name = lst.takeFirst(); int idx = name.indexOf(':'); - name = name.right(name.count()-idx-1); // name + name = name.right(name.size()-idx-1); // name QString G = lst.takeFirst(); QString D = lst.takeFirst(); QString S = lst.takeFirst(); @@ -244,7 +244,7 @@ QString qucs2spice::convert_bjt(QString line) QStringList lst = line.split(" ",qucs::SkipEmptyParts); QString name = lst.takeFirst(); int idx = name.indexOf(':'); - name = name.right(name.count()-idx-1); // name + name = name.right(name.size()-idx-1); // name QString B = lst.takeFirst(); QString C = lst.takeFirst(); QString E = lst.takeFirst(); @@ -294,7 +294,7 @@ QString qucs2spice::convert_ccs(const QString& line, bool voltage) QStringList lst = line.split(" ",qucs::SkipEmptyParts); QString name = lst.takeFirst(); int idx = name.indexOf(':'); - name = name.right(name.count()-idx-1); // name + name = name.right(name.size()-idx-1); // name QString nod0 = lst.takeFirst(); QString nod1 = lst.takeFirst(); @@ -302,7 +302,7 @@ QString qucs2spice::convert_ccs(const QString& line, bool voltage) QString nod3 = lst.takeFirst(); QString s1 = lst.takeFirst().remove("\""); idx = s1.indexOf('='); - QString val = s1.right(s1.count()-idx-1); + QString val = s1.right(s1.size()-idx-1); QString s; if (voltage) s="H"; else s="F"; @@ -326,7 +326,7 @@ QString qucs2spice::convert_vcs(const QString& line,bool voltage) QStringList lst = line.split(" ",qucs::SkipEmptyParts); QString name = lst.takeFirst(); int idx = name.indexOf(':'); - name = name.right(name.count()-idx-1); // name + name = name.right(name.size()-idx-1); // name QString nod0 = lst.takeFirst(); QString nod1 = lst.takeFirst(); @@ -334,7 +334,7 @@ QString qucs2spice::convert_vcs(const QString& line,bool voltage) QString nod3 = lst.takeFirst(); QString s1 = lst.takeFirst().remove("\""); idx = s1.indexOf('='); - QString val = s1.right(s1.count()-idx-1); + QString val = s1.right(s1.size()-idx-1); QString s; if (voltage) s="E"; @@ -353,7 +353,7 @@ QString qucs2spice::convert_dc_src(const QString& line) s += " " + lst.takeFirst() + " "; s1 = lst.takeFirst().remove("\""); int idx = s1.indexOf('='); - QString val = s1.right(s1.count()-idx-1); + QString val = s1.right(s1.size()-idx-1); s += "DC " + val + "\n"; return s; } diff --git a/qucs/extsimkernels/spicecompat.cpp b/qucs/extsimkernels/spicecompat.cpp index 87bfa3a9b..601b5ccf4 100644 --- a/qucs/extsimkernels/spicecompat.cpp +++ b/qucs/extsimkernels/spicecompat.cpp @@ -233,7 +233,7 @@ void spicecompat::convertNodeNames(QStringList &tokens, QString &sim) if ((it->endsWith(".V"))||(it->endsWith(".I"))) sim = "dc"; QString suffix = it->section('.',1,1); int idx = it->indexOf('.'); - int cnt = it->count(); + int cnt = it->size(); it->chop(cnt-idx); if (suffix.toUpper().startsWith("I")) *it = QString("V%1#branch").arg(*it); diff --git a/qucs/imagewriter.cpp b/qucs/imagewriter.cpp index 5235fe666..52cd578e9 100644 --- a/qucs/imagewriter.cpp +++ b/qucs/imagewriter.cpp @@ -371,8 +371,8 @@ void ImageWriter::getSelAreaWidthAndHeight(Schematic *sch, int &wsel, int &hsel, pd->Bounding(x1,y1,x2,y2); updateMinMax(xmin,xmax,ymin,ymax,x1,x2,y1,y2); - for (auto& pg: qAsConst(pd->Graphs)) { - for (auto& pm: qAsConst(pg->Markers)) { + for (auto& pg: std::as_const(pd->Graphs)) { + for (auto& pm: std::as_const(pg->Markers)) { if (pm->isSelected) { //int x1,y1,x2,y2; pm->Bounding(x1,y1,x2,y2); diff --git a/qucs/main.cpp b/qucs/main.cpp index 3c35433ed..a3a0f63ea 100644 --- a/qucs/main.cpp +++ b/qucs/main.cpp @@ -92,10 +92,22 @@ bool loadSettings() if(settings.contains("LargeFontSize"))QucsSettings.largeFontSize=settings.value("LargeFontSize").toDouble(); // use toDouble() as it can interpret the string according to the current locale if(settings.contains("maxUndo"))QucsSettings.maxUndo=settings.value("maxUndo").toInt(); if(settings.contains("NodeWiring"))QucsSettings.NodeWiring=settings.value("NodeWiring").toInt(); - if(settings.contains("BGColor"))QucsSettings.BGColor.setNamedColor(settings.value("BGColor").toString()); if(settings.contains("Editor"))QucsSettings.Editor=settings.value("Editor").toString(); if(settings.contains("FileTypes"))QucsSettings.FileTypes=settings.value("FileTypes").toStringList(); if(settings.contains("Language"))QucsSettings.Language=settings.value("Language").toString(); +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + if(settings.contains("BGColor"))QucsSettings.BGColor.fromString(settings.value("BGColor").toString()); + if(settings.contains("Comment"))QucsSettings.Comment.fromString(settings.value("Comment").toString()); + if(settings.contains("String"))QucsSettings.String.fromString(settings.value("String").toString()); + if(settings.contains("Integer"))QucsSettings.Integer.fromString(settings.value("Integer").toString()); + if(settings.contains("Real"))QucsSettings.Real.fromString(settings.value("Real").toString()); + if(settings.contains("Character"))QucsSettings.Character.fromString(settings.value("Character").toString()); + if(settings.contains("Type"))QucsSettings.Type.fromString(settings.value("Type").toString()); + if(settings.contains("Attribute"))QucsSettings.Attribute.fromString(settings.value("Attribute").toString()); + if(settings.contains("Directive"))QucsSettings.Directive.fromString(settings.value("Directive").toString()); + if(settings.contains("Task"))QucsSettings.Task.fromString(settings.value("Task").toString()); +#else + if(settings.contains("BGColor"))QucsSettings.BGColor.setNamedColor(settings.value("BGColor").toString()); if(settings.contains("Comment"))QucsSettings.Comment.setNamedColor(settings.value("Comment").toString()); if(settings.contains("String"))QucsSettings.String.setNamedColor(settings.value("String").toString()); if(settings.contains("Integer"))QucsSettings.Integer.setNamedColor(settings.value("Integer").toString()); @@ -105,6 +117,7 @@ bool loadSettings() if(settings.contains("Attribute"))QucsSettings.Attribute.setNamedColor(settings.value("Attribute").toString()); if(settings.contains("Directive"))QucsSettings.Directive.setNamedColor(settings.value("Directive").toString()); if(settings.contains("Task"))QucsSettings.Task.setNamedColor(settings.value("Task").toString()); +#endif if (settings.contains("panelIconsTheme")) QucsSettings.panelIconsTheme = settings.value("panelIconsTheme").toInt(); else QucsSettings.panelIconsTheme = qucs::autoIcons; @@ -823,8 +836,8 @@ int main(int argc, char *argv[]) QucsSettings.maxUndo = 20; QucsSettings.NodeWiring = 0; - QApplication::setAttribute(Qt::AA_EnableHighDpiScaling,true); #if QT_VERSION < 0x060000 + QApplication::setAttribute(Qt::AA_EnableHighDpiScaling,true); QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps,true); #endif diff --git a/qucs/mouseactions.cpp b/qucs/mouseactions.cpp index 26be53162..b7c17848d 100644 --- a/qucs/mouseactions.cpp +++ b/qucs/mouseactions.cpp @@ -75,8 +75,13 @@ MouseActions::MouseActions(QucsApp* App_) // ............................................................... // initialize menu appearing by right mouse button click on component ComponentMenu = new QMenu(QucsMain); +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + focusMEvent = new QMouseEvent(QEvent::MouseButtonPress, QPoint(0,0), QPoint(0,0), + Qt::NoButton, Qt::NoButton, Qt::NoModifier); +#else focusMEvent = new QMouseEvent(QEvent::MouseButtonPress, QPoint(0,0), Qt::NoButton, Qt::NoButton, Qt::NoModifier); +#endif } diff --git a/qucs/paintings/arrow.cpp b/qucs/paintings/arrow.cpp index 3aff065a3..cb48a8e43 100644 --- a/qucs/paintings/arrow.cpp +++ b/qucs/paintings/arrow.cpp @@ -177,7 +177,11 @@ bool Arrow::load(const QString& s) n = s.section(' ',7,7); // color QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Pen.setColor(co); if(!Pen.color().isValid()) return false; diff --git a/qucs/paintings/ellipse.cpp b/qucs/paintings/ellipse.cpp index 027101de2..146ece475 100644 --- a/qucs/paintings/ellipse.cpp +++ b/qucs/paintings/ellipse.cpp @@ -138,7 +138,11 @@ bool qucs::Ellipse::load(const QString& s) n = s.section(' ',5,5); // color QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Pen.setColor(co); if(!Pen.color().isValid()) return false; @@ -151,7 +155,11 @@ bool qucs::Ellipse::load(const QString& s) if(!ok) return false; n = s.section(' ',8,8); // fill color +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Brush.setColor(co); if(!Brush.color().isValid()) return false; diff --git a/qucs/paintings/ellipsearc.cpp b/qucs/paintings/ellipsearc.cpp index 04409e641..0ddfbb2da 100644 --- a/qucs/paintings/ellipsearc.cpp +++ b/qucs/paintings/ellipsearc.cpp @@ -129,7 +129,11 @@ bool EllipseArc::load(const QString& s) n = s.section(' ',7,7); // color QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Pen.setColor(co); if(!Pen.color().isValid()) return false; diff --git a/qucs/paintings/graphicline.cpp b/qucs/paintings/graphicline.cpp index 99663ea5d..c857a9b3e 100644 --- a/qucs/paintings/graphicline.cpp +++ b/qucs/paintings/graphicline.cpp @@ -120,7 +120,11 @@ bool GraphicLine::load(const QString& s) n = s.section(' ',5,5); // color QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Pen.setColor(co); if(!Pen.color().isValid()) return false; diff --git a/qucs/paintings/graphictext.cpp b/qucs/paintings/graphictext.cpp index 9875a4352..575ef87bc 100644 --- a/qucs/paintings/graphictext.cpp +++ b/qucs/paintings/graphictext.cpp @@ -156,7 +156,11 @@ bool GraphicText::load(const QString& s) if(!ok) return false; n = s.section(' ',4,4); // Color +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + Color.fromString(n); +#else Color.setNamedColor(n); +#endif if(!Color.isValid()) return false; n = s.section(' ',5,5); // Angle diff --git a/qucs/paintings/rectangle.cpp b/qucs/paintings/rectangle.cpp index 01468ffc4..a9f80ad8c 100644 --- a/qucs/paintings/rectangle.cpp +++ b/qucs/paintings/rectangle.cpp @@ -137,7 +137,11 @@ bool qucs::Rectangle::load(const QString& s) n = s.section(' ',5,5); // color QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Pen.setColor(co); if(!Pen.color().isValid()) return false; @@ -150,7 +154,11 @@ bool qucs::Rectangle::load(const QString& s) if(!ok) return false; n = s.section(' ',8,8); // fill color +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Brush.setColor(co); if(!Brush.color().isValid()) return false; diff --git a/qucs/schematic.cpp b/qucs/schematic.cpp index af7cbc36a..8a6113202 100644 --- a/qucs/schematic.cpp +++ b/qucs/schematic.cpp @@ -2245,11 +2245,13 @@ void Schematic::contentsDropEvent(QDropEvent *Event) #if QT_VERSION >= 0x060000 auto ev_pos = Event->position(); + QMouseEvent e(QEvent::MouseButtonPress, ev_pos, ev_pos, + Qt::LeftButton, Qt::NoButton, Qt::NoModifier); #else auto ev_pos = Event->pos(); -#endif QMouseEvent e(QEvent::MouseButtonPress, ev_pos, Qt::LeftButton, Qt::NoButton, Qt::NoModifier); +#endif int x = int(ev_pos.x()/Scale) + ViewX1; int y = int(ev_pos.y()/Scale) + ViewY1; @@ -2343,8 +2345,8 @@ void Schematic::contentsDragMoveEvent(QDragMoveEvent *Event) } #if QT_VERSION >= 0x060000 - QMouseEvent e(QEvent::MouseMove, Event->position(), Qt::NoButton, - Qt::NoButton, Qt::NoModifier); + QMouseEvent e(QEvent::MouseMove, Event->position(), Event->position(), + Qt::NoButton, Qt::NoButton, Qt::NoModifier); #else QMouseEvent e(QEvent::MouseMove, Event->pos(), Qt::NoButton, Qt::NoButton, Qt::NoModifier); diff --git a/qucs/symbolwidget.cpp b/qucs/symbolwidget.cpp index 7b886856c..7c1edca7e 100644 --- a/qucs/symbolwidget.cpp +++ b/qucs/symbolwidget.cpp @@ -591,7 +591,11 @@ int SymbolWidget::analyseLine(const QString& Row) } else if(s == "Text") { // must be last in order to reuse "s" ********* if(!getCompLineIntegers(Row, &i1, &i2, &i3)) return -1; - Color.setNamedColor(Row.section(' ',4,4)); +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + Color.fromString(Row.section(' ', 4, 4)); +#else + Color.setNamedColor(Row.section(' ', 4, 4)); +#endif if(!Color.isValid()) return -1; s = Row.mid(Row.indexOf('"')+1); // Text (can contain " !!!) @@ -627,7 +631,11 @@ bool SymbolWidget::getPen(const QString& s, QPen& Pen, int i) n = s.section(' ',i,i); // color QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Pen.setColor(co); if(!Pen.color().isValid()) return false; @@ -652,7 +660,11 @@ bool SymbolWidget::getBrush(const QString& s, QBrush& Brush, int i) n = s.section(' ',i,i); // fill color QColor co; +#if QT_VERSION >= QT_VERSION_CHECK(6, 4, 0) + co.fromString(n); +#else co.setNamedColor(n); +#endif Brush.setColor(co); if(!Brush.color().isValid()) return false;