From fa98027215ea9315624cd64bcb3adbafe431df02 Mon Sep 17 00:00:00 2001 From: GravisZro Date: Sun, 10 Sep 2023 13:43:38 -0400 Subject: [PATCH 1/5] Safety/Initialization/Deletion fixes. Many variables were not initialized or were initialized only after complex code execution. Variables (especially pointers!!!) should ALWAYS be initialized at the start of the constructor in order to avoid uninitialized values while debugging code in the constructor. Always assign deleted pointers to nullptr for extra safety. I know it's against your style but I very much hope you adopt this style because it will save you from finding yourself in "impossible" situations. --- src/kicad/itemmodel/componentlibitemmodel.cpp | 22 ++++++----- src/kicad/itemmodel/componentlibtreeview.cpp | 16 ++++---- .../itemmodel/componentpinsitemmodel.cpp | 11 +++--- .../itemmodel/componentpinstableview.cpp | 7 +++- src/kicad/itemmodel/pinlisteditor.cpp | 4 +- src/kicad/ksseditor/ksseditor.cpp | 6 ++- src/kicad/model/component.cpp | 25 ++++++++++-- src/kicad/model/drawarc.cpp | 3 ++ src/kicad/model/drawcircle.cpp | 1 + src/kicad/model/lib.cpp | 2 + src/kicad/model/pad.cpp | 8 +++- src/kicad/model/pin.cpp | 4 +- src/kicad/parser/kicadlibparser.cpp | 35 ++++++++++------- src/kicad/pinruler/classrule.cpp | 35 +++++++++-------- src/kicad/pinruler/pinclass.cpp | 6 +-- src/kicad/pinruler/pinclassitem.cpp | 4 +- src/kicad/pinruler/pinrule.cpp | 19 +++++----- src/kicad/pinruler/pinruler.cpp | 12 ++++-- src/kicad/pinruler/rule.cpp | 5 ++- src/kicad/pinruler/rulesparser.cpp | 6 ++- src/kicad/pinruler/rulesset.cpp | 2 + src/kicad/schematicsimport/textimporter.cpp | 1 - src/kicad/viewer/componentitem.cpp | 4 +- src/kicad/viewer/componentscene.cpp | 13 ++++--- src/kicad/viewer/componentviewer.cpp | 4 +- src/kicad/viewer/componentwidget.cpp | 11 +++++- src/kicad/viewer/drawcircleitem.cpp | 3 +- src/kicad/viewer/drawitem.cpp | 2 +- src/kicad/viewer/drawpolyitem.cpp | 3 +- src/kicad/viewer/drawrectitem.cpp | 3 +- src/kicad/viewer/drawtextitem.cpp | 17 +++++++-- src/kicad/viewer/drawtextitem.h | 3 ++ src/kicad/viewer/kicadfont.cpp | 3 +- src/kicad/viewer/pinitem.cpp | 38 ++++++++++++++----- src/pdf_extract/controller/pdfloader.cpp | 10 ++++- src/pdf_extract/datasheet.cpp | 28 +++++++++++--- src/pdf_extract/datasheetbox.h | 1 - src/pdf_extract/datasheetpin.cpp | 14 ++++++- src/pdf_extract/model/pdfdatasheet.cpp | 8 +++- src/pdf_extract/model/pdfpage.cpp | 2 + src/pdf_extract/model/pdftextbox.cpp | 10 ++--- .../pdfdebugwidget/pdfdebugitempage.cpp | 3 +- .../pdfdebugwidget/pdfdebugviewer.cpp | 3 +- .../pdfdebugwidget/pdfdebugwidget.cpp | 19 ++++++++-- src/uconfig_gui/componentinfoseditor.cpp | 7 +++- src/uconfig_gui/importer/componentspage.cpp | 17 ++++++++- .../importer/datasheetprocesspage.cpp | 11 +++++- src/uconfig_gui/importer/datasheetthread.cpp | 7 ++-- src/uconfig_gui/importer/filepage.cpp | 12 ++++-- src/uconfig_gui/importer/pdffilepage.cpp | 9 ++++- src/uconfig_gui/importer/pinlistimporter.cpp | 3 +- src/uconfig_gui/importer/pinlistimporter.h | 1 + src/uconfig_gui/importer/resultspage.cpp | 3 +- src/uconfig_gui/importer/startwizardpage.cpp | 4 +- src/uconfig_gui/project/uconfigproject.cpp | 7 ++-- src/uconfig_gui/uconfigmainwindow.cpp | 13 ++++++- 56 files changed, 372 insertions(+), 158 deletions(-) diff --git a/src/kicad/itemmodel/componentlibitemmodel.cpp b/src/kicad/itemmodel/componentlibitemmodel.cpp index 67c6375..ffd4d21 100644 --- a/src/kicad/itemmodel/componentlibitemmodel.cpp +++ b/src/kicad/itemmodel/componentlibitemmodel.cpp @@ -22,18 +22,17 @@ #include ComponentLibItemModel::ComponentLibItemModel(Lib *lib, QObject *parent) - : QAbstractItemModel(parent) + : QAbstractItemModel(parent), + _lib(nullptr), + _activeComponent(nullptr), + _selectedMode(false) { - if (lib != nullptr) + if (lib == nullptr) { - _lib = lib; + lib = new Lib(); } - else - { - _lib = new Lib(); - } - _selectedMode = false; - _activeComponent = nullptr; + + _lib = lib; } Lib *ComponentLibItemModel::lib() const @@ -47,7 +46,10 @@ void ComponentLibItemModel::setLib(Lib *lib) _activeComponent = nullptr; beginResetModel(); resetInternalData(); - // delete _lib; + if(lib != nullptr) + { + delete _lib; + } _lib = lib; endResetModel(); emit layoutChanged(); diff --git a/src/kicad/itemmodel/componentlibtreeview.cpp b/src/kicad/itemmodel/componentlibtreeview.cpp index e1776c0..d3ef20d 100644 --- a/src/kicad/itemmodel/componentlibtreeview.cpp +++ b/src/kicad/itemmodel/componentlibtreeview.cpp @@ -24,17 +24,19 @@ #include ComponentLibTreeView::ComponentLibTreeView(Lib *lib, QWidget *parent) - : QTreeView(parent) + : QTreeView(parent), + _model(nullptr), + _sortProxy(nullptr), + _editMode(false), + _removeAction(nullptr) { - if (lib != nullptr) + if (lib == nullptr) { - _model = new ComponentLibItemModel(lib); - } - else - { - _model = new ComponentLibItemModel(new Lib()); + lib = new Lib(); } + _model = new ComponentLibItemModel(lib); + setSelectionMode(QAbstractItemView::ExtendedSelection); _editMode = false; diff --git a/src/kicad/itemmodel/componentpinsitemmodel.cpp b/src/kicad/itemmodel/componentpinsitemmodel.cpp index 9179e96..e610a18 100644 --- a/src/kicad/itemmodel/componentpinsitemmodel.cpp +++ b/src/kicad/itemmodel/componentpinsitemmodel.cpp @@ -24,11 +24,12 @@ #include ComponentPinsItemModel::ComponentPinsItemModel(Component *component, QObject *parent) - : QAbstractItemModel(parent) + : QAbstractItemModel(parent), + _component(nullptr), + _isExpendable(true) { setComponent(component); - _isExpendable = true; - _higherPin = QString(); + _higherPin.clear(); } Component *ComponentPinsItemModel::component() const @@ -317,8 +318,8 @@ QString ComponentPinsItemModel::toNumeric(const QString &str) void ComponentPinsItemModel::updateHigherPin() { - _higherPin = QString(); - QString higherNumPin = QString(); + QString higherNumPin; + _higherPin.clear(); if (_component != nullptr) { for (Pin *pin : _component->pins()) diff --git a/src/kicad/itemmodel/componentpinstableview.cpp b/src/kicad/itemmodel/componentpinstableview.cpp index 1d2ee48..6e51039 100644 --- a/src/kicad/itemmodel/componentpinstableview.cpp +++ b/src/kicad/itemmodel/componentpinstableview.cpp @@ -25,7 +25,12 @@ #include ComponentPinsTableView::ComponentPinsTableView(Component *component, QWidget *parent) - : QTableView(parent) + : QTableView(parent), + _model(nullptr), + _delegate(nullptr), + _sortProxy(nullptr), + _removeAction(nullptr), + _copyAction(nullptr) { _model = new ComponentPinsItemModel(component); diff --git a/src/kicad/itemmodel/pinlisteditor.cpp b/src/kicad/itemmodel/pinlisteditor.cpp index 070d903..a693049 100644 --- a/src/kicad/itemmodel/pinlisteditor.cpp +++ b/src/kicad/itemmodel/pinlisteditor.cpp @@ -22,7 +22,9 @@ #include PinListEditor::PinListEditor(QWidget *parent) - : QWidget(parent) + : QWidget(parent), + _componentPinsTableView(nullptr), + _nameFilterEdit(nullptr) { createWidgets(); } diff --git a/src/kicad/ksseditor/ksseditor.cpp b/src/kicad/ksseditor/ksseditor.cpp index 9036629..1087665 100644 --- a/src/kicad/ksseditor/ksseditor.cpp +++ b/src/kicad/ksseditor/ksseditor.cpp @@ -22,7 +22,10 @@ #include KssEditor::KssEditor(QWidget *parent) - : QPlainTextEdit(parent) + : QPlainTextEdit(parent), + _syntax(nullptr), + _kssEditorMargin(nullptr), + _lineError(-1) { _syntax = new KSSSyntax(this->document()); @@ -36,7 +39,6 @@ KssEditor::KssEditor(QWidget *parent) font.setStyleHint(QFont::Monospace); setFont(font); - _lineError = -1; updateExtraSelection(); } diff --git a/src/kicad/model/component.cpp b/src/kicad/model/component.cpp index aaf45e2..9129b2e 100644 --- a/src/kicad/model/component.cpp +++ b/src/kicad/model/component.cpp @@ -29,11 +29,15 @@ * @param name optionally specify the component name at the creation */ Component::Component(const QString &name) - : _prefix("U") + : _prefix("U"), + _showPinName(true), + _showPadName(true), + _unitCount(1), + _refText(nullptr), + _nameText(nullptr), + _packageText(nullptr), + _docText(nullptr) { - _showPinName = true; - _showPadName = true; - _unitCount = 1; _refText = new DrawText("U"); _nameText = new DrawText(); _packageText = new DrawText(); @@ -80,15 +84,24 @@ Component::~Component() for (auto &pin : _pins) { delete pin; + pin = nullptr; } for (auto &draw : _draws) { delete draw; + draw = nullptr; } delete _refText; + _refText = nullptr; + delete _nameText; + _nameText = nullptr; + delete _packageText; + _packageText = nullptr; + delete _docText; + _docText = nullptr; } /** @@ -149,6 +162,7 @@ void Component::removePin(Pin *pin) if (_pins.removeOne(pin)) { delete pin; + pin = nullptr; } } @@ -160,6 +174,7 @@ void Component::clearPins() for (auto &pin : _pins) { delete pin; + pin = nullptr; } _pins.clear(); } @@ -211,6 +226,7 @@ void Component::removeDraw(Draw *draw) if (_draws.removeOne(draw)) { delete draw; + draw = nullptr; } } @@ -222,6 +238,7 @@ void Component::clearDraws() for (auto &draw : _draws) { delete draw; + draw = nullptr; } _draws.clear(); } diff --git a/src/kicad/model/drawarc.cpp b/src/kicad/model/drawarc.cpp index b9009f4..0a09f23 100644 --- a/src/kicad/model/drawarc.cpp +++ b/src/kicad/model/drawarc.cpp @@ -19,6 +19,9 @@ #include "drawarc.h" DrawArc::DrawArc() + : _radius(0), + _startAngle(0), + _endAngle(0) { } diff --git a/src/kicad/model/drawcircle.cpp b/src/kicad/model/drawcircle.cpp index e261498..586c4b1 100644 --- a/src/kicad/model/drawcircle.cpp +++ b/src/kicad/model/drawcircle.cpp @@ -19,6 +19,7 @@ #include "drawcircle.h" DrawCircle::DrawCircle() + : _radius(0) { } diff --git a/src/kicad/model/lib.cpp b/src/kicad/model/lib.cpp index d1b5ccb..9d05b71 100644 --- a/src/kicad/model/lib.cpp +++ b/src/kicad/model/lib.cpp @@ -124,6 +124,7 @@ void Lib::removeComponent(Component *component) if (_components.removeOne(component)) { delete component; + component = nullptr; } } @@ -153,6 +154,7 @@ void Lib::clear() for (auto &component : _components) { delete component; + component = nullptr; } _components.clear(); } diff --git a/src/kicad/model/pad.cpp b/src/kicad/model/pad.cpp index 2764602..277c206 100644 --- a/src/kicad/model/pad.cpp +++ b/src/kicad/model/pad.cpp @@ -21,7 +21,11 @@ #include Pad::Pad() - : _angle(0) + : _shape(Pad::Rect), + _angle(0.0), + _drillDiameter(0.0), + _type(Pad::Std), + _layers(0) { } @@ -118,7 +122,7 @@ Pad::Type Pad::type() const QString Pad::typeString() const { - switch (_shape) + switch (_type) { case Pad::Std: return "STD"; diff --git a/src/kicad/model/pin.cpp b/src/kicad/model/pin.cpp index c68397f..47ee139 100644 --- a/src/kicad/model/pin.cpp +++ b/src/kicad/model/pin.cpp @@ -22,7 +22,7 @@ Pin::Pin() : _pinType(Pin::Normal), - _electricalType(Pin::Input) + _electricalType(Pin::Unspecified) { _angle = 0; _unit = 1; @@ -36,7 +36,7 @@ Pin::Pin(const QString &name, const QString &padName) : _name(name), _padName(padName), _pinType(Pin::Normal), - _electricalType(Pin::Input) + _electricalType(Pin::Unspecified) { _angle = 0; _unit = 1; diff --git a/src/kicad/parser/kicadlibparser.cpp b/src/kicad/parser/kicadlibparser.cpp index 19d2160..d5c5b57 100644 --- a/src/kicad/parser/kicadlibparser.cpp +++ b/src/kicad/parser/kicadlibparser.cpp @@ -47,6 +47,7 @@ Lib *KicadLibParser::loadLib(const QString &fileName, Lib *lib) if (mylib) { delete lib; + lib = nullptr; } return nullptr; } @@ -55,7 +56,7 @@ Lib *KicadLibParser::loadLib(const QString &fileName, Lib *lib) _stream.readLine(); lib->clear(); - Component *component; + Component *component = nullptr; do { component = readComponent(); @@ -241,8 +242,8 @@ void KicadLibParser::writePin(Pin *pin) void KicadLibParser::writeDraw(Draw *draw) { - DrawRect *drawRect; - DrawText *drawText; + DrawRect *drawRect = nullptr; + DrawText *drawText = nullptr; switch (draw->type()) { @@ -566,6 +567,7 @@ Component *KicadLibParser::readComponent() } while (!_stream.atEnd()); delete component; + component = nullptr; return nullptr; } @@ -584,6 +586,7 @@ Pin *KicadLibParser::readPin() if (_stream.status() != QTextStream::Ok) { delete pin; + pin = nullptr; return nullptr; } pin->setName(name); @@ -594,51 +597,55 @@ Pin *KicadLibParser::readPin() if (_stream.status() != QTextStream::Ok) { delete pin; + pin = nullptr; return nullptr; } pin->setPadName(padName); // position - int x; - int y; + int x = 0; + int y = 0; _stream >> x >> y; if (_stream.status() != QTextStream::Ok) { delete pin; + pin = nullptr; return nullptr; } pin->setPos(x, -y); // lenght - int lenght; + int lenght = 0; _stream >> lenght; if (_stream.status() != QTextStream::Ok) { delete pin; + pin = nullptr; return nullptr; } pin->setLength(lenght); // orientation - char directionChar; + char directionChar = 0; _stream.skipWhiteSpace(); _stream >> directionChar; pin->setAngle(pinAngle(directionChar)); // text size - int textNameSize; - int textPadSize; + int textNameSize = 0; + int textPadSize = 0; _stream >> textPadSize; _stream >> textNameSize; pin->setTextNameSize(textNameSize); pin->setTextPadSize(textPadSize); // layer - int layer; + int layer = 0; _stream >> layer; if (_stream.status() != QTextStream::Ok) { delete pin; + pin = nullptr; return nullptr; } pin->setUnit(layer); @@ -662,8 +669,8 @@ Pin *KicadLibParser::readPin() Draw *KicadLibParser::readDraw(char c) { - int n; - char nc; + int n = 0; + char nc = 0; QString text; _stream.resetStatus(); @@ -1016,7 +1023,7 @@ QString KicadLibParser::pinElectricalTypeString(Pin::ElectricalType electricalTy int KicadLibParser::pinAngle(char directionChar) { - int angle; + int angle = 0; switch (directionChar) { default: @@ -1084,7 +1091,7 @@ Pin::PinType KicadLibParser::pinType(const QString &pinTypeString) const Pin::ElectricalType KicadLibParser::pinElectricalType(char electricalTypeChar) const { - Pin::ElectricalType electricalType; + Pin::ElectricalType electricalType = Pin::NotConnected; switch (electricalTypeChar) { case 'I': diff --git a/src/kicad/pinruler/classrule.cpp b/src/kicad/pinruler/classrule.cpp index 3b77900..c0c0dbe 100644 --- a/src/kicad/pinruler/classrule.cpp +++ b/src/kicad/pinruler/classrule.cpp @@ -45,31 +45,30 @@ QStringList ClassRule::boolEnumStr = QStringList() << "false" << "true"; ClassRule::ClassRule(const QString &selector) - : Rule(selector) -{ - _position = PositionASide; - _positionSet = false; + : Rule(selector), + _position(PositionASide), + _positionSet(false), - _sort = SortAsc; - _sortSet = false; + _sort(SortAsc), + _sortSet(false), - _sortPattern = ".*"; - _sortPatternSet = false; + _sortPattern(".*"), + _sortPatternSet(false), - _length = 200; - _lengthSet = false; + _length(200), + _lengthSet(false), - _priority = 0; - _prioritySet = false; + _priority(0), + _prioritySet(false), - _visibility = VisibilityVisible; - _visibilitySet = false; + _visibility(VisibilityVisible), + _visibilitySet(false), - _label = ""; - _labelSet = false; + _labelSet(false), - _rect = 0; - _rectSet = false; + _rect(0), + _rectSet(false) +{ } Rule::Type ClassRule::type() const diff --git a/src/kicad/pinruler/pinclass.cpp b/src/kicad/pinruler/pinclass.cpp index d37bcdb..e834c8d 100644 --- a/src/kicad/pinruler/pinclass.cpp +++ b/src/kicad/pinruler/pinclass.cpp @@ -25,9 +25,9 @@ #include "viewer/kicadfont.h" PinClass::PinClass(QString className) - : _className(std::move(className)) + : _className(std::move(className)), + _brect(false) { - _brect = false; } QString PinClass::className() const @@ -193,7 +193,7 @@ void PinClass::setPos(const QPoint &basePos) QPoint pinPos = basePos; QPoint offset; QPoint translate; - int angle; + int angle = 0; switch (_position) { diff --git a/src/kicad/pinruler/pinclassitem.cpp b/src/kicad/pinruler/pinclassitem.cpp index 813817b..c9c87b5 100644 --- a/src/kicad/pinruler/pinclassitem.cpp +++ b/src/kicad/pinruler/pinclassitem.cpp @@ -21,9 +21,9 @@ #include PinClassItem::PinClassItem(Pin *pin) - : _pin(pin) + : _pin(pin), + _priority(0) { - _priority = 0; } Pin *PinClassItem::pin() const diff --git a/src/kicad/pinruler/pinrule.cpp b/src/kicad/pinruler/pinrule.cpp index aff7e5e..5be4026 100644 --- a/src/kicad/pinruler/pinrule.cpp +++ b/src/kicad/pinruler/pinrule.cpp @@ -49,18 +49,19 @@ QStringList PinRule::pinTypeEnumStr = QStringList() << "norm" << "nologic"; PinRule::PinRule(const QString &selector) - : Rule(selector) -{ - _classSet = false; + : Rule(selector), + + _classSet(false), - _elecType = Pin::Input; - _elecTypeSet = false; + _elecType(Pin::Input), + _elecTypeSet(false), - _pinType = Pin::Normal; - _pinTypeSet = false; + _pinType(Pin::Normal), + _pinTypeSet(false), - _priority = 0; - _prioritySet = false; + _priority(0), + _prioritySet(false) +{ } Rule::Type PinRule::type() const diff --git a/src/kicad/pinruler/pinruler.cpp b/src/kicad/pinruler/pinruler.cpp index af7f388..4d6bff0 100644 --- a/src/kicad/pinruler/pinruler.cpp +++ b/src/kicad/pinruler/pinruler.cpp @@ -24,8 +24,8 @@ #include "model/drawrect.h" PinRuler::PinRuler(RulesSet *ruleSet) + : _ruleSet(ruleSet) { - _ruleSet = ruleSet; } bool nameGreaterThan(PinClass *c1, PinClass *c2) @@ -53,8 +53,8 @@ bool prioGreaterThan(PinClass *c1, PinClass *c2) void PinRuler::organize(Component *component) { - int x; - int y; + int x = -1; + int y = -1; component->clearDraws(); @@ -340,6 +340,7 @@ void PinRuler::organize(Component *component) for (PinClass *mpinClass : _pinClasses) { delete mpinClass; + mpinClass = nullptr; } _pinClasses.clear(); } @@ -351,7 +352,10 @@ RulesSet *PinRuler::ruleSet() const void PinRuler::setRuleSet(RulesSet *ruleSet) { - delete _ruleSet; + if(_ruleSet != nullptr) + { + delete _ruleSet; + } _ruleSet = ruleSet; } diff --git a/src/kicad/pinruler/rule.cpp b/src/kicad/pinruler/rule.cpp index 0a8a191..2aaacee 100644 --- a/src/kicad/pinruler/rule.cpp +++ b/src/kicad/pinruler/rule.cpp @@ -21,9 +21,10 @@ #include Rule::Rule(const QString &selector) - : _selector(selector, QRegularExpression::CaseInsensitiveOption) + : _selector(selector, QRegularExpression::CaseInsensitiveOption), + _enabled(true), + _line(-1) { - _enabled = true; } Rule::~Rule() diff --git a/src/kicad/pinruler/rulesparser.cpp b/src/kicad/pinruler/rulesparser.cpp index 9a301d3..1e3dd15 100644 --- a/src/kicad/pinruler/rulesparser.cpp +++ b/src/kicad/pinruler/rulesparser.cpp @@ -25,8 +25,10 @@ #include RulesParser::RulesParser(const QString &fileName) + : _id(-1), + _line(-1), + _errorLine(-1) { - _errorLine = -1; _fileName = fileName; if (!fileName.isEmpty()) { @@ -82,6 +84,7 @@ bool RulesParser::parse(RulesSet *ruleSet) { _errorLine = _line; delete rule; + rule = nullptr; return false; // error } QString propertyValue; @@ -105,6 +108,7 @@ bool RulesParser::parse(RulesSet *ruleSet) { _errorLine = _line; delete rule; + rule = nullptr; return false; // error } diff --git a/src/kicad/pinruler/rulesset.cpp b/src/kicad/pinruler/rulesset.cpp index fb66b15..dd414ee 100644 --- a/src/kicad/pinruler/rulesset.cpp +++ b/src/kicad/pinruler/rulesset.cpp @@ -53,10 +53,12 @@ RulesSet::~RulesSet() for (auto &classRule : _classRules) { delete classRule; + classRule = nullptr; } for (auto &pinRule : _pinRules) { delete pinRule; + pinRule = nullptr; } } diff --git a/src/kicad/schematicsimport/textimporter.cpp b/src/kicad/schematicsimport/textimporter.cpp index 8d88846..575365a 100644 --- a/src/kicad/schematicsimport/textimporter.cpp +++ b/src/kicad/schematicsimport/textimporter.cpp @@ -134,7 +134,6 @@ bool TextImporter::import(const QString &fileName) } QString pinNumber = columns[_pinColumn]; - QStringList pinNameColumns; for (int column : qAsConst(_pinNameColumns)) { diff --git a/src/kicad/viewer/componentitem.cpp b/src/kicad/viewer/componentitem.cpp index cd7adc0..f080e83 100644 --- a/src/kicad/viewer/componentitem.cpp +++ b/src/kicad/viewer/componentitem.cpp @@ -28,9 +28,11 @@ const int ComponentItem::ratio = 5; ComponentItem::ComponentItem(Component *component, int unit) + : _component(nullptr), + _unit(0), + _showElectricalType(true) { setComponent(component, unit); - _showElectricalType = true; } void ComponentItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) diff --git a/src/kicad/viewer/componentscene.cpp b/src/kicad/viewer/componentscene.cpp index 461d4ac..8833084 100644 --- a/src/kicad/viewer/componentscene.cpp +++ b/src/kicad/viewer/componentscene.cpp @@ -22,12 +22,15 @@ #include ComponentScene::ComponentScene(qreal x, qreal y, qreal w, qreal h) - : QGraphicsScene(x, y, w, h) -{ - _grid = true; - _gridFront = false; - _prevGridSize = 0; + : QGraphicsScene(x, y, w, h), + _grid(true), + _gridFront(false), + _prevGridSize(0), + _elecType(false), + _component(nullptr), + _componentItem(nullptr) +{ setComponent(nullptr); } diff --git a/src/kicad/viewer/componentviewer.cpp b/src/kicad/viewer/componentviewer.cpp index a827658..1f415fb 100644 --- a/src/kicad/viewer/componentviewer.cpp +++ b/src/kicad/viewer/componentviewer.cpp @@ -30,7 +30,9 @@ #include ComponentViewer::ComponentViewer(QWidget *parent) - : QGraphicsView(parent) + : QGraphicsView(parent), + _scene(nullptr), + _currentZoomLevel(0.0) { _scene = new ComponentScene(-5000, -5000, 10000, 10000); setScene(_scene); diff --git a/src/kicad/viewer/componentwidget.cpp b/src/kicad/viewer/componentwidget.cpp index 27372ae..f246ad1 100644 --- a/src/kicad/viewer/componentwidget.cpp +++ b/src/kicad/viewer/componentwidget.cpp @@ -23,10 +23,17 @@ #include ComponentWidget::ComponentWidget(QWidget *parent) - : QWidget(parent) + : QWidget(parent), + _component(nullptr), + _viewer(nullptr), + _gridGroup(nullptr), + _actionNoGrid(nullptr), + _actionGrid(nullptr), + _actionGridFront(nullptr), + _actionElecType(nullptr), + _comboUnit(nullptr) { Q_INIT_RESOURCE(imgviewer); - _component = nullptr; createWidgets(); } diff --git a/src/kicad/viewer/drawcircleitem.cpp b/src/kicad/viewer/drawcircleitem.cpp index b8e72f7..ac4c525 100644 --- a/src/kicad/viewer/drawcircleitem.cpp +++ b/src/kicad/viewer/drawcircleitem.cpp @@ -24,7 +24,8 @@ #include DrawCircleItem::DrawCircleItem(DrawCircle *draw) - : DrawItem(draw) + : DrawItem(draw), + _drawCircle(nullptr) { setDraw(draw); setZValue(-1); diff --git a/src/kicad/viewer/drawitem.cpp b/src/kicad/viewer/drawitem.cpp index 5b1bb5e..ae8451a 100644 --- a/src/kicad/viewer/drawitem.cpp +++ b/src/kicad/viewer/drawitem.cpp @@ -29,8 +29,8 @@ #include "drawtextitem.h" DrawItem::DrawItem(Draw *draw) + : _draw(draw) { - _draw = draw; setZValue(-1); } diff --git a/src/kicad/viewer/drawpolyitem.cpp b/src/kicad/viewer/drawpolyitem.cpp index 9bd551c..6a8023d 100644 --- a/src/kicad/viewer/drawpolyitem.cpp +++ b/src/kicad/viewer/drawpolyitem.cpp @@ -24,7 +24,8 @@ #include DrawPolyItem::DrawPolyItem(DrawPoly *draw) - : DrawItem(draw) + : DrawItem(draw), + _drawPoly(nullptr) { setDraw(draw); setZValue(-1); diff --git a/src/kicad/viewer/drawrectitem.cpp b/src/kicad/viewer/drawrectitem.cpp index 3e79873..ef35453 100644 --- a/src/kicad/viewer/drawrectitem.cpp +++ b/src/kicad/viewer/drawrectitem.cpp @@ -24,7 +24,8 @@ #include DrawRectItem::DrawRectItem(DrawRect *draw) - : DrawItem(draw) + : DrawItem(draw), + _drawRect(nullptr) { setDraw(draw); setZValue(-1); diff --git a/src/kicad/viewer/drawtextitem.cpp b/src/kicad/viewer/drawtextitem.cpp index 60ce0f2..7e31f30 100644 --- a/src/kicad/viewer/drawtextitem.cpp +++ b/src/kicad/viewer/drawtextitem.cpp @@ -25,22 +25,33 @@ DrawTextItem::DrawTextItem(DrawText *draw, bool internal) : DrawItem(draw), + _drawText(nullptr), + _fontText(nullptr), _internal(internal) { - _fontText = nullptr; setDraw(draw); setZValue(10); } DrawTextItem::~DrawTextItem() { - delete _fontText; + deleteFontText(); +} + +void DrawTextItem::deleteFontText() +{ + if(_fontText != nullptr) + { + delete _fontText; + _fontText = nullptr; + } } void DrawTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { Q_UNUSED(option) Q_UNUSED(widget) + Q_ASSERT(_fontText != nullptr); painter->setRenderHint(QPainter::Antialiasing); painter->setRenderHint(QPainter::TextAntialiasing); @@ -81,7 +92,7 @@ void DrawTextItem::setDraw(DrawText *draw) { _drawText = draw; - delete _fontText; + deleteFontText(); _fontText = new KicadFont(_drawText->textSize() / ComponentItem::ratio); QFont font = _fontText->font(); diff --git a/src/kicad/viewer/drawtextitem.h b/src/kicad/viewer/drawtextitem.h index fc8559e..294642c 100644 --- a/src/kicad/viewer/drawtextitem.h +++ b/src/kicad/viewer/drawtextitem.h @@ -46,6 +46,9 @@ class KICAD_EXPORT DrawTextItem : public DrawItem void setDraw(DrawText *draw); +protected: + void deleteFontText(); + protected: DrawText *_drawText; QRectF _rect; diff --git a/src/kicad/viewer/kicadfont.cpp b/src/kicad/viewer/kicadfont.cpp index 420e450..92b4802 100644 --- a/src/kicad/viewer/kicadfont.cpp +++ b/src/kicad/viewer/kicadfont.cpp @@ -30,6 +30,7 @@ const int KicadFont::charWidthTable[] = {35, 20, 28, 38, 35, 42, 45, 20, 26, 26, 34, 20, 20, 30, 22, 48, 34, 34, 34, 33, 25, 30, 23, 34, 29, 39, 31, 29, 31, 26, 35, 26}; KicadFont::KicadFont(double size) + : _size(0.0) { setSize(size); } @@ -45,7 +46,7 @@ double KicadFont::charWidth(QChar c) const double KicadFont::textWidth(const QString &text) const { - double width = 0; + double width = 0.0; for (QChar c : text) { width += charWidth(c); diff --git a/src/kicad/viewer/pinitem.cpp b/src/kicad/viewer/pinitem.cpp index cc3a355..628b574 100644 --- a/src/kicad/viewer/pinitem.cpp +++ b/src/kicad/viewer/pinitem.cpp @@ -27,11 +27,12 @@ #include "model/component.h" PinItem::PinItem(Pin *pin) + : _pin(nullptr), + _fontPad(nullptr), + _fontName(nullptr), + _fontType(nullptr), + _showElectricalType(false) { - _fontPad = nullptr; - _fontName = nullptr; - _fontType = nullptr; - setPin(pin); setFlag(QGraphicsItem::ItemIsSelectable); setCursor(Qt::CrossCursor); @@ -40,9 +41,21 @@ PinItem::PinItem(Pin *pin) PinItem::~PinItem() { - delete _fontPad; - delete _fontName; - delete _fontType; + if(_fontPad != nullptr) + { + delete _fontPad; + _fontPad = nullptr; + } + if(_fontName != nullptr) + { + delete _fontName; + _fontName = nullptr; + } + if(_fontType != nullptr) + { + delete _fontType; + _fontType = nullptr; + } } void PinItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -299,13 +312,18 @@ void PinItem::setPin(Pin *pin) QString type = Pin::electricalTypeDesc(_pin->electricalType()); type[0] = type[0].toUpper(); - delete _fontPad; + if(_fontPad != nullptr) + delete _fontPad; _fontPad = new KicadFont(_pin->textPadSize() / ComponentItem::ratio); QFontMetrics metricsPad(_fontPad->font()); - delete _fontName; + + if(_fontName != nullptr) + delete _fontName; _fontName = new KicadFont(_pin->textNameSize() / ComponentItem::ratio); QFontMetrics metricsName(_fontName->font()); - delete _fontType; + + if(_fontType != nullptr) + delete _fontType; _fontType = new KicadFont(25.0 / ComponentItem::ratio); QFontMetrics metricsType(_fontType->font()); diff --git a/src/pdf_extract/controller/pdfloader.cpp b/src/pdf_extract/controller/pdfloader.cpp index 06ec863..4d3935f 100644 --- a/src/pdf_extract/controller/pdfloader.cpp +++ b/src/pdf_extract/controller/pdfloader.cpp @@ -24,7 +24,8 @@ #include PDFLoader::PDFLoader(PDFDatasheet *pdfDatasheet) - : _pdfDatasheet(pdfDatasheet) + : _document(nullptr), + _pdfDatasheet(pdfDatasheet) { _document = Poppler::Document::load(_pdfDatasheet->_fileName); _pdfDatasheet->_pageCount = _document->numPages(); @@ -37,7 +38,11 @@ PDFLoader::PDFLoader(PDFDatasheet *pdfDatasheet) PDFLoader::~PDFLoader() { - delete _document; + if(_document != nullptr) + { + delete _document; + _document = nullptr; + } } bool PDFLoader::loadPage(PDFPage *pdfPage) @@ -126,6 +131,7 @@ void PDFLoader::loadBoxes(PDFPage *pdfPage) } } delete ptextBox; + ptextBox = nullptr; } pdfPage->_boxesLoaded = true; } diff --git a/src/pdf_extract/datasheet.cpp b/src/pdf_extract/datasheet.cpp index 07d3b13..1416e88 100644 --- a/src/pdf_extract/datasheet.cpp +++ b/src/pdf_extract/datasheet.cpp @@ -32,10 +32,10 @@ using namespace Poppler; Datasheet::Datasheet() + : _doc(nullptr), + _debug(false), + _force(false) { - _doc = nullptr; - _debug = false; - _force = false; } Datasheet::~Datasheet() @@ -74,8 +74,11 @@ bool Datasheet::open(const QString &fileName) void Datasheet::close() { - delete _doc; - _doc = nullptr; + if(_doc != nullptr) + { + delete _doc; + _doc = nullptr; + } } void Datasheet::pinSearch(int numPage) @@ -216,6 +219,7 @@ void Datasheet::pinSearch(int numPage) { badcount++; delete package; + package = nullptr; continue; } // package pin 1 very far to pin 2 are deleted @@ -224,6 +228,7 @@ void Datasheet::pinSearch(int numPage) { badcount++; delete package; + package = nullptr; continue; } count++; @@ -420,7 +425,11 @@ QList Datasheet::extractPins(int numPage) else if (box->text.size() > 10 && (!box->text.contains("/") && !box->text.contains("_") && !box->text.contains(","))) { // qDebug()<<"filter long label"<text; - delete box; + if(box != nullptr) + { + delete box; + box = nullptr; + } box = new DatasheetBox(); box->page = numPage; } @@ -434,6 +443,7 @@ QList Datasheet::extractPins(int numPage) prev = false; } delete textBox; + textBox = nullptr; } // pairing label and number to pin @@ -493,6 +503,7 @@ QList Datasheet::extractPins(int numPage) } delete page; + page = nullptr; return pins; } @@ -558,6 +569,7 @@ void Datasheet::clean() for (DatasheetPackage *box : _packages) { delete box; + box = nullptr; } _packages.clear(); } @@ -646,14 +658,18 @@ int Datasheet::pagePinDiagram(int pageStart, int pageEnd, bool *bgaStyle) } } delete textBox; + textBox = nullptr; if (labelOk && (vssOk || vddOk)) { delete page; + page = nullptr; return i; } } delete page; + page = nullptr; + QCoreApplication::processEvents(); } diff --git a/src/pdf_extract/datasheetbox.h b/src/pdf_extract/datasheetbox.h index 6d08e86..f07bff6 100644 --- a/src/pdf_extract/datasheetbox.h +++ b/src/pdf_extract/datasheetbox.h @@ -46,7 +46,6 @@ class DATASHEET_EXTRACTOR_EXPORT DatasheetBox static bool isAlign(const DatasheetBox &label, const DatasheetBox &number); static int created; - static int deleted; }; #endif // DATASHEETBOX_H diff --git a/src/pdf_extract/datasheetpin.cpp b/src/pdf_extract/datasheetpin.cpp index a79bbc9..2b9cc39 100644 --- a/src/pdf_extract/datasheetpin.cpp +++ b/src/pdf_extract/datasheetpin.cpp @@ -19,13 +19,23 @@ #include "datasheetpin.h" DatasheetPin::DatasheetPin() + : numberBox(nullptr), + nameBox(nullptr) { } DatasheetPin::~DatasheetPin() { - delete numberBox; - delete nameBox; + if(numberBox != nullptr) + { + delete numberBox; + numberBox = nullptr; + } + if(nameBox != nullptr) + { + delete nameBox; + nameBox = nullptr; + } } qreal DatasheetPin::distanceToPoint(const QPointF ¢er) const diff --git a/src/pdf_extract/model/pdfdatasheet.cpp b/src/pdf_extract/model/pdfdatasheet.cpp index 3732325..cedf5ae 100644 --- a/src/pdf_extract/model/pdfdatasheet.cpp +++ b/src/pdf_extract/model/pdfdatasheet.cpp @@ -23,14 +23,20 @@ #include "controller/pdfloader.h" PDFDatasheet::PDFDatasheet(QString fileName) - : _fileName(std::move(fileName)) + : _pageCount(0), + _fileName(std::move(fileName)), + _pdfLoader(nullptr) { _pdfLoader = new PDFLoader(this); } PDFDatasheet::~PDFDatasheet() { + if(_pdfLoader != nullptr) + { delete _pdfLoader; + _pdfLoader = nullptr; + } } const QString &PDFDatasheet::fileName() const diff --git a/src/pdf_extract/model/pdfpage.cpp b/src/pdf_extract/model/pdfpage.cpp index 5cfb75a..aded6e7 100644 --- a/src/pdf_extract/model/pdfpage.cpp +++ b/src/pdf_extract/model/pdfpage.cpp @@ -35,8 +35,10 @@ PDFPage::~PDFPage() for (PDFTextBox *textBox : _textBoxes) { delete textBox; + textBox = nullptr; } delete _page; + _page = nullptr; } PDFDatasheet *PDFPage::datasheet() const diff --git a/src/pdf_extract/model/pdftextbox.cpp b/src/pdf_extract/model/pdftextbox.cpp index 5243f14..d363c97 100644 --- a/src/pdf_extract/model/pdftextbox.cpp +++ b/src/pdf_extract/model/pdftextbox.cpp @@ -22,11 +22,11 @@ PDFTextBox::PDFTextBox(QString text, const QRectF &boundingRect) : _text(std::move(text)), - _boundingRect(boundingRect) + _boundingRect(boundingRect), + _type(Text), + _page(nullptr), + _parentBox(nullptr) { - _page = nullptr; - _parentBox = nullptr; - _type = Text; } PDFTextBox::~PDFTextBox() @@ -54,7 +54,7 @@ const QRectF &PDFTextBox::boundingRect() const bool PDFTextBox::isPadName() const { - bool okNumber; + bool okNumber = false; _text.toInt(&okNumber); if (okNumber) { diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.cpp b/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.cpp index 3a6d7b3..efc8c9e 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.cpp +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.cpp @@ -28,9 +28,8 @@ #include "pdfdebugitemtextbox.h" PdfDebugItemPage::PdfDebugItemPage(PDFPage *page) + : _page(page) { - _page = page; - for (PDFTextBox *textBox : _page->textBoxes()) { new PdfDebugItemTextBox(textBox, this); diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugviewer.cpp b/src/pdf_extract/pdfdebugwidget/pdfdebugviewer.cpp index a39a041..0a8124c 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugviewer.cpp +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugviewer.cpp @@ -22,7 +22,8 @@ #include PdfDebugViewer::PdfDebugViewer(QWidget *parent) - : QGraphicsView(parent) + : QGraphicsView(parent), + _page(nullptr) { setScene(new QGraphicsScene(this)); diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.cpp b/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.cpp index 4d89d7e..c69d047 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.cpp +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.cpp @@ -24,16 +24,27 @@ PdfDebugWidget::PdfDebugWidget(QWidget *parent) : QWidget(parent), - _datasheet(nullptr) + _datasheet(nullptr), + _currentPage(nullptr), + _viewer(nullptr), + _ationPrev(nullptr), + _ationNext(nullptr), + _pageLineEdit(nullptr), + _pageLabel(nullptr) { - _currentPage = nullptr; createWidgets(); } PdfDebugWidget::PdfDebugWidget(PDFDatasheet *datasheet, QWidget *parent) - : QWidget(parent) + : QWidget(parent), + _datasheet(nullptr), + _currentPage(nullptr), + _viewer(nullptr), + _ationPrev(nullptr), + _ationNext(nullptr), + _pageLineEdit(nullptr), + _pageLabel(nullptr) { - _currentPage = nullptr; createWidgets(); setDatasheet(datasheet); } diff --git a/src/uconfig_gui/componentinfoseditor.cpp b/src/uconfig_gui/componentinfoseditor.cpp index 9aed866..b3b1060 100644 --- a/src/uconfig_gui/componentinfoseditor.cpp +++ b/src/uconfig_gui/componentinfoseditor.cpp @@ -21,8 +21,13 @@ #include ComponentInfosEditor::ComponentInfosEditor(UConfigProject *project) + : _project(project), + _component(nullptr), + _nameEdit(nullptr), + _packageEdit(nullptr), + _referenceEdit(nullptr), + _aliasesEdit(nullptr) { - _project = project; createWidgets(); setComponent(nullptr); } diff --git a/src/uconfig_gui/importer/componentspage.cpp b/src/uconfig_gui/importer/componentspage.cpp index d4dbd3c..9baea6b 100644 --- a/src/uconfig_gui/importer/componentspage.cpp +++ b/src/uconfig_gui/importer/componentspage.cpp @@ -29,7 +29,11 @@ #include ComponentsPage::ComponentsPage() - : QWizardPage(nullptr) + : QWizardPage(nullptr), + _checkAllBox(nullptr), + _statusLabel(nullptr), + _componentTreeView(nullptr), + _lib(nullptr) { QVBoxLayout *layout = new QVBoxLayout; @@ -59,6 +63,10 @@ void ComponentsPage::initializePage() _lib = new Lib(); switch (type) { + case PinListImporter::Undefined: + qFatal("not a valid type"); + break; + case PinListImporter::Kicad: { QString file = field("file").toString(); @@ -120,7 +128,12 @@ bool ComponentsPage::validatePage() _lib->takeComponent(component); } _componentTreeView->setLib(nullptr); - delete _lib; + + if(_lib != nullptr) + { + delete _lib; + _lib = nullptr; + } return true; } diff --git a/src/uconfig_gui/importer/datasheetprocesspage.cpp b/src/uconfig_gui/importer/datasheetprocesspage.cpp index f903744..1efe6e8 100644 --- a/src/uconfig_gui/importer/datasheetprocesspage.cpp +++ b/src/uconfig_gui/importer/datasheetprocesspage.cpp @@ -26,7 +26,16 @@ #include "pinlistimporter.h" DatasheetProcessPage::DatasheetProcessPage() - : QWizardPage(nullptr) + : QWizardPage(nullptr), + _datasheet(nullptr), + _thread(nullptr), + _statusLabel(nullptr), + _progressLabel(nullptr), + _progressBar(nullptr), + _logger(nullptr), + _pageStart(0), + _pageCount(0), + _complete(false) { QVBoxLayout *layout = new QVBoxLayout; diff --git a/src/uconfig_gui/importer/datasheetthread.cpp b/src/uconfig_gui/importer/datasheetthread.cpp index 8086ab1..d808c96 100644 --- a/src/uconfig_gui/importer/datasheetthread.cpp +++ b/src/uconfig_gui/importer/datasheetthread.cpp @@ -21,11 +21,11 @@ #include DataSheetThread::DataSheetThread(Datasheet *datasheet) + : _datasheet(datasheet), + _pageBegin(-1), + _pageEnd(-1) { - _datasheet = datasheet; _datasheet->moveToThread(this); - _pageBegin = -1; - _pageEnd = -1; } DataSheetThread::~DataSheetThread() @@ -36,6 +36,7 @@ DataSheetThread::~DataSheetThread() terminate(); } delete _datasheet; + _datasheet = nullptr; } bool DataSheetThread::open(const QString &fileName) diff --git a/src/uconfig_gui/importer/filepage.cpp b/src/uconfig_gui/importer/filepage.cpp index d28393c..7b1b3d1 100644 --- a/src/uconfig_gui/importer/filepage.cpp +++ b/src/uconfig_gui/importer/filepage.cpp @@ -33,10 +33,10 @@ #include "pinlistimporter.h" FilePage::FilePage() - : QWizardPage(nullptr) + : QWizardPage(nullptr), + _complete(false), + _fileEdit(nullptr) { - _complete = false; - setAcceptDrops(true); QLabel *label = new QLabel("File:"); @@ -66,6 +66,9 @@ int FilePage::nextId() const { switch (dynamic_cast(wizard())->type()) { + case PinListImporter::Undefined: + qFatal("not a valid type"); + break; case PinListImporter::Kicad: return PinListImporter::PageComponents; case PinListImporter::CSV: @@ -84,6 +87,9 @@ void FilePage::initializePage() { switch (dynamic_cast(wizard())->type()) { + case PinListImporter::Undefined: + qFatal("not a valid type"); + break; case PinListImporter::Kicad: _fileTitle = "Kicad lib (.lib)"; _suffixes << "lib"; diff --git a/src/uconfig_gui/importer/pdffilepage.cpp b/src/uconfig_gui/importer/pdffilepage.cpp index 6d92159..fd59a4d 100644 --- a/src/uconfig_gui/importer/pdffilepage.cpp +++ b/src/uconfig_gui/importer/pdffilepage.cpp @@ -29,7 +29,14 @@ PDFFilePage::PDFFilePage(DataSheetThread *datasheetThread) : QWizardPage(nullptr), - _datasheetThread(datasheetThread) + _datasheetThread(datasheetThread), + _complete(false), + _pagePreviewLabel(nullptr), + _allRadio(nullptr), + _partialRadio(nullptr), + _rangeEdit(nullptr), + _forceCheckBox(nullptr), + _pageCountLabel(nullptr) { _complete = false; diff --git a/src/uconfig_gui/importer/pinlistimporter.cpp b/src/uconfig_gui/importer/pinlistimporter.cpp index ce761df..2e85c51 100644 --- a/src/uconfig_gui/importer/pinlistimporter.cpp +++ b/src/uconfig_gui/importer/pinlistimporter.cpp @@ -28,7 +28,8 @@ #include PinListImporter::PinListImporter(const QString &fileName, QWidget *parent) - : QWizard(parent) + : QWizard(parent), + _type(Undefined) { setPage(PageStart, new StartWizardPage()); setPage(PageFile, new FilePage()); diff --git a/src/uconfig_gui/importer/pinlistimporter.h b/src/uconfig_gui/importer/pinlistimporter.h index 32971aa..09e1365 100644 --- a/src/uconfig_gui/importer/pinlistimporter.h +++ b/src/uconfig_gui/importer/pinlistimporter.h @@ -38,6 +38,7 @@ class PinListImporter : public QWizard */ enum ImportType { + Undefined = 0, CSV, PDF, // Table, diff --git a/src/uconfig_gui/importer/resultspage.cpp b/src/uconfig_gui/importer/resultspage.cpp index 3e0b642..9c49767 100644 --- a/src/uconfig_gui/importer/resultspage.cpp +++ b/src/uconfig_gui/importer/resultspage.cpp @@ -28,7 +28,8 @@ #include "pinlistimporter.h" ResultsPage::ResultsPage() - : QWizardPage(nullptr) + : QWizardPage(nullptr), + _resultLabel(nullptr) { QVBoxLayout *layout = new QVBoxLayout; _resultLabel = new QLabel(); diff --git a/src/uconfig_gui/importer/startwizardpage.cpp b/src/uconfig_gui/importer/startwizardpage.cpp index cecffcb..ab0248b 100644 --- a/src/uconfig_gui/importer/startwizardpage.cpp +++ b/src/uconfig_gui/importer/startwizardpage.cpp @@ -28,9 +28,9 @@ #include "pinlistimporter.h" StartWizardPage::StartWizardPage(QWidget *parent) - : QWizardPage(parent) + : QWizardPage(parent), + _complete(false) { - _complete = false; setAcceptDrops(true); setTitle("Choose import format"); diff --git a/src/uconfig_gui/project/uconfigproject.cpp b/src/uconfig_gui/project/uconfigproject.cpp index f18670f..b782436 100644 --- a/src/uconfig_gui/project/uconfigproject.cpp +++ b/src/uconfig_gui/project/uconfigproject.cpp @@ -29,11 +29,12 @@ const int UConfigProject::MaxOldProject = 8; UConfigProject::UConfigProject(QWidget *window) + : _lib(nullptr), + _activeComponent(nullptr), + _window(nullptr) { setWindow(window); readSettings(); - _lib = nullptr; - _activeComponent = nullptr; } UConfigProject::~UConfigProject() @@ -212,7 +213,7 @@ bool UConfigProject::closeLib() } int ret = QMessageBox::question(_window, tr("Saves lib?"), - tr("Do you want to save '%1' library? Modifications will be losted.").arg(_lib->name()), + tr("Do you want to save '%1' library? Modifications will be lost.").arg(_lib->name()), QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel); diff --git a/src/uconfig_gui/uconfigmainwindow.cpp b/src/uconfig_gui/uconfigmainwindow.cpp index 62fc547..399ed1b 100644 --- a/src/uconfig_gui/uconfigmainwindow.cpp +++ b/src/uconfig_gui/uconfigmainwindow.cpp @@ -44,7 +44,18 @@ #include "pinruler/rulesset.h" UConfigMainWindow::UConfigMainWindow(UConfigProject *project) - : _project(project) + : _project(project), + _splitter(nullptr), + _componentsTreeView(nullptr), + _componentInfosEditor(nullptr), + _pinListEditor(nullptr), + _componentWidget(nullptr), + _ruleComboBox(nullptr), + _pdfDebug(nullptr), + _splitterEditor(nullptr), + _kssEditor(nullptr), + _componentsListDock(nullptr), + _componentInfosDock(nullptr) { setWindowIcon(QIcon(":/icons/img/uConfig.ico")); createWidgets(); From 1e1b2d8a7a3284d28a0e0b76966b6783b7169306 Mon Sep 17 00:00:00 2001 From: GravisZro Date: Sat, 9 Sep 2023 17:17:44 -0400 Subject: [PATCH 2/5] Fix include statements Included files that are relative to the current directory should be included as such: \#include "relative_path/file.h" Included files that are relative to an included path should be included as such: \#include The fact that they worked is somewhat of a bug and they may not always be the case. --- src/autotest/tst_pdf_extract.cpp | 4 ++-- src/kicad/itemmodel/componentlibitemmodel.h | 2 +- src/kicad/itemmodel/componentpinsitemmodel.h | 2 +- src/kicad/parser/abstractlibparser.h | 2 +- src/kicad/parser/kicadlibparser.cpp | 8 ++++---- src/kicad/pinruler/pinclass.cpp | 2 +- src/kicad/pinruler/pinclass.h | 4 ++-- src/kicad/pinruler/pinclassitem.h | 2 +- src/kicad/pinruler/pinrule.h | 2 +- src/kicad/pinruler/pinruler.cpp | 2 +- src/kicad/pinruler/pinruler.h | 2 +- src/kicad/schematicsimport/schematicsimporter.h | 2 +- src/kicad/viewer/componentitem.h | 2 +- src/kicad/viewer/componentscene.h | 2 +- src/kicad/viewer/componentviewer.h | 2 +- src/kicad/viewer/drawcircleitem.h | 2 +- src/kicad/viewer/drawitem.h | 2 +- src/kicad/viewer/drawpolyitem.h | 2 +- src/kicad/viewer/drawrectitem.h | 2 +- src/kicad/viewer/drawtextitem.h | 2 +- src/kicad/viewer/pinitem.cpp | 2 +- src/kicad/viewer/pinitem.h | 2 +- src/pdf_extract/controller/pdfloader.h | 2 +- src/pdf_extract/model/pdfdatasheet.cpp | 2 +- src/pdf_extract/model/pdfpage.cpp | 2 +- src/pdf_extract/pdfdebugwidget/pdfdebugitempage.h | 2 +- src/pdf_extract/pdfdebugwidget/pdfdebugitemtextbox.h | 2 +- src/pdf_extract/pdfdebugwidget/pdfdebugviewer.h | 2 +- src/pdf_extract/pdfdebugwidget/pdfdebugwidget.h | 2 +- src/test/test_libkicad.cpp | 2 +- src/uconfig_gui/project/uconfigproject.cpp | 2 +- src/uconfig_gui/project/uconfigproject.h | 2 +- src/uconfig_gui/uconfigmainwindow.cpp | 6 +++--- src/uconfig_gui/uconfigmainwindow.h | 8 ++++---- 34 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/autotest/tst_pdf_extract.cpp b/src/autotest/tst_pdf_extract.cpp index 1a28e46..24a1a06 100644 --- a/src/autotest/tst_pdf_extract.cpp +++ b/src/autotest/tst_pdf_extract.cpp @@ -1,9 +1,9 @@ #include #include -#include "datasheet.h" +#include -#include "model/lib.h" +#include class PdfExtract : public QObject { diff --git a/src/kicad/itemmodel/componentlibitemmodel.h b/src/kicad/itemmodel/componentlibitemmodel.h index af9bc50..9c2d68e 100644 --- a/src/kicad/itemmodel/componentlibitemmodel.h +++ b/src/kicad/itemmodel/componentlibitemmodel.h @@ -22,7 +22,7 @@ #include #include -#include "model/lib.h" +#include class KICAD_EXPORT ComponentLibItemModel : public QAbstractItemModel { diff --git a/src/kicad/itemmodel/componentpinsitemmodel.h b/src/kicad/itemmodel/componentpinsitemmodel.h index 46b6bbc..1040d5b 100644 --- a/src/kicad/itemmodel/componentpinsitemmodel.h +++ b/src/kicad/itemmodel/componentpinsitemmodel.h @@ -21,7 +21,7 @@ #include -#include "model/component.h" +#include class KICAD_EXPORT ComponentPinsItemModel : public QAbstractItemModel { diff --git a/src/kicad/parser/abstractlibparser.h b/src/kicad/parser/abstractlibparser.h index fda17af..2846ae9 100644 --- a/src/kicad/parser/abstractlibparser.h +++ b/src/kicad/parser/abstractlibparser.h @@ -21,7 +21,7 @@ #include -#include "../model/lib.h" +#include class KICAD_EXPORT AbstractLibParser { diff --git a/src/kicad/parser/kicadlibparser.cpp b/src/kicad/parser/kicadlibparser.cpp index d5c5b57..a43da20 100644 --- a/src/kicad/parser/kicadlibparser.cpp +++ b/src/kicad/parser/kicadlibparser.cpp @@ -22,10 +22,10 @@ #include #include -#include "model/drawcircle.h" -#include "model/drawpoly.h" -#include "model/drawrect.h" -#include "model/drawtext.h" +#include +#include +#include +#include KicadLibParser::KicadLibParser() { diff --git a/src/kicad/pinruler/pinclass.cpp b/src/kicad/pinruler/pinclass.cpp index e834c8d..7b44060 100644 --- a/src/kicad/pinruler/pinclass.cpp +++ b/src/kicad/pinruler/pinclass.cpp @@ -22,7 +22,7 @@ #include #include -#include "viewer/kicadfont.h" +#include PinClass::PinClass(QString className) : _className(std::move(className)), diff --git a/src/kicad/pinruler/pinclass.h b/src/kicad/pinruler/pinclass.h index 4a78220..120d8cb 100644 --- a/src/kicad/pinruler/pinclass.h +++ b/src/kicad/pinruler/pinclass.h @@ -27,8 +27,8 @@ #include "classrule.h" #include "pinclassitem.h" -#include "model/drawrect.h" -#include "model/drawtext.h" +#include +#include class KICAD_EXPORT PinClass : public ClassRule { diff --git a/src/kicad/pinruler/pinclassitem.h b/src/kicad/pinruler/pinclassitem.h index 7422238..9a246e3 100644 --- a/src/kicad/pinruler/pinclassitem.h +++ b/src/kicad/pinruler/pinclassitem.h @@ -21,7 +21,7 @@ #include -#include "model/pin.h" +#include class KICAD_EXPORT PinClassItem { diff --git a/src/kicad/pinruler/pinrule.h b/src/kicad/pinruler/pinrule.h index 026035b..0a82fbb 100644 --- a/src/kicad/pinruler/pinrule.h +++ b/src/kicad/pinruler/pinrule.h @@ -23,7 +23,7 @@ #include #include -#include "model/pin.h" +#include #include "rule.h" class KICAD_EXPORT PinRule : public Rule diff --git a/src/kicad/pinruler/pinruler.cpp b/src/kicad/pinruler/pinruler.cpp index 4d6bff0..48728ab 100644 --- a/src/kicad/pinruler/pinruler.cpp +++ b/src/kicad/pinruler/pinruler.cpp @@ -21,7 +21,7 @@ #include #include -#include "model/drawrect.h" +#include PinRuler::PinRuler(RulesSet *ruleSet) : _ruleSet(ruleSet) diff --git a/src/kicad/pinruler/pinruler.h b/src/kicad/pinruler/pinruler.h index 7371785..4ee7fb4 100644 --- a/src/kicad/pinruler/pinruler.h +++ b/src/kicad/pinruler/pinruler.h @@ -22,7 +22,7 @@ #include #include -#include "model/component.h" +#include #include "pinclass.h" #include "rulesset.h" diff --git a/src/kicad/schematicsimport/schematicsimporter.h b/src/kicad/schematicsimport/schematicsimporter.h index 91aa5d9..09411d7 100644 --- a/src/kicad/schematicsimport/schematicsimporter.h +++ b/src/kicad/schematicsimport/schematicsimporter.h @@ -21,7 +21,7 @@ #include -#include "model/component.h" +#include class KICAD_EXPORT SchematicsImporter { diff --git a/src/kicad/viewer/componentitem.h b/src/kicad/viewer/componentitem.h index f6691a8..c452710 100644 --- a/src/kicad/viewer/componentitem.h +++ b/src/kicad/viewer/componentitem.h @@ -23,7 +23,7 @@ #include #include -#include "model/component.h" +#include #include "pinitem.h" class PinItem; diff --git a/src/kicad/viewer/componentscene.h b/src/kicad/viewer/componentscene.h index 24f2820..f7e7cab 100644 --- a/src/kicad/viewer/componentscene.h +++ b/src/kicad/viewer/componentscene.h @@ -23,7 +23,7 @@ #include #include "componentitem.h" -#include "model/component.h" +#include class KICAD_EXPORT ComponentScene : public QGraphicsScene { diff --git a/src/kicad/viewer/componentviewer.h b/src/kicad/viewer/componentviewer.h index e8c796f..71ba54b 100644 --- a/src/kicad/viewer/componentviewer.h +++ b/src/kicad/viewer/componentviewer.h @@ -24,7 +24,7 @@ #include #include "componentscene.h" -#include "model/component.h" +#include class ComponentScene; class ComponentItem; diff --git a/src/kicad/viewer/drawcircleitem.h b/src/kicad/viewer/drawcircleitem.h index 816ecb4..380e1b9 100644 --- a/src/kicad/viewer/drawcircleitem.h +++ b/src/kicad/viewer/drawcircleitem.h @@ -23,7 +23,7 @@ #include "drawitem.h" -#include "model/drawcircle.h" +#include class KICAD_EXPORT DrawCircleItem : public DrawItem { diff --git a/src/kicad/viewer/drawitem.h b/src/kicad/viewer/drawitem.h index 4864266..1995a70 100644 --- a/src/kicad/viewer/drawitem.h +++ b/src/kicad/viewer/drawitem.h @@ -22,7 +22,7 @@ #include #include -#include "model/draw.h" +#include class KICAD_EXPORT DrawItem : public QGraphicsItem { diff --git a/src/kicad/viewer/drawpolyitem.h b/src/kicad/viewer/drawpolyitem.h index a6a67ab..1f60367 100644 --- a/src/kicad/viewer/drawpolyitem.h +++ b/src/kicad/viewer/drawpolyitem.h @@ -23,7 +23,7 @@ #include "drawitem.h" -#include "model/drawpoly.h" +#include class KICAD_EXPORT DrawPolyItem : public DrawItem { diff --git a/src/kicad/viewer/drawrectitem.h b/src/kicad/viewer/drawrectitem.h index bc18db6..45c1c27 100644 --- a/src/kicad/viewer/drawrectitem.h +++ b/src/kicad/viewer/drawrectitem.h @@ -23,7 +23,7 @@ #include "drawitem.h" -#include "model/drawrect.h" +#include class KICAD_EXPORT DrawRectItem : public DrawItem { diff --git a/src/kicad/viewer/drawtextitem.h b/src/kicad/viewer/drawtextitem.h index 294642c..ae30efa 100644 --- a/src/kicad/viewer/drawtextitem.h +++ b/src/kicad/viewer/drawtextitem.h @@ -24,7 +24,7 @@ #include "drawitem.h" #include "kicadfont.h" -#include "model/drawtext.h" +#include class KICAD_EXPORT DrawTextItem : public DrawItem { diff --git a/src/kicad/viewer/pinitem.cpp b/src/kicad/viewer/pinitem.cpp index 628b574..1476536 100644 --- a/src/kicad/viewer/pinitem.cpp +++ b/src/kicad/viewer/pinitem.cpp @@ -24,7 +24,7 @@ #include #include -#include "model/component.h" +#include PinItem::PinItem(Pin *pin) : _pin(nullptr), diff --git a/src/kicad/viewer/pinitem.h b/src/kicad/viewer/pinitem.h index 00ba660..be84673 100644 --- a/src/kicad/viewer/pinitem.h +++ b/src/kicad/viewer/pinitem.h @@ -22,7 +22,7 @@ #include #include -#include "model/pin.h" +#include #include "kicadfont.h" diff --git a/src/pdf_extract/controller/pdfloader.h b/src/pdf_extract/controller/pdfloader.h index 97437d8..4096593 100644 --- a/src/pdf_extract/controller/pdfloader.h +++ b/src/pdf_extract/controller/pdfloader.h @@ -21,7 +21,7 @@ #include -#include "model/pdfdatasheet.h" +#include namespace Poppler { diff --git a/src/pdf_extract/model/pdfdatasheet.cpp b/src/pdf_extract/model/pdfdatasheet.cpp index cedf5ae..14dbad0 100644 --- a/src/pdf_extract/model/pdfdatasheet.cpp +++ b/src/pdf_extract/model/pdfdatasheet.cpp @@ -20,7 +20,7 @@ #include -#include "controller/pdfloader.h" +#include PDFDatasheet::PDFDatasheet(QString fileName) : _pageCount(0), diff --git a/src/pdf_extract/model/pdfpage.cpp b/src/pdf_extract/model/pdfpage.cpp index aded6e7..a4ec32f 100644 --- a/src/pdf_extract/model/pdfpage.cpp +++ b/src/pdf_extract/model/pdfpage.cpp @@ -17,7 +17,7 @@ **/ #include "pdfpage.h" -#include "controller/pdfloader.h" +#include #include "pdfdatasheet.h" #include diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.h b/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.h index 911ae31..04e657c 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.h +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.h @@ -23,7 +23,7 @@ #include -#include "model/pdfpage.h" +#include class DATASHEET_EXTRACTOR_EXPORT PdfDebugItemPage : public QGraphicsItem { diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugitemtextbox.h b/src/pdf_extract/pdfdebugwidget/pdfdebugitemtextbox.h index 46af713..7e8a379 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugitemtextbox.h +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugitemtextbox.h @@ -23,7 +23,7 @@ #include -#include "model/pdftextbox.h" +#include class DATASHEET_EXTRACTOR_EXPORT PdfDebugItemTextBox : public QGraphicsItem { diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugviewer.h b/src/pdf_extract/pdfdebugwidget/pdfdebugviewer.h index 9531b43..89ea51b 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugviewer.h +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugviewer.h @@ -23,7 +23,7 @@ #include -#include "model/pdfpage.h" +#include #include "pdfdebugitempage.h" class DATASHEET_EXTRACTOR_EXPORT PdfDebugViewer : public QGraphicsView diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.h b/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.h index 77b16fb..e2ce1ef 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.h +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.h @@ -26,7 +26,7 @@ #include #include -#include "model/pdfdatasheet.h" +#include #include "pdfdebugviewer.h" class DATASHEET_EXTRACTOR_EXPORT PdfDebugWidget : public QWidget diff --git a/src/test/test_libkicad.cpp b/src/test/test_libkicad.cpp index 812a429..a2a2ff9 100644 --- a/src/test/test_libkicad.cpp +++ b/src/test/test_libkicad.cpp @@ -16,7 +16,7 @@ ** along with this program. If not, see . **/ -#include "model/lib.h" +#include #include #include diff --git a/src/uconfig_gui/project/uconfigproject.cpp b/src/uconfig_gui/project/uconfigproject.cpp index b782436..39433dc 100644 --- a/src/uconfig_gui/project/uconfigproject.cpp +++ b/src/uconfig_gui/project/uconfigproject.cpp @@ -24,7 +24,7 @@ #include #include -#include "importer/pinlistimporter.h" +#include const int UConfigProject::MaxOldProject = 8; diff --git a/src/uconfig_gui/project/uconfigproject.h b/src/uconfig_gui/project/uconfigproject.h index b7389d9..d39b3db 100644 --- a/src/uconfig_gui/project/uconfigproject.h +++ b/src/uconfig_gui/project/uconfigproject.h @@ -21,7 +21,7 @@ #include -#include "model/lib.h" +#include class UConfigProject : public QObject { diff --git a/src/uconfig_gui/uconfigmainwindow.cpp b/src/uconfig_gui/uconfigmainwindow.cpp index 399ed1b..7a5b9d8 100644 --- a/src/uconfig_gui/uconfigmainwindow.cpp +++ b/src/uconfig_gui/uconfigmainwindow.cpp @@ -39,9 +39,9 @@ #include -#include "pinruler/pinruler.h" -#include "pinruler/rulesparser.h" -#include "pinruler/rulesset.h" +#include +#include +#include UConfigMainWindow::UConfigMainWindow(UConfigProject *project) : _project(project), diff --git a/src/uconfig_gui/uconfigmainwindow.h b/src/uconfig_gui/uconfigmainwindow.h index eca990d..ee6e34c 100644 --- a/src/uconfig_gui/uconfigmainwindow.h +++ b/src/uconfig_gui/uconfigmainwindow.h @@ -31,10 +31,10 @@ #include "project/uconfigproject.h" #include "componentinfoseditor.h" -#include "itemmodel/componentlibtreeview.h" -#include "itemmodel/pinlisteditor.h" -#include "ksseditor/ksseditor.h" -#include "viewer/componentwidget.h" +#include +#include +#include +#include class UConfigMainWindow : public QMainWindow { From 88a3ba8d63555d725725f052832debf033070afc Mon Sep 17 00:00:00 2001 From: GravisZro Date: Sun, 10 Sep 2023 18:58:12 -0400 Subject: [PATCH 3/5] Serious memory bug fix. The program has been using objects in freed memory for a very long time. --- src/kicad/itemmodel/componentlibtreeview.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/kicad/itemmodel/componentlibtreeview.cpp b/src/kicad/itemmodel/componentlibtreeview.cpp index d3ef20d..7e2bf28 100644 --- a/src/kicad/itemmodel/componentlibtreeview.cpp +++ b/src/kicad/itemmodel/componentlibtreeview.cpp @@ -57,13 +57,12 @@ Lib *ComponentLibTreeView::lib() const void ComponentLibTreeView::setLib(Lib *lib) { - _model->setLib(lib); - if (lib == _model->lib()) + if (lib != _model->lib()) { - return; + _model->setLib(lib); + resizeColumnToContents(0); + resizeColumnToContents(1); } - resizeColumnToContents(0); - resizeColumnToContents(1); } void ComponentLibTreeView::setActiveComponent(Component *component) From 52eb8d6201e42e4dbb12f250e6bad3e898a5fb3d Mon Sep 17 00:00:00 2001 From: GravisZro Date: Sun, 17 Sep 2023 08:15:52 -0400 Subject: [PATCH 4/5] Fixes for Qt code Since Qt objects are based on reference counting/garbage collection, they can have some unexpected behaviors, specifically when dealing with lists. I have fixed many instance of different Qt related issues after being identified using Clazy. https://github.com/KDE/clazy/blob/1.11/docs/checks/README-range-loop-detach.md https://github.com/KDE/clazy/blob/1.11/docs/checks/README-detaching-temporary.md https://github.com/KDE/clazy/blob/1.11/docs/checks/README-use-static-qregularexpression.md https://github.com/KDE/clazy/blob/1.11/docs/checks/README-qproperty-without-notify.md --- src/kicad/itemmodel/componentlibtreeview.cpp | 2 +- .../itemmodel/componentpinsitemmodel.cpp | 6 +-- .../itemmodel/componentpinstableview.cpp | 5 +- src/kicad/ksseditor/ksssyntax.cpp | 6 +-- src/kicad/pinruler/pinclass.cpp | 8 +-- src/kicad/pinruler/pinruler.cpp | 6 +-- src/kicad/pinruler/rulesparser.cpp | 8 +-- src/kicad/viewer/componentitem.cpp | 6 +-- src/kicad/viewer/componentviewer.cpp | 3 +- src/kicad/viewer/drawpolyitem.cpp | 4 +- src/pdf_extract/datasheet.cpp | 49 ++++++++++--------- src/pdf_extract/model/pdfpage.cpp | 2 +- src/pdf_extract/model/pdftextbox.cpp | 2 +- src/test/test_libkicad.cpp | 4 +- .../importer/datasheetprocesspage.cpp | 3 +- src/uconfig_gui/importer/filepage.cpp | 2 +- src/uconfig_gui/importer/filepage.h | 2 +- src/uconfig_gui/importer/pdffilepage.cpp | 2 +- src/uconfig_gui/project/uconfigproject.cpp | 10 ++-- src/uconfig_gui/project/uconfigproject.h | 2 +- src/uconfig_gui/uconfig_gui.cpp | 2 +- src/uconfig_gui/uconfigmainwindow.cpp | 8 +-- 22 files changed, 77 insertions(+), 65 deletions(-) diff --git a/src/kicad/itemmodel/componentlibtreeview.cpp b/src/kicad/itemmodel/componentlibtreeview.cpp index 7e2bf28..ab35c5c 100644 --- a/src/kicad/itemmodel/componentlibtreeview.cpp +++ b/src/kicad/itemmodel/componentlibtreeview.cpp @@ -130,7 +130,7 @@ void ComponentLibTreeView::remove() return; } QList pindex; - for (QModelIndex selected : selection) + for (QModelIndex selected : qAsConst(selection)) { const QModelIndex &indexComponent = _sortProxy->mapToSource(selected); if (!indexComponent.isValid() || indexComponent.column() != 0) diff --git a/src/kicad/itemmodel/componentpinsitemmodel.cpp b/src/kicad/itemmodel/componentpinsitemmodel.cpp index e610a18..c2ba47f 100644 --- a/src/kicad/itemmodel/componentpinsitemmodel.cpp +++ b/src/kicad/itemmodel/componentpinsitemmodel.cpp @@ -300,7 +300,7 @@ QString ComponentPinsItemModel::toNumeric(const QString &str) { QString sortPatern = str; - QRegularExpression numPattern("([^0-9]*)([0-9]+)([^0-9]*)", QRegularExpression::CaseInsensitiveOption); + static QRegularExpression numPattern("([^0-9]*)([0-9]+)([^0-9]*)", QRegularExpression::CaseInsensitiveOption); QRegularExpressionMatchIterator numMatchIt = numPattern.globalMatch(str); if (numMatchIt.hasNext()) @@ -322,7 +322,7 @@ void ComponentPinsItemModel::updateHigherPin() _higherPin.clear(); if (_component != nullptr) { - for (Pin *pin : _component->pins()) + for (Pin *pin : qAsConst(_component->pins())) { QString numPin = toNumeric(pin->padName()); if (numPin > higherNumPin) @@ -331,7 +331,7 @@ void ComponentPinsItemModel::updateHigherPin() higherNumPin = numPin; } } - QRegularExpression higherNumPinPattern("([A-Z]*0*)([1-9][0-9]*)", QRegularExpression::CaseInsensitiveOption); + static QRegularExpression higherNumPinPattern("([A-Z]*0*)([1-9][0-9]*)", QRegularExpression::CaseInsensitiveOption); QRegularExpressionMatchIterator higherNumPinMatchIt = higherNumPinPattern.globalMatch(_higherPin); if (higherNumPinMatchIt.hasNext()) { diff --git a/src/kicad/itemmodel/componentpinstableview.cpp b/src/kicad/itemmodel/componentpinstableview.cpp index 6e51039..5d53f89 100644 --- a/src/kicad/itemmodel/componentpinstableview.cpp +++ b/src/kicad/itemmodel/componentpinstableview.cpp @@ -131,7 +131,7 @@ void ComponentPinsTableView::remove() if (!selection.empty()) { QList pindex; - for (QModelIndex selected : selection) + for (QModelIndex selected : qAsConst(selection)) { const QModelIndex &indexComponent = _sortProxy->mapToSource(selected); if (!indexComponent.isValid()) @@ -179,7 +179,8 @@ void ComponentPinsTableView::updateSelect(const QItemSelection &selected, const Q_UNUSED(deselected) QSet selectedPins; - for (const QModelIndex &index : selectionModel()->selectedIndexes()) + const auto& selected_idx = selectionModel()->selectedIndexes(); + for (const QModelIndex &index : selected_idx) { if (!index.isValid()) { diff --git a/src/kicad/ksseditor/ksssyntax.cpp b/src/kicad/ksseditor/ksssyntax.cpp index bb3e21a..9482a62 100644 --- a/src/kicad/ksseditor/ksssyntax.cpp +++ b/src/kicad/ksseditor/ksssyntax.cpp @@ -46,7 +46,7 @@ KSSSyntax::KSSSyntax(QTextDocument *parent) << "label" << "rect" << "priority"; - for (const QString &pattern : keywordPatterns) + for (const QString &pattern : qAsConst(keywordPatterns)) { rule.pattern.setPattern("\\b(" + pattern + ")\\b"); rule.format = keywordFormat; @@ -89,7 +89,7 @@ KSSSyntax::KSSSyntax(QTextDocument *parent) << "faledge" << "nologic"; - for (const QString &pattern : enumvaluesPatterns) + for (const QString &pattern : qAsConst(enumvaluesPatterns)) { rule.pattern.setPattern("\\b(" + pattern + ")\\b"); rule.format = enumvaluesFormat; @@ -117,7 +117,7 @@ void KSSSyntax::highlightBlock(const QString &text) PartToHighlight highlight; partsToHighlight.clear(); - for (const HighlightingRule &rule : highlightingRules) + for (const HighlightingRule &rule : qAsConst(highlightingRules)) { QRegularExpressionMatch match = rule.pattern.match(text); if (match.hasMatch()) diff --git a/src/kicad/pinruler/pinclass.cpp b/src/kicad/pinruler/pinclass.cpp index 7b44060..a61b633 100644 --- a/src/kicad/pinruler/pinclass.cpp +++ b/src/kicad/pinruler/pinclass.cpp @@ -122,10 +122,10 @@ void PinClass::sortPins() return; } - QRegularExpression pattern(_sortPattern, QRegularExpression::CaseInsensitiveOption); - QRegularExpression numPattern("([^0-9]*)([0-9]+)([^0-9]*)", QRegularExpression::CaseInsensitiveOption); + static QRegularExpression pattern(_sortPattern, QRegularExpression::CaseInsensitiveOption); + static QRegularExpression numPattern("([^0-9]*)([0-9]+)([^0-9]*)", QRegularExpression::CaseInsensitiveOption); - for (PinClassItem *pinItem : _pins) + for (PinClassItem *pinItem : qAsConst(_pins)) { QString sortPatern; QString pinName = pinItem->pin()->name(); @@ -220,7 +220,7 @@ void PinClass::setPos(const QPoint &basePos) break; } sortPins(); - for (PinClassItem *pinItem : _pins) + for (PinClassItem *pinItem : qAsConst(_pins)) { pinItem->pin()->setAngle(angle); pinItem->pin()->setPos(pinPos + translate); diff --git a/src/kicad/pinruler/pinruler.cpp b/src/kicad/pinruler/pinruler.cpp index 48728ab..596cd6d 100644 --- a/src/kicad/pinruler/pinruler.cpp +++ b/src/kicad/pinruler/pinruler.cpp @@ -59,7 +59,7 @@ void PinRuler::organize(Component *component) component->clearDraws(); PinClass *defaultClass = pinClass("default"); - for (Pin *pin : component->pins()) + for (Pin *pin : qAsConst(component->pins())) { PinClassItem *pinClassItem = new PinClassItem(pin); const QList &rules = _ruleSet->rulesForPin(pin->name()); @@ -131,7 +131,7 @@ void PinRuler::organize(Component *component) QSize leftSize = QSize(0, 0); QSize rightSize = QSize(0, 0); QSize removedSize = QSize(0, 0); - for (PinClass *mpinClass : _pinClasses) + for (PinClass *mpinClass : qAsConst(_pinClasses)) { if (mpinClass->pins().count() == 0) { @@ -337,7 +337,7 @@ void PinRuler::organize(Component *component) component->refText()->setTextHJustify(DrawText::TextHLeft); component->refText()->setDirection(DrawText::DirectionHorizontal); - for (PinClass *mpinClass : _pinClasses) + for (PinClass *mpinClass : qAsConst(_pinClasses)) { delete mpinClass; mpinClass = nullptr; diff --git a/src/kicad/pinruler/rulesparser.cpp b/src/kicad/pinruler/rulesparser.cpp index 1e3dd15..d4532cb 100644 --- a/src/kicad/pinruler/rulesparser.cpp +++ b/src/kicad/pinruler/rulesparser.cpp @@ -176,8 +176,8 @@ void RulesParser::skipSpaceAndComments() QString RulesParser::getSelector() { - QRegularExpression rule(R"((\.?[a-zA-Z\(\[\.][/a-zA-Z0-9\+\-\[\]\(\)\_\|\\\*\.\^$\?:]*))"); - QRegularExpressionMatch ruleMath = rule.match(_data.mid(_id)); + static QRegularExpression rule(R"((\.?[a-zA-Z\(\[\.][/a-zA-Z0-9\+\-\[\]\(\)\_\|\\\*\.\^$\?:]*))"); + static QRegularExpressionMatch ruleMath = rule.match(_data.mid(_id)); if (ruleMath.hasMatch() && ruleMath.capturedStart() != 0) { return QString(); @@ -209,7 +209,7 @@ QString RulesParser::getSelector() QString RulesParser::getPropertyName() { - QRegularExpression rule("([a-zA-Z][a-zA-Z0-9\\_\\-]*)[\t ]*:[\t ]*", QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption); + static QRegularExpression rule("([a-zA-Z][a-zA-Z0-9\\_\\-]*)[\t ]*:[\t ]*", QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption); QRegularExpressionMatch ruleMath = rule.match(_data.mid(_id)); if (ruleMath.hasMatch() && ruleMath.capturedStart() != 0) { @@ -221,7 +221,7 @@ QString RulesParser::getPropertyName() QString RulesParser::getPropertyValue() { - QRegularExpression rule(R"lit("?([a-zA-Z0-9/^\?\$\|:\_\-\+\\\[\]\(\)\.\* ]*)"?;?)lit", + static QRegularExpression rule(R"lit("?([a-zA-Z0-9/^\?\$\|:\_\-\+\\\[\]\(\)\.\* ]*)"?;?)lit", QRegularExpression::MultilineOption | QRegularExpression::DotMatchesEverythingOption); QRegularExpressionMatch ruleMath = rule.match(_data.mid(_id)); if (ruleMath.hasMatch() && ruleMath.capturedStart() != 0) diff --git a/src/kicad/viewer/componentitem.cpp b/src/kicad/viewer/componentitem.cpp index f080e83..979142d 100644 --- a/src/kicad/viewer/componentitem.cpp +++ b/src/kicad/viewer/componentitem.cpp @@ -59,7 +59,7 @@ void ComponentItem::setComponent(Component *component, int unit) _pinItemMap.clear(); _unit = unit; - for (Pin *pin : component->pins()) + for (Pin *pin : qAsConst(component->pins())) { if (pin->unit() == _unit || pin->unit() == 0) { @@ -68,7 +68,7 @@ void ComponentItem::setComponent(Component *component, int unit) _pinItemMap.insert(pin, pinItem); } } - for (Draw *draw : component->draws()) + for (Draw *draw : qAsConst(component->draws())) { if (draw->unit() == _unit || draw->unit() == 0) { @@ -117,7 +117,7 @@ void ComponentItem::setShowElectricalType(bool showElectricalType) { if (showElectricalType != _showElectricalType) { - for (PinItem *pinItem : _pinItemMap) + for (PinItem *pinItem : qAsConst(_pinItemMap)) { pinItem->setShowElectricalType(showElectricalType); } diff --git a/src/kicad/viewer/componentviewer.cpp b/src/kicad/viewer/componentviewer.cpp index 1f415fb..469575e 100644 --- a/src/kicad/viewer/componentviewer.cpp +++ b/src/kicad/viewer/componentviewer.cpp @@ -166,7 +166,8 @@ void ComponentViewer::selectedItem() { QList selectedPins; - for (QGraphicsItem *item : scene()->selectedItems()) + const auto& selected = scene()->selectedItems(); + for (QGraphicsItem *item : selected) { PinItem *pinItem = qgraphicsitem_cast(item); selectedPins.append(pinItem->pin()); diff --git a/src/kicad/viewer/drawpolyitem.cpp b/src/kicad/viewer/drawpolyitem.cpp index 6a8023d..8b0575f 100644 --- a/src/kicad/viewer/drawpolyitem.cpp +++ b/src/kicad/viewer/drawpolyitem.cpp @@ -49,7 +49,7 @@ void DrawPolyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti } QPolygon poly; - for (QPoint pt : _drawPoly->points()) + for (QPoint pt : qAsConst(_drawPoly->points())) { poly.append(pt / ComponentItem::ratio); } @@ -67,7 +67,7 @@ void DrawPolyItem::setDraw(DrawPoly *draw) _drawPoly = draw; QRect mrect(0, 0, 1, 1); - for (QPoint pt : _drawPoly->points()) + for (QPoint pt : qAsConst(_drawPoly->points())) { mrect = mrect.united(QRect(pt / ComponentItem::ratio, QSize(1, 1))); } diff --git a/src/pdf_extract/datasheet.cpp b/src/pdf_extract/datasheet.cpp index 1416e88..d4d931f 100644 --- a/src/pdf_extract/datasheet.cpp +++ b/src/pdf_extract/datasheet.cpp @@ -110,7 +110,7 @@ void Datasheet::pinSearch(int numPage) QCoreApplication::processEvents(); // painring pin to find package - for (DatasheetPin *pin : pins) + for (DatasheetPin *pin : qAsConst(pins)) { if (pin->pin == 1 && pin->page == numPage) { @@ -155,7 +155,7 @@ void Datasheet::pinSearch(int numPage) QCoreApplication::processEvents(); // unasociated label - for (DatasheetBox *label : _labels) + for (DatasheetBox *label : qAsConst(_labels)) { if (label->associated) { @@ -197,7 +197,7 @@ void Datasheet::pinSearch(int numPage) { QRectF rect; QRectF rectNum; - for (DatasheetPin *pin : package->pins) + for (DatasheetPin *pin : qAsConst(package->pins)) { rect = rect.united(pin->pos); rectNum = rectNum.united(pin->numPos); @@ -250,11 +250,11 @@ void Datasheet::pinSearch(int numPage) dir.mkdir(_name); painter.setPen(QPen(Qt::yellow, 2, Qt::DotLine)); - for (DatasheetBox *number : _numbers) + for (DatasheetBox *number : qAsConst(_numbers)) { painter.drawRect(QRect((number->pos.topLeft() - rect.topLeft()).toPoint() * res, number->pos.size().toSize() * res)); } - for (DatasheetBox *label : _labels) + for (DatasheetBox *label : qAsConst(_labels)) { if (!label->associated) { @@ -296,6 +296,10 @@ QRectF Datasheet::toGlobalPos(const QRectF &rect, Poppler::Page *page, int pageN QList Datasheet::extractPins(int numPage) { + static QRegularExpression number_in_parens("\\([0-9]+\\)"); + static QRegularExpression only_number_in_parens("^\\([0-9]+\\)$"); + static QRegularExpression excess_spacing(" +"); + QList pins; emit log(QString("+ find pins at page: %1").arg(numPage + 1)); @@ -320,13 +324,14 @@ QList Datasheet::extractPins(int numPage) bool prev = false; DatasheetBox *box = new DatasheetBox(); box->page = numPage; - for (TextBox *textBox : page->textList()) + const auto& textBoxes = page->textList(); + for (TextBox *textBox : textBoxes) { bool okNumber; if (textBox->text().startsWith("•")) { - textBox->text().mid(1).toInt(&okNumber); + textBox->text().midRef(1).toInt(&okNumber); } else { @@ -395,12 +400,12 @@ QList Datasheet::extractPins(int numPage) } // remove notes - box->text.replace(QRegularExpression("\\([0-9]+\\)"), ""); + box->text.remove(number_in_parens); // classify boxes if (!okNumber || prev) { - if (box->text.isEmpty() || box->text.contains("Note", Qt::CaseInsensitive) || box->text.contains(QRegularExpression("^\\([0-9]+\\)$"))) + if (box->text.isEmpty() || box->text.contains("Note", Qt::CaseInsensitive) || box->text.contains(only_number_in_parens)) { // none } @@ -447,9 +452,8 @@ QList Datasheet::extractPins(int numPage) } // pairing label and number to pin - for (DatasheetBox *number : _numbers) + for (DatasheetBox *number : qAsConst(_numbers)) { - DatasheetPin *pin = new DatasheetPin(); qreal dist = 999999999999; QPointF center = number->pos.center(); DatasheetBox *assocLabel = nullptr; @@ -483,6 +487,8 @@ QList Datasheet::extractPins(int numPage) if (assocLabel != nullptr) { + DatasheetPin *pin = new DatasheetPin(); + assocLabel->associated = true; number->associated = true; @@ -491,8 +497,8 @@ QList Datasheet::extractPins(int numPage) pin->numberBox = number; pin->name = assocLabel->text; - pin->name.remove(QRegularExpression("\\([0-9]+\\)")); - pin->name.remove(QRegularExpression(" +")); + pin->name.remove(number_in_parens); + pin->name.remove(excess_spacing); pin->nameBox = assocLabel; pin->page = number->page; @@ -539,13 +545,11 @@ int Datasheet::pageCount() const QImage Datasheet::pageThumbnail(int numPage) const { QImage image; - if (_doc == nullptr) + if (_doc != nullptr) { - return QImage(); + image = _doc->page(numPage)->renderToImage(20, 20, 0, 0, -1, -1); } - - Poppler::Page *page = _doc->page(numPage); - return page->renderToImage(20, 20, 0, 0, -1, -1); + return image; } void Datasheet::clean() @@ -566,7 +570,7 @@ void Datasheet::clean() if (!box->associated) delete box;*/ _pack_labels.clear(); - for (DatasheetPackage *box : _packages) + for (DatasheetPackage *box : qAsConst(_packages)) { delete box; box = nullptr; @@ -625,7 +629,8 @@ int Datasheet::pagePinDiagram(int pageStart, int pageEnd, bool *bgaStyle) bool vssOk = false; bool vddOk = false; bool labelOk = false; - for (TextBox *textBox : page->textList()) + const auto& textBoxes = page->textList(); + for (TextBox *textBox : textBoxes) { QString text = textBox->text(); if (textBox->nextWord() != nullptr) @@ -649,7 +654,7 @@ int Datasheet::pagePinDiagram(int pageStart, int pageEnd, bool *bgaStyle) *bgaStyle=true;*/ *bgaStyle = false; - for (const QString &keyWord : keyWords) + for (const QString &keyWord : qAsConst(keyWords)) { if (text.contains(keyWord, Qt::CaseInsensitive)) { @@ -736,7 +741,7 @@ const QList &Datasheet::packages() const QList Datasheet::components() { QList components; - for (DatasheetPackage *package : _packages) + for (DatasheetPackage *package : qAsConst(_packages)) { Component *component = package->toComponent(); component->reorganizeToPackageStyle(); diff --git a/src/pdf_extract/model/pdfpage.cpp b/src/pdf_extract/model/pdfpage.cpp index a4ec32f..2515268 100644 --- a/src/pdf_extract/model/pdfpage.cpp +++ b/src/pdf_extract/model/pdfpage.cpp @@ -32,7 +32,7 @@ PDFPage::PDFPage(PDFDatasheet *datasheet, int numPage) PDFPage::~PDFPage() { - for (PDFTextBox *textBox : _textBoxes) + for (PDFTextBox *textBox : qAsConst(_textBoxes)) { delete textBox; textBox = nullptr; diff --git a/src/pdf_extract/model/pdftextbox.cpp b/src/pdf_extract/model/pdftextbox.cpp index d363c97..9223547 100644 --- a/src/pdf_extract/model/pdftextbox.cpp +++ b/src/pdf_extract/model/pdftextbox.cpp @@ -31,7 +31,7 @@ PDFTextBox::PDFTextBox(QString text, const QRectF &boundingRect) PDFTextBox::~PDFTextBox() { - for (PDFTextBox *textBox : _subBoxes) + for (PDFTextBox *textBox : qAsConst(_subBoxes)) { delete textBox; } diff --git a/src/test/test_libkicad.cpp b/src/test/test_libkicad.cpp index a2a2ff9..bf497c9 100644 --- a/src/test/test_libkicad.cpp +++ b/src/test/test_libkicad.cpp @@ -39,7 +39,7 @@ void test_libkicad() QStringList items = line.split(";"); int i = 0; - for (const QString &item : items) + for (const QString &item : qAsConst(items)) { if (i > 0 && !item.isEmpty()) { @@ -68,7 +68,7 @@ void test_libkicad() points.append(QPoint(1000 + 300 * i, 0)); } - for (auto pin : component->pins()) + for (auto pin : qAsConst(component->pins())) { if (pin->name() == "GND") { diff --git a/src/uconfig_gui/importer/datasheetprocesspage.cpp b/src/uconfig_gui/importer/datasheetprocesspage.cpp index 1efe6e8..42d0b94 100644 --- a/src/uconfig_gui/importer/datasheetprocesspage.cpp +++ b/src/uconfig_gui/importer/datasheetprocesspage.cpp @@ -118,7 +118,8 @@ void DatasheetProcessPage::finish() qDeleteAll(components); components.clear(); - for (Component *component : _thread->datasheet()->components()) + const auto& component_list = _thread->datasheet()->components(); + for (Component *component : component_list) { components.append(component); } diff --git a/src/uconfig_gui/importer/filepage.cpp b/src/uconfig_gui/importer/filepage.cpp index 7b1b3d1..16103b3 100644 --- a/src/uconfig_gui/importer/filepage.cpp +++ b/src/uconfig_gui/importer/filepage.cpp @@ -153,7 +153,7 @@ void FilePage::fileExplore() } QString fileName = QFileDialog::getOpenFileName( - this, QString("Choose a %1 file").arg(_fileTitle), lastPath, QString("%1 (%2)").arg(_fileTitle).arg("*." + _suffixes.join(" *."))); + this, QString("Choose a %1 file").arg(_fileTitle), lastPath, QString("%1 (%2)").arg(_fileTitle, "*." + _suffixes.join(" *."))); if (!fileName.isEmpty()) { setFile(fileName); diff --git a/src/uconfig_gui/importer/filepage.h b/src/uconfig_gui/importer/filepage.h index a164c7b..b16f6ed 100644 --- a/src/uconfig_gui/importer/filepage.h +++ b/src/uconfig_gui/importer/filepage.h @@ -37,7 +37,7 @@ class FilePage : public QWizardPage int nextId() const override; void initializePage() override; - Q_PROPERTY(QString file READ file) + Q_PROPERTY(QString file CONSTANT READ file) QString file() const; protected: diff --git a/src/uconfig_gui/importer/pdffilepage.cpp b/src/uconfig_gui/importer/pdffilepage.cpp index fd59a4d..9831a9b 100644 --- a/src/uconfig_gui/importer/pdffilepage.cpp +++ b/src/uconfig_gui/importer/pdffilepage.cpp @@ -119,7 +119,7 @@ void PDFFilePage::check() { int start = -1; int stop = -1; - QRegularExpression reg("^([0-9]+)(\\-[0-9]+)?$"); + static QRegularExpression reg("^([0-9]+)(\\-[0-9]+)?$"); QRegularExpressionMatch match = reg.match(_rangeEdit->text()); start = match.captured(1).toInt() - 1; if (start >= _datasheetThread->datasheet()->pageCount() || start < 0) diff --git a/src/uconfig_gui/project/uconfigproject.cpp b/src/uconfig_gui/project/uconfigproject.cpp index 39433dc..e594ff1 100644 --- a/src/uconfig_gui/project/uconfigproject.cpp +++ b/src/uconfig_gui/project/uconfigproject.cpp @@ -87,7 +87,7 @@ void UConfigProject::openLib(const QString &libFileName) } if (fileDialog.exec() != 0) { - mlibFileName = fileDialog.selectedFiles().first(); + mlibFileName = fileDialog.selectedFiles().constFirst(); } if (mlibFileName.isEmpty()) { @@ -126,6 +126,7 @@ void UConfigProject::saveLib() void UConfigProject::saveLibAs(const QString &fileName) { + static QRegularExpression pdf_or_cvs("(.*)\\.(pdf|csv)"); QString libFileName; if (fileName.isEmpty()) @@ -138,12 +139,12 @@ void UConfigProject::saveLibAs(const QString &fileName) if (!_importedPathLib.isEmpty()) { libFileName = _importedPathLib; - libFileName.replace(QRegularExpression("(.*)\\.(pdf|csv)"), "\\1.lib"); + libFileName.replace(pdf_or_cvs, "\\1.lib"); fileDialog.selectFile(libFileName); } if (fileDialog.exec() != 0) { - libFileName = fileDialog.selectedFiles().first(); + libFileName = fileDialog.selectedFiles().constFirst(); } if (libFileName.isEmpty()) { @@ -187,7 +188,8 @@ void UConfigProject::importComponents(const QString &fileName) return; } - for (Component *component : importer.components()) + const auto& component_list = importer.components(); + for (Component *component : component_list) { _lib->addComponent(component); } diff --git a/src/uconfig_gui/project/uconfigproject.h b/src/uconfig_gui/project/uconfigproject.h index d39b3db..b1a501b 100644 --- a/src/uconfig_gui/project/uconfigproject.h +++ b/src/uconfig_gui/project/uconfigproject.h @@ -60,7 +60,7 @@ public slots: void selectComponent(Component *component); - void setComponentInfo(ComponentInfoType infoType, const QVariant &value); + void setComponentInfo(UConfigProject::ComponentInfoType infoType, const QVariant &value); signals: void libChanged(Lib *lib); diff --git a/src/uconfig_gui/uconfig_gui.cpp b/src/uconfig_gui/uconfig_gui.cpp index 500d9bc..4936ba6 100644 --- a/src/uconfig_gui/uconfig_gui.cpp +++ b/src/uconfig_gui/uconfig_gui.cpp @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) mainWindow.show(); if (QApplication::arguments().size() > 1) { - QString fileArg = QApplication::arguments()[1]; + QString fileArg = QApplication::arguments().at(1); if (fileArg.endsWith(".lib", Qt::CaseInsensitive)) { project.openLib(fileArg); diff --git a/src/uconfig_gui/uconfigmainwindow.cpp b/src/uconfig_gui/uconfigmainwindow.cpp index 7a5b9d8..699b3af 100644 --- a/src/uconfig_gui/uconfigmainwindow.cpp +++ b/src/uconfig_gui/uconfigmainwindow.cpp @@ -109,7 +109,8 @@ void UConfigMainWindow::dropEvent(QDropEvent *event) { event->accept(); - for (const QUrl &url : event->mimeData()->urls()) + const auto& urls = event->mimeData()->urls(); + for (const QUrl &url : urls) { QString fileName = url.toLocalFile(); _project->importComponents(fileName); @@ -193,7 +194,8 @@ void UConfigMainWindow::reloadRuleSetList() _ruleComboBox->clear(); _ruleComboBox->addItem(tr("package")); QDir dir(qApp->applicationDirPath() + "/../rules/"); - for (const QFileInfo &ruleInfo : dir.entryInfoList(QStringList() << "*.kss", QDir::NoDotAndDotDot | QDir::Files)) + const auto& entry_list = dir.entryInfoList(QStringList() << "*.kss", QDir::NoDotAndDotDot | QDir::Files); + for (const QFileInfo &ruleInfo : entry_list) { _ruleComboBox->addItem(ruleInfo.baseName()); } @@ -303,7 +305,7 @@ void UConfigMainWindow::updateOldProjects() { for (int i = 0; i < _project->oldProjects().size(); i++) { - QString path = _project->oldProjects()[i]; + QString path = _project->oldProjects().at(i); _oldProjectsActions[i]->setVisible(true); _oldProjectsActions[i]->setData(path); _oldProjectsActions[i]->setText(QString("&%1. %2").arg(i + 1).arg(path)); From 5d799a17ba467078c9c3140205a9633ec11be620 Mon Sep 17 00:00:00 2001 From: GravisZro Date: Mon, 11 Sep 2023 14:35:53 -0400 Subject: [PATCH 5/5] Overhaul PDF Model code I used re-structured the code to be more OO compliant. However, the main extraction loop was heavily modified to be readable. Some unused files were deleted and removed from the project file. Project file options were unified and updated for Appveyor. --- src/autotest/autotest.pro | 13 +- src/kicad/kicad.pro | 18 ++- src/pdf_extract/controller/pdfloader.cpp | 137 ------------------ src/pdf_extract/controller/pdfloader.h | 45 ------ .../controller/pdfpackagesearcher.cpp | 23 --- .../controller/pdfpackagesearcher.h | 30 ---- src/pdf_extract/datasheet.cpp | 3 +- src/pdf_extract/model/pdfcomponent.cpp | 23 --- src/pdf_extract/model/pdfcomponent.h | 30 ---- src/pdf_extract/model/pdfdatasheet.cpp | 48 +++--- src/pdf_extract/model/pdfdatasheet.h | 18 +-- src/pdf_extract/model/pdfpage.cpp | 73 +++++----- src/pdf_extract/model/pdfpage.h | 32 +--- src/pdf_extract/model/pdfpin.cpp | 23 --- src/pdf_extract/model/pdfpin.h | 30 ---- src/pdf_extract/model/pdftextbox.cpp | 24 +-- src/pdf_extract/model/pdftextbox.h | 10 +- src/pdf_extract/pdf_extract.pro | 25 ++-- .../pdfdebugwidget/pdfdebugitempage.cpp | 2 +- .../pdfdebugwidget/pdfdebugwidget.cpp | 18 +-- .../pdfdebugwidget/pdfdebugwidget.h | 1 - src/test/main.cpp | 3 + src/test/test.pro | 19 ++- src/uconfig/uconfig.pro | 16 +- src/uconfig_gui/uconfig_gui.pro | 16 +- 25 files changed, 145 insertions(+), 535 deletions(-) delete mode 100644 src/pdf_extract/controller/pdfloader.cpp delete mode 100644 src/pdf_extract/controller/pdfloader.h delete mode 100644 src/pdf_extract/controller/pdfpackagesearcher.cpp delete mode 100644 src/pdf_extract/controller/pdfpackagesearcher.h delete mode 100644 src/pdf_extract/model/pdfcomponent.cpp delete mode 100644 src/pdf_extract/model/pdfcomponent.h delete mode 100644 src/pdf_extract/model/pdfpin.cpp delete mode 100644 src/pdf_extract/model/pdfpin.h diff --git a/src/autotest/autotest.pro b/src/autotest/autotest.pro index d3d6e38..961ae19 100644 --- a/src/autotest/autotest.pro +++ b/src/autotest/autotest.pro @@ -1,6 +1,13 @@ -QT += testlib xml +QT += testlib +CONFIG += c++11 strict_c++ +CONFIG(release, debug|release):CONFIG += optimize_full + +# For Appveyor because it dumps includes in the project root +APPVEYOR_BUILD_FOLDER=$$(APPVEYOR_BUILD_FOLDER) +!isEmpty(APPVEYOR_BUILD_FOLDER) { + INCLUDEPATH += $$APPVEYOR_BUILD_FOLDER +} -CONFIG += optimize_full c++11 CONFIG += qt console warn_on depend_includepath testcase CONFIG -= app_bundle @@ -20,7 +27,7 @@ DEPENDPATH += $$SOURCE_ROOT/kicad $$SOURCE_ROOT/pdf_extract SOURCES += tst_pdf_extract.cpp -unix:{ +unix { QMAKE_LFLAGS_RPATH= QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'" } diff --git a/src/kicad/kicad.pro b/src/kicad/kicad.pro index b02314f..740e4eb 100644 --- a/src/kicad/kicad.pro +++ b/src/kicad/kicad.pro @@ -1,13 +1,15 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2014-08-05T17:49:45 -# -#------------------------------------------------- +QT += core gui widgets +QT += printsupport +# printer support is for PDF output -QT += gui printsupport -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +CONFIG += c++11 strict_c++ +CONFIG(release, debug|release):CONFIG += optimize_full -CONFIG += optimize_full c++11 +# For Appveyor because it dumps includes in the project root +APPVEYOR_BUILD_FOLDER=$$(APPVEYOR_BUILD_FOLDER) +!isEmpty(APPVEYOR_BUILD_FOLDER) { + INCLUDEPATH += $$APPVEYOR_BUILD_FOLDER +} TARGET = kicad TEMPLATE = lib diff --git a/src/pdf_extract/controller/pdfloader.cpp b/src/pdf_extract/controller/pdfloader.cpp deleted file mode 100644 index 4d3935f..0000000 --- a/src/pdf_extract/controller/pdfloader.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/** - ** This file is part of the uConfig project. - ** Copyright 2017-2020 Robotips, Sebastien CAUX (sebcaux) - ** - ** This program 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 3 of the License, or - ** (at your option) any later version. - ** - ** This program 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 this program. If not, see . - **/ - -#include "pdfloader.h" - -#include -#include - -#include - -PDFLoader::PDFLoader(PDFDatasheet *pdfDatasheet) - : _document(nullptr), - _pdfDatasheet(pdfDatasheet) -{ - _document = Poppler::Document::load(_pdfDatasheet->_fileName); - _pdfDatasheet->_pageCount = _document->numPages(); - _pdfDatasheet->_title = _document->info("Title"); - - _document->setRenderBackend(Poppler::Document::ArthurBackend); - _document->setRenderHint(Poppler::Document::Antialiasing, true); - _document->setRenderHint(Poppler::Document::TextAntialiasing, true); -} - -PDFLoader::~PDFLoader() -{ - if(_document != nullptr) - { - delete _document; - _document = nullptr; - } -} - -bool PDFLoader::loadPage(PDFPage *pdfPage) -{ - if (pdfPage->numPage() >= _document->numPages()) - { - return false; - } - - Poppler::Page *page = _document->page(pdfPage->numPage()); - if (page == nullptr) - { - return false; - } - pdfPage->_page = page; - pdfPage->_pageRect = QRect(QPoint(0, 0), page->pageSize()); - - return true; -} - -void PDFLoader::loadBoxes(PDFPage *pdfPage) -{ - PDFTextBox *parentTextBox = nullptr; - for (Poppler::TextBox *ptextBox : pdfPage->page()->textList()) - { - PDFTextBox *textBox = new PDFTextBox(ptextBox->text(), ptextBox->boundingBox()); - textBox->_page = pdfPage; - - bool padName = textBox->isPadName(); - if (padName) - { - textBox->_type = PDFTextBox::Pad; - } - if (parentTextBox == nullptr) - { - if (ptextBox->nextWord() == nullptr || padName) - { - pdfPage->_textBoxes.append(textBox); - } - else - { - parentTextBox = new PDFTextBox(QString(), ptextBox->boundingBox()); - parentTextBox->_page = pdfPage; - if (ptextBox->hasSpaceAfter()) - { - textBox->_text.append(QChar(' ')); - } - textBox->_parentBox = parentTextBox; - textBox->_type = PDFTextBox::SubText; - parentTextBox->_subBoxes.append(textBox); - } - } - else - { - if (padName) - { - pdfPage->_textBoxes.append(textBox); - } - else - { - textBox->_parentBox = parentTextBox; - textBox->_type = PDFTextBox::SubText; - parentTextBox->_subBoxes.append(textBox); - } - if (ptextBox->nextWord() == nullptr || padName) - { - QRectF boundingRect; - QString text; - for (PDFTextBox *subBox : parentTextBox->subBoxes()) - { - text.append(subBox->text()); - boundingRect = boundingRect.united(subBox->boundingRect()); - } - parentTextBox->_text = text; - parentTextBox->_boundingRect = boundingRect.adjusted(-1, -1, 1, 1); - - pdfPage->_textBoxes.append(parentTextBox); - parentTextBox = nullptr; - } - else - { - if (ptextBox->hasSpaceAfter()) - { - textBox->_text.append(QChar(' ')); - } - } - } - delete ptextBox; - ptextBox = nullptr; - } - pdfPage->_boxesLoaded = true; -} diff --git a/src/pdf_extract/controller/pdfloader.h b/src/pdf_extract/controller/pdfloader.h deleted file mode 100644 index 4096593..0000000 --- a/src/pdf_extract/controller/pdfloader.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - ** This file is part of the uConfig project. - ** Copyright 2017-2020 Robotips, Sebastien CAUX (sebcaux) - ** - ** This program 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 3 of the License, or - ** (at your option) any later version. - ** - ** This program 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 this program. If not, see . - **/ - -#ifndef PAGELOADER_H -#define PAGELOADER_H - -#include - -#include - -namespace Poppler -{ -class Document; -} - -class DATASHEET_EXTRACTOR_EXPORT PDFLoader -{ -public: - PDFLoader(PDFDatasheet *pdfDatasheet); - ~PDFLoader(); - - bool loadPage(PDFPage *pdfPage); - void loadBoxes(PDFPage *pdfPage); - -protected: - Poppler::Document *_document; - PDFDatasheet *_pdfDatasheet; -}; - -#endif // PAGELOADER_H diff --git a/src/pdf_extract/controller/pdfpackagesearcher.cpp b/src/pdf_extract/controller/pdfpackagesearcher.cpp deleted file mode 100644 index d543c33..0000000 --- a/src/pdf_extract/controller/pdfpackagesearcher.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/** - ** This file is part of the uConfig project. - ** Copyright 2017-2020 Robotips, Sebastien CAUX (sebcaux) - ** - ** This program 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 3 of the License, or - ** (at your option) any later version. - ** - ** This program 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 this program. If not, see . - **/ - -#include "pdfpackagesearcher.h" - -PDFPackageSearcher::PDFPackageSearcher() -{ -} diff --git a/src/pdf_extract/controller/pdfpackagesearcher.h b/src/pdf_extract/controller/pdfpackagesearcher.h deleted file mode 100644 index 4962cab..0000000 --- a/src/pdf_extract/controller/pdfpackagesearcher.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - ** This file is part of the uConfig project. - ** Copyright 2017-2020 Robotips, Sebastien CAUX (sebcaux) - ** - ** This program 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 3 of the License, or - ** (at your option) any later version. - ** - ** This program 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 this program. If not, see . - **/ - -#ifndef PDFPACKAGESEARCHER_H -#define PDFPACKAGESEARCHER_H - -#include - -class DATASHEET_EXTRACTOR_EXPORT PDFPackageSearcher -{ -public: - PDFPackageSearcher(); -}; - -#endif // PDFPACKAGESEARCHER_H diff --git a/src/pdf_extract/datasheet.cpp b/src/pdf_extract/datasheet.cpp index d4d931f..d3a35b8 100644 --- a/src/pdf_extract/datasheet.cpp +++ b/src/pdf_extract/datasheet.cpp @@ -21,12 +21,11 @@ #include #include #include -#include +//#include #include #include #include -#include #include using namespace Poppler; diff --git a/src/pdf_extract/model/pdfcomponent.cpp b/src/pdf_extract/model/pdfcomponent.cpp deleted file mode 100644 index d48d129..0000000 --- a/src/pdf_extract/model/pdfcomponent.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/** - ** This file is part of the uConfig project. - ** Copyright 2017-2020 Robotips, Sebastien CAUX (sebcaux) - ** - ** This program 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 3 of the License, or - ** (at your option) any later version. - ** - ** This program 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 this program. If not, see . - **/ - -#include "pdfcomponent.h" - -PDFComponent::PDFComponent() -{ -} diff --git a/src/pdf_extract/model/pdfcomponent.h b/src/pdf_extract/model/pdfcomponent.h deleted file mode 100644 index bc72637..0000000 --- a/src/pdf_extract/model/pdfcomponent.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - ** This file is part of the uConfig project. - ** Copyright 2017-2020 Robotips, Sebastien CAUX (sebcaux) - ** - ** This program 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 3 of the License, or - ** (at your option) any later version. - ** - ** This program 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 this program. If not, see . - **/ - -#ifndef PDFCOMPONENT_H -#define PDFCOMPONENT_H - -#include - -class DATASHEET_EXTRACTOR_EXPORT PDFComponent -{ -public: - PDFComponent(); -}; - -#endif // PDFCOMPONENT_H diff --git a/src/pdf_extract/model/pdfdatasheet.cpp b/src/pdf_extract/model/pdfdatasheet.cpp index 14dbad0..4fac9f2 100644 --- a/src/pdf_extract/model/pdfdatasheet.cpp +++ b/src/pdf_extract/model/pdfdatasheet.cpp @@ -18,25 +18,20 @@ #include "pdfdatasheet.h" -#include - -#include - -PDFDatasheet::PDFDatasheet(QString fileName) - : _pageCount(0), - _fileName(std::move(fileName)), - _pdfLoader(nullptr) +PDFDatasheet::PDFDatasheet(const QString& fileName) + : std::unique_ptr(Poppler::Document::load(fileName)), + _fileName(fileName) { - _pdfLoader = new PDFLoader(this); + if(*this) + { + get()->setRenderBackend(Poppler::Document::ArthurBackend); + get()->setRenderHint(Poppler::Document::Antialiasing, true); + get()->setRenderHint(Poppler::Document::TextAntialiasing, true); + } } PDFDatasheet::~PDFDatasheet() { - if(_pdfLoader != nullptr) - { - delete _pdfLoader; - _pdfLoader = nullptr; - } } const QString &PDFDatasheet::fileName() const @@ -44,30 +39,32 @@ const QString &PDFDatasheet::fileName() const return _fileName; } -const QString &PDFDatasheet::title() const +QString PDFDatasheet::title() const { - return _title; + return get()->info("Title"); } bool PDFDatasheet::loadPage(int numPage) { - if (numPage >= _pageCount || numPage < 0) + if (numPage >= pageCount() || numPage < 0) { return false; } - if (page(numPage) != nullptr) + + PDFPage *pdfPage = page(numPage); + + if (pdfPage == nullptr) { - return true; + pdfPage = new PDFPage(get()->page(numPage)); + _pagesLoaded.insert(numPage, pdfPage); } - PDFPage *page = new PDFPage(this, numPage); - _pagesLoaded.insert(numPage, page); - return _pdfLoader->loadPage(page); + return pdfPage->numPage() < pageCount(); } int PDFDatasheet::pageCount() const { - return _pageCount; + return get()->numPages(); } int PDFDatasheet::loadedPageCount() const @@ -84,8 +81,3 @@ PDFPage *PDFDatasheet::page(int numPage) } return *itFind; } - -PDFLoader *PDFDatasheet::pdfLoader() const -{ - return _pdfLoader; -} diff --git a/src/pdf_extract/model/pdfdatasheet.h b/src/pdf_extract/model/pdfdatasheet.h index d101a87..8455b87 100644 --- a/src/pdf_extract/model/pdfdatasheet.h +++ b/src/pdf_extract/model/pdfdatasheet.h @@ -21,21 +21,22 @@ #include +#include +#include + #include "pdfpage.h" #include #include -class PDFLoader; - -class DATASHEET_EXTRACTOR_EXPORT PDFDatasheet +class DATASHEET_EXTRACTOR_EXPORT PDFDatasheet : protected std::unique_ptr { public: - PDFDatasheet(QString fileName); + PDFDatasheet(const QString& fileName); ~PDFDatasheet(); const QString &fileName() const; - const QString &title() const; + QString title() const; bool loadPage(int numPage); @@ -43,16 +44,9 @@ class DATASHEET_EXTRACTOR_EXPORT PDFDatasheet int loadedPageCount() const; PDFPage *page(int numPage); - PDFLoader *pdfLoader() const; - protected: - int _pageCount; QMap _pagesLoaded; QString _fileName; - QString _title; - - friend class PDFLoader; - PDFLoader *_pdfLoader; }; #endif // PDFDATASHEET_H diff --git a/src/pdf_extract/model/pdfpage.cpp b/src/pdf_extract/model/pdfpage.cpp index 2515268..ece688b 100644 --- a/src/pdf_extract/model/pdfpage.cpp +++ b/src/pdf_extract/model/pdfpage.cpp @@ -17,17 +17,11 @@ **/ #include "pdfpage.h" -#include -#include "pdfdatasheet.h" -#include - -PDFPage::PDFPage(PDFDatasheet *datasheet, int numPage) - : _datasheet(datasheet), - _numPage(numPage), - _boxesLoaded(false), - _page(nullptr) +PDFPage::PDFPage(Poppler::Page *page) + : std::unique_ptr(page) { + loadBoxes(); } PDFPage::~PDFPage() @@ -37,46 +31,53 @@ PDFPage::~PDFPage() delete textBox; textBox = nullptr; } - delete _page; - _page = nullptr; -} - -PDFDatasheet *PDFPage::datasheet() const -{ - return _datasheet; } int PDFPage::numPage() const { - return _numPage; + return get()->index(); } -const QRect &PDFPage::pageRect() const +QRect PDFPage::pageRect() const { - return _pageRect; -} - -const QImage &PDFPage::image() const -{ - return _image; -} - -Poppler::Page *PDFPage::page() const -{ - return _page; + return QRect(QPoint(0, 0), get()->pageSize()); } void PDFPage::loadBoxes() { - if (!_boxesLoaded) + QString fullText; + QRectF fullBoundingRect; + const auto& texts = get()->textList(); + for (Poppler::TextBox *ptextBox : texts) { - _datasheet->pdfLoader()->loadBoxes(this); - } -} + bool isNumber = false; + QString text = ptextBox->text(); + text.toInt(&isNumber); -bool PDFPage::boxesLoaded() const -{ - return _boxesLoaded; + if(fullText.isEmpty() || isNumber) + { + _textBoxes.append(new PDFTextBox(text, ptextBox->boundingBox())); + } + else + { + fullBoundingRect = fullBoundingRect.united(ptextBox->boundingBox()); + fullText += text; + + if(ptextBox->nextWord() != nullptr) + { + if(!ptextBox->hasSpaceAfter()) + fullText.append(QChar(' ')); + } + else + { + _textBoxes.append(new PDFTextBox(fullText, fullBoundingRect.adjusted(-1, -1, 1, 1))); + fullText.clear(); + fullBoundingRect = QRectF(); + } + } + delete ptextBox; + ptextBox = nullptr; + } } const QList &PDFPage::textBoxes() const diff --git a/src/pdf_extract/model/pdfpage.h b/src/pdf_extract/model/pdfpage.h index 04db0aa..7a458fb 100644 --- a/src/pdf_extract/model/pdfpage.h +++ b/src/pdf_extract/model/pdfpage.h @@ -21,48 +21,30 @@ #include +#include +#include + #include "pdftextbox.h" #include #include #include -namespace Poppler -{ -class Page; -} - -class PDFDatasheet; - -class DATASHEET_EXTRACTOR_EXPORT PDFPage +class DATASHEET_EXTRACTOR_EXPORT PDFPage : public std::unique_ptr { public: - PDFPage(PDFDatasheet *datasheet, int numPage = 0); + PDFPage(Poppler::Page *page); ~PDFPage(); - PDFDatasheet *datasheet() const; - int numPage() const; - const QRect &pageRect() const; - const QImage &image() const; + QRect pageRect() const; - Poppler::Page *page() const; - - void loadBoxes(); - bool boxesLoaded() const; const QList &textBoxes() const; protected: - PDFDatasheet *_datasheet; - int _numPage; - QRect _pageRect; - QImage _image; + void loadBoxes(); - bool _boxesLoaded; QList _textBoxes; - - friend class PDFLoader; - Poppler::Page *_page; }; #endif // PDFPAGE_H diff --git a/src/pdf_extract/model/pdfpin.cpp b/src/pdf_extract/model/pdfpin.cpp deleted file mode 100644 index 2655c4f..0000000 --- a/src/pdf_extract/model/pdfpin.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/** - ** This file is part of the uConfig project. - ** Copyright 2017-2020 Robotips, Sebastien CAUX (sebcaux) - ** - ** This program 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 3 of the License, or - ** (at your option) any later version. - ** - ** This program 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 this program. If not, see . - **/ - -#include "pdfpin.h" - -PDFPin::PDFPin() -{ -} diff --git a/src/pdf_extract/model/pdfpin.h b/src/pdf_extract/model/pdfpin.h deleted file mode 100644 index c2016d1..0000000 --- a/src/pdf_extract/model/pdfpin.h +++ /dev/null @@ -1,30 +0,0 @@ -/** - ** This file is part of the uConfig project. - ** Copyright 2017-2020 Robotips, Sebastien CAUX (sebcaux) - ** - ** This program 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 3 of the License, or - ** (at your option) any later version. - ** - ** This program 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 this program. If not, see . - **/ - -#ifndef PDFPIN_H -#define PDFPIN_H - -#include - -class DATASHEET_EXTRACTOR_EXPORT PDFPin -{ -public: - PDFPin(); -}; - -#endif // PDFPIN_H diff --git a/src/pdf_extract/model/pdftextbox.cpp b/src/pdf_extract/model/pdftextbox.cpp index 9223547..a6b24b4 100644 --- a/src/pdf_extract/model/pdftextbox.cpp +++ b/src/pdf_extract/model/pdftextbox.cpp @@ -18,15 +18,15 @@ #include "pdftextbox.h" -#include - -PDFTextBox::PDFTextBox(QString text, const QRectF &boundingRect) - : _text(std::move(text)), +PDFTextBox::PDFTextBox(const QString& text, const QRectF &boundingRect) + : _text(text), _boundingRect(boundingRect), - _type(Text), - _page(nullptr), - _parentBox(nullptr) + _type(Text) { + if(isPadName()) + { + _type = PDFTextBox::Pad; + } } PDFTextBox::~PDFTextBox() @@ -68,13 +68,3 @@ PDFTextBox::Type PDFTextBox::type() const { return _type; } - -PDFTextBox *PDFTextBox::parentBox() const -{ - return _parentBox; -} - -PDFPage *PDFTextBox::page() const -{ - return _page; -} diff --git a/src/pdf_extract/model/pdftextbox.h b/src/pdf_extract/model/pdftextbox.h index 1492648..2343272 100644 --- a/src/pdf_extract/model/pdftextbox.h +++ b/src/pdf_extract/model/pdftextbox.h @@ -21,8 +21,6 @@ #include -class PDFPage; - #include #include #include @@ -30,7 +28,7 @@ class PDFPage; class DATASHEET_EXTRACTOR_EXPORT PDFTextBox { public: - PDFTextBox(QString text, const QRectF &boundingRect); + PDFTextBox(const QString& text, const QRectF &boundingRect); ~PDFTextBox(); const QString &text() const; @@ -46,18 +44,12 @@ class DATASHEET_EXTRACTOR_EXPORT PDFTextBox Type type() const; const QList &subBoxes() const; - PDFTextBox *parentBox() const; - PDFPage *page() const; - protected: QString _text; QRectF _boundingRect; Type _type; QList _subBoxes; - PDFPage *_page; - PDFTextBox *_parentBox; - friend class PDFLoader; }; #endif // PDFTEXTBOX_H diff --git a/src/pdf_extract/pdf_extract.pro b/src/pdf_extract/pdf_extract.pro index 5d3caf2..373c5b4 100644 --- a/src/pdf_extract/pdf_extract.pro +++ b/src/pdf_extract/pdf_extract.pro @@ -1,4 +1,12 @@ -QT += core gui widgets xml +QT += core gui widgets +CONFIG += c++11 strict_c++ +CONFIG(release, debug|release):CONFIG += optimize_full + +# For Appveyor because it dumps includes in the project root +APPVEYOR_BUILD_FOLDER=$$(APPVEYOR_BUILD_FOLDER) +!isEmpty(APPVEYOR_BUILD_FOLDER) { + INCLUDEPATH += $$APPVEYOR_BUILD_FOLDER +} TARGET = pdf_extract TEMPLATE = lib @@ -11,11 +19,6 @@ INCLUDEPATH += $$SOURCE_ROOT DEFINES += KICAD_EXPORT=Q_DECL_IMPORT DEFINES += DATASHEET_EXTRACTOR_EXPORT_LIB -CONFIG(release, debug|release) { - CONFIG += optimize_full -} -CONFIG += c++11 - SOURCES += \ $$PWD/datasheet.cpp \ $$PWD/datasheetpackage.cpp \ @@ -30,10 +33,6 @@ SOURCES += \ $$PWD/model/pdfdatasheet.cpp \ $$PWD/model/pdfpage.cpp \ $$PWD/model/pdftextbox.cpp \ - $$PWD/model/pdfpin.cpp \ - $$PWD/model/pdfcomponent.cpp \ - $$PWD/controller/pdfloader.cpp \ - $$PWD/controller/pdfpackagesearcher.cpp HEADERS += \ $$PWD/pdf_extract_common.h \ @@ -49,11 +48,7 @@ HEADERS += \ $$PWD/pdfdebugwidget/pdfdebugitemtextbox.h \ $$PWD/model/pdfdatasheet.h \ $$PWD/model/pdfpage.h \ - $$PWD/model/pdftextbox.h \ - $$PWD/model/pdfpin.h \ - $$PWD/model/pdfcomponent.h \ - $$PWD/controller/pdfloader.h \ - $$PWD/controller/pdfpackagesearcher.h + $$PWD/model/pdftextbox.h LIBS += -L"$$PROJECT_ROOT/bin" INCLUDEPATH += $$PROJECT_ROOT/ diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.cpp b/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.cpp index efc8c9e..14d266e 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.cpp +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugitempage.cpp @@ -55,7 +55,7 @@ void PdfDebugItemPage::paint(QPainter *painter, const QStyleOptionGraphicsItem * painter->setPen(Qt::black); - _page->page()->renderToPainter(painter, 72.0, 72.0, 0, 0, _page->pageRect().width(), _page->pageRect().width(), Poppler::Page::Rotate0); + _page->get()->renderToPainter(painter, 72.0, 72.0, 0, 0, _page->pageRect().width(), _page->pageRect().width(), Poppler::Page::Rotate0); // const qreal lod = option->levelOfDetailFromTransform(painter->worldTransform()); // QImage image = _page->page()->renderToImage(72.0 * lod, 72.0 * lod, 0 ,0); diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.cpp b/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.cpp index c69d047..22166fc 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.cpp +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.cpp @@ -80,23 +80,9 @@ void PdfDebugWidget::showPage(int page) { return; } - showPage(pdfPage); -} - -void PdfDebugWidget::showPage(PDFPage *page) -{ - if (page->datasheet() != _datasheet) - { - setDatasheet(page->datasheet()); - } - - if (!page->boxesLoaded()) - { - page->loadBoxes(); - } - _currentPage = page; - _viewer->setPage(page); + _currentPage = pdfPage; + _viewer->setPage(pdfPage); _pageLineEdit->setText(QString::number(_currentPage->numPage() + 1)); emit pageChanged(_currentPage->numPage()); } diff --git a/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.h b/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.h index e2ce1ef..3ca8fb9 100644 --- a/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.h +++ b/src/pdf_extract/pdfdebugwidget/pdfdebugwidget.h @@ -47,7 +47,6 @@ class DATASHEET_EXTRACTOR_EXPORT PdfDebugWidget : public QWidget public slots: void showPage(int page); - void showPage(PDFPage *page); void previous(); void next(); diff --git a/src/test/main.cpp b/src/test/main.cpp index 9d3f073..4d32a2d 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -112,6 +112,9 @@ int main(int argc, char *argv[]) // PDFDatasheet pdf("../src/autotest/ATmega328P_pins.pdf"); // PDFDatasheet pdf("C:/Users/seb/Seafile/UniSwarm/DataSheets/Microchip/PIC16b/dsPIC33EP/PIC24-dsPIC33-EPxxxGP-MC-20x-50x_revH.pdf"); + Q_ASSERT(pdf.pageCount() > 0); + qDebug("page count: %u", pdf.pageCount()); + PdfDebugWidget viewer(&pdf); viewer.showPage(0); viewer.show(); diff --git a/src/test/test.pro b/src/test/test.pro index 6e58871..e928f9d 100644 --- a/src/test/test.pro +++ b/src/test/test.pro @@ -1,13 +1,12 @@ -#------------------------------------------------- -# -# Project created by QtCreator 2014-08-06T09:40:31 -# -#------------------------------------------------- - -QT += core gui printsupport -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += optimize_full c++11 +QT += core gui widgets +CONFIG += c++11 strict_c++ +CONFIG(release, debug|release):CONFIG += optimize_full + +# For Appveyor because it dumps includes in the project root +APPVEYOR_BUILD_FOLDER=$$(APPVEYOR_BUILD_FOLDER) +!isEmpty(APPVEYOR_BUILD_FOLDER) { + INCLUDEPATH += $$APPVEYOR_BUILD_FOLDER +} TARGET = test TEMPLATE = app diff --git a/src/uconfig/uconfig.pro b/src/uconfig/uconfig.pro index 82d2b80..60801e8 100644 --- a/src/uconfig/uconfig.pro +++ b/src/uconfig/uconfig.pro @@ -1,6 +1,12 @@ -QT += core gui xml widgets - -CONFIG += optimize_full c++11 +QT += core gui widgets +CONFIG += c++11 strict_c++ +CONFIG(release, debug|release):CONFIG += optimize_full + +# For Appveyor because it dumps includes in the project root +APPVEYOR_BUILD_FOLDER=$$(APPVEYOR_BUILD_FOLDER) +!isEmpty(APPVEYOR_BUILD_FOLDER) { + INCLUDEPATH += $$APPVEYOR_BUILD_FOLDER +} TARGET = uconfig TEMPLATE = app @@ -14,9 +20,7 @@ DEFINES += KICAD_EXPORT=Q_DECL_IMPORT SOURCES += $$PWD/uconfig.cpp -HEADERS += - -unix:{ +unix { QMAKE_LFLAGS_RPATH= QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'" } diff --git a/src/uconfig_gui/uconfig_gui.pro b/src/uconfig_gui/uconfig_gui.pro index 561de26..01e66c8 100644 --- a/src/uconfig_gui/uconfig_gui.pro +++ b/src/uconfig_gui/uconfig_gui.pro @@ -1,6 +1,12 @@ -QT += core gui xml widgets - -CONFIG += optimize_full c++11 +QT += core gui widgets +CONFIG += c++11 strict_c++ +CONFIG(release, debug|release):CONFIG += optimize_full + +# For Appveyor because it dumps includes in the project root +APPVEYOR_BUILD_FOLDER=$$(APPVEYOR_BUILD_FOLDER) +!isEmpty(APPVEYOR_BUILD_FOLDER) { + INCLUDEPATH += $$APPVEYOR_BUILD_FOLDER +} TARGET = uconfig_gui TEMPLATE = app @@ -42,7 +48,7 @@ HEADERS += \ RESOURCES += \ $$PWD/img.qrc -unix:{ +unix { QMAKE_LFLAGS_RPATH= QMAKE_LFLAGS += "-Wl,-rpath,\'\$$ORIGIN\'" } @@ -52,4 +58,4 @@ LIBS += -lkicad -lpdf_extract INCLUDEPATH += $$SOURCE_ROOT/kicad DEPENDPATH += $$SOURCE_ROOT/kicad -win32 : RC_FILE = uconfig_gui.rc +win32:RC_FILE = uconfig_gui.rc