Skip to content

Commit

Permalink
Port away from deprecated Qt6 methods and constuctors
Browse files Browse the repository at this point in the history
Fixes #375 (part 2)
  • Loading branch information
BSDKaffee committed Nov 22, 2023
1 parent 3d411fd commit be42e72
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 20 deletions.
12 changes: 12 additions & 0 deletions qucs/components/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 " !!!)
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions qucs/diagrams/diagram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions qucs/diagrams/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qucs/extsimkernels/abstractspicekernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions qucs/extsimkernels/qucs2spice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -294,15 +294,15 @@ 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();
QString nod2 = lst.takeFirst();
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";
Expand All @@ -326,15 +326,15 @@ 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();
QString nod2 = lst.takeFirst();
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";
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion qucs/extsimkernels/spicecompat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions qucs/imagewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 15 additions & 2 deletions qucs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions qucs/mouseactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand Down
4 changes: 4 additions & 0 deletions qucs/paintings/arrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions qucs/paintings/ellipse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions qucs/paintings/ellipsearc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions qucs/paintings/graphicline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions qucs/paintings/graphictext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions qucs/paintings/rectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions qucs/schematic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion qucs/symbolwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 " !!!)
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down

0 comments on commit be42e72

Please sign in to comment.