freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] gsoc-2022-chariri-2 f57587d 11/30: [ftinspect] Fix par


From: Werner Lemberg
Subject: [freetype2-demos] gsoc-2022-chariri-2 f57587d 11/30: [ftinspect] Fix parent-child relationships in Qt objects tree.
Date: Mon, 11 Jul 2022 07:17:38 -0400 (EDT)

branch: gsoc-2022-chariri-2
commit f57587da3295650fbb8283f5d0274e89cd93b148
Author: Charlie Jiang <w@chariri.moe>
Commit: Charlie Jiang <w@chariri.moe>

    [ftinspect] Fix parent-child relationships in Qt objects tree.
    
    Most Qt objects' parent should be explicitly set to have the object included
    in the Qt object tree. This ensures that all objects is properly deleted 
when
    their parents is being deleted.
    
    Note that `QLayout::addWidgets` doesn't take ownership of the widget, so no
    auto-parenting is done here! However, `QWidget::setLayout` does set the 
parent
    of the layout automatically to the widget, so no need to specify parents for
    layouts.
    
    * src/ftinspect/maingui.cpp: Add `this` for all non-layout sub-widgets.
    
    * src/ftinspect/widgets/custom_widgets.cpp,
      src/ftinspect/widgets/custom_widgets.hpp,
      src/ftinspect/models/ttsettingscomboboxmodel.cpp,
      src/ftinspect/models/ttsettingscomboboxmodel.hpp: Add `parent` as
      constructor parameters and pass it up to the base class constructor.
    
    * src/ftinspect/panels/settingpanel.cpp,
      src/ftinspect/panels/settingpanel.hpp: Both of the above.
---
 src/ftinspect/maingui.cpp                        | 67 ++++++++++++------------
 src/ftinspect/models/ttsettingscomboboxmodel.cpp | 15 ++++--
 src/ftinspect/models/ttsettingscomboboxmodel.hpp |  8 +--
 src/ftinspect/panels/settingpanel.cpp            | 50 +++++++++---------
 src/ftinspect/panels/settingpanel.hpp            |  2 +-
 src/ftinspect/widgets/custom_widgets.cpp         | 10 +++-
 src/ftinspect/widgets/custom_widgets.hpp         |  3 +-
 7 files changed, 86 insertions(+), 69 deletions(-)

diff --git a/src/ftinspect/maingui.cpp b/src/ftinspect/maingui.cpp
index 74b6b6c..510f110 100644
--- a/src/ftinspect/maingui.cpp
+++ b/src/ftinspect/maingui.cpp
@@ -553,12 +553,12 @@ void
 MainGUI::createLayout()
 {
   // left side
-  fontFilenameLabel_ = new QLabel;
+  fontFilenameLabel_ = new QLabel(this);
 
   infoLeftLayout_ = new QHBoxLayout;
   infoLeftLayout_->addWidget(fontFilenameLabel_);
 
-  settingPanel_ = new SettingPanel(engine_);
+  settingPanel_ = new SettingPanel(this, engine_);
 
   leftLayout_ = new QVBoxLayout;
   leftLayout_->addLayout(infoLeftLayout_);
@@ -566,7 +566,7 @@ MainGUI::createLayout()
 
   // we don't want to expand the left side horizontally;
   // to change the policy we have to use a widget wrapper
-  leftWidget_ = new QWidget;
+  leftWidget_ = new QWidget(this);
   leftWidget_->setLayout(leftLayout_);
 
   QSizePolicy leftWidgetPolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
@@ -577,11 +577,11 @@ MainGUI::createLayout()
   leftWidget_->setSizePolicy(leftWidgetPolicy);
 
   // right side
-  glyphIndexLabel_ = new QLabel;
-  glyphNameLabel_ = new QLabel;
-  fontNameLabel_ = new QLabel;
+  glyphIndexLabel_ = new QLabel(this);
+  glyphNameLabel_ = new QLabel(this);
+  fontNameLabel_ = new QLabel(this);
 
-  glyphScene_ = new QGraphicsScene;
+  glyphScene_ = new QGraphicsScene(this);
   glyphScene_->addItem(new Grid(gridPen_, axisPen_));
 
   currentGlyphBitmapItem_ = NULL;
@@ -589,7 +589,7 @@ MainGUI::createLayout()
   currentGlyphPointsItem_ = NULL;
   currentGlyphPointNumbersItem_ = NULL;
 
-  glyphView_ = new QGraphicsViewx;
+  glyphView_ = new QGraphicsViewx(this);
   glyphView_->setRenderHint(QPainter::Antialiasing, true);
   glyphView_->setDragMode(QGraphicsView::ScrollHandDrag);
   glyphView_->setOptimizationFlags(QGraphicsView::DontSavePainterState);
@@ -597,7 +597,7 @@ MainGUI::createLayout()
   glyphView_->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
   glyphView_->setScene(glyphScene_);
 
-  sizeLabel_ = new QLabel(tr("Size "));
+  sizeLabel_ = new QLabel(tr("Size "), this);
   sizeLabel_->setAlignment(Qt::AlignRight);
   sizeDoubleSpinBox_ = new QDoubleSpinBox;
   sizeDoubleSpinBox_->setAlignment(Qt::AlignRight);
@@ -605,42 +605,43 @@ MainGUI::createLayout()
   sizeDoubleSpinBox_->setRange(1, 500);
   sizeLabel_->setBuddy(sizeDoubleSpinBox_);
 
-  unitsComboBox_ = new QComboBox;
+  unitsComboBox_ = new QComboBox(this);
   unitsComboBox_->insertItem(Units_px, "px");
   unitsComboBox_->insertItem(Units_pt, "pt");
 
-  dpiLabel_ = new QLabel(tr("DPI "));
+  dpiLabel_ = new QLabel(tr("DPI "), this);
   dpiLabel_->setAlignment(Qt::AlignRight);
-  dpiSpinBox_ = new QSpinBox;
+  dpiSpinBox_ = new QSpinBox(this);
   dpiSpinBox_->setAlignment(Qt::AlignRight);
   dpiSpinBox_->setRange(10, 600);
   dpiLabel_->setBuddy(dpiSpinBox_);
 
-  toStartButtonx_ = new QPushButtonx("|<");
-  toM1000Buttonx_ = new QPushButtonx("-1000");
-  toM100Buttonx_ = new QPushButtonx("-100");
-  toM10Buttonx_ = new QPushButtonx("-10");
-  toM1Buttonx_ = new QPushButtonx("-1");
-  toP1Buttonx_ = new QPushButtonx("+1");
-  toP10Buttonx_ = new QPushButtonx("+10");
-  toP100Buttonx_ = new QPushButtonx("+100");
-  toP1000Buttonx_ = new QPushButtonx("+1000");
-  toEndButtonx_ = new QPushButtonx(">|");
-
-  zoomLabel_ = new QLabel(tr("Zoom Factor"));
+  toStartButtonx_ = new QPushButtonx("|<", this);
+  toM1000Buttonx_ = new QPushButtonx("-1000", this);
+  toM100Buttonx_ = new QPushButtonx("-100", this);
+  toM10Buttonx_ = new QPushButtonx("-10", this);
+  toM1Buttonx_ = new QPushButtonx("-1", this);
+  toP1Buttonx_ = new QPushButtonx("+1", this);
+  toP10Buttonx_ = new QPushButtonx("+10", this);
+  toP100Buttonx_ = new QPushButtonx("+100", this);
+  toP1000Buttonx_ = new QPushButtonx("+1000", this);
+  toEndButtonx_ = new QPushButtonx(">|", this);
+
+  zoomLabel_ = new QLabel(tr("Zoom Factor"), this);
   zoomLabel_->setAlignment(Qt::AlignRight);
-  zoomSpinBox_ = new QSpinBoxx;
+  zoomSpinBox_ = new QSpinBoxx(this);
   zoomSpinBox_->setAlignment(Qt::AlignRight);
   zoomSpinBox_->setRange(1, 1000 - 1000 % 64);
   zoomSpinBox_->setKeyboardTracking(false);
   zoomLabel_->setBuddy(zoomSpinBox_);
 
-  previousFontButton_ = new QPushButton(tr("Previous Font"));
-  nextFontButton_ = new QPushButton(tr("Next Font"));
-  previousFaceButton_ = new QPushButton(tr("Previous Face"));
-  nextFaceButton_ = new QPushButton(tr("Next Face"));
-  previousNamedInstanceButton_ = new QPushButton(tr("Previous Named 
Instance"));
-  nextNamedInstanceButton_ = new QPushButton(tr("Next Named Instance"));
+  previousFontButton_ = new QPushButton(tr("Previous Font"), this);
+  nextFontButton_ = new QPushButton(tr("Next Font"), this);
+  previousFaceButton_ = new QPushButton(tr("Previous Face"), this);
+  nextFaceButton_ = new QPushButton(tr("Next Face"), this);
+  previousNamedInstanceButton_
+    = new QPushButton(tr("Previous Named Instance"), this);
+  nextNamedInstanceButton_ = new QPushButton(tr("Next Named Instance"), this);
 
   infoRightLayout = new QGridLayout;
   infoRightLayout->addWidget(glyphIndexLabel_, 0, 0);
@@ -697,7 +698,7 @@ MainGUI::createLayout()
   rightLayout_->addLayout(fontLayout);
 
   // for symmetry with the left side use a widget also
-  rightWidget_ = new QWidget;
+  rightWidget_ = new QWidget(this);
   rightWidget_->setLayout(rightLayout_);
 
   // the whole thing
@@ -705,7 +706,7 @@ MainGUI::createLayout()
   ftinspectLayout_->addWidget(leftWidget_);
   ftinspectLayout_->addWidget(rightWidget_);
 
-  ftinspectWidget_ = new QWidget;
+  ftinspectWidget_ = new QWidget(this);
   ftinspectWidget_->setLayout(ftinspectLayout_);
   setCentralWidget(ftinspectWidget_);
   setWindowTitle("ftinspect");
diff --git a/src/ftinspect/models/ttsettingscomboboxmodel.cpp 
b/src/ftinspect/models/ttsettingscomboboxmodel.cpp
index 750c629..c5a3975 100644
--- a/src/ftinspect/models/ttsettingscomboboxmodel.cpp
+++ b/src/ftinspect/models/ttsettingscomboboxmodel.cpp
@@ -17,7 +17,8 @@
 //
 /////////////////////////////////////////////////////////////////////////////
 
-HintingModeComboBoxModel::HintingModeComboBoxModel()
+HintingModeComboBoxModel::HintingModeComboBoxModel(QObject* parent)
+: QAbstractListModel(parent)
 {
   items_[HintingMode_TrueType_v35] = {
     HintingEngineType_TrueType,
@@ -196,6 +197,12 @@ 
HintingModeComboBoxModel::setCurrentEngineType(HintingEngineType type)
 /////////////////////////////////////////////////////////////////////////////
 
 
+SimpleComboBoxModel::SimpleComboBoxModel(QObject* parent)
+: QAbstractListModel(parent)
+{
+}
+
+
 int
 SimpleComboBoxModel::rowCount(const QModelIndex& parent) const
 {
@@ -232,7 +239,8 @@ SimpleComboBoxModel::indexToValue(int index)
 /////////////////////////////////////////////////////////////////////////////
 
 
-LCDFilterComboBoxModel::LCDFilterComboBoxModel()
+LCDFilterComboBoxModel::LCDFilterComboBoxModel(QObject* parent)
+: SimpleComboBoxModel(parent)
 {
   items_[LCDFilter_Default] = {
     FT_LCD_FILTER_DEFAULT,
@@ -260,7 +268,8 @@ LCDFilterComboBoxModel::LCDFilterComboBoxModel()
 /////////////////////////////////////////////////////////////////////////////
 
 
-AntiAliasingComboBoxModel::AntiAliasingComboBoxModel()
+AntiAliasingComboBoxModel::AntiAliasingComboBoxModel(QObject* parent)
+: SimpleComboBoxModel(parent)
 {
   items_[AntiAliasing_None] = {
     FT_LOAD_TARGET_MONO,
diff --git a/src/ftinspect/models/ttsettingscomboboxmodel.hpp 
b/src/ftinspect/models/ttsettingscomboboxmodel.hpp
index 0298ac4..3d3489f 100644
--- a/src/ftinspect/models/ttsettingscomboboxmodel.hpp
+++ b/src/ftinspect/models/ttsettingscomboboxmodel.hpp
@@ -25,7 +25,7 @@ public:
     QString displayName;
   };
 
-  HintingModeComboBoxModel();
+  explicit HintingModeComboBoxModel(QObject* parent);
   ~HintingModeComboBoxModel() = default;
 
   int rowCount(const QModelIndex& parent) const;
@@ -82,7 +82,7 @@ public:
     QString displayName;
   };
 
-  SimpleComboBoxModel() {}
+  explicit SimpleComboBoxModel(QObject* parent);
   ~SimpleComboBoxModel() = default;
 
   int rowCount(const QModelIndex& parent) const;
@@ -107,7 +107,7 @@ public:
     QString displayName;
   };
 
-  LCDFilterComboBoxModel();
+  explicit LCDFilterComboBoxModel(QObject* parent);
   ~LCDFilterComboBoxModel() = default;
 
 public:
@@ -127,7 +127,7 @@ class AntiAliasingComboBoxModel
 public:
   enum AntiAliasing : int;
 
-  AntiAliasingComboBoxModel();
+  explicit AntiAliasingComboBoxModel(QObject* parent);
   ~AntiAliasingComboBoxModel() = default;
   
   QVariant data(const QModelIndex& index,
diff --git a/src/ftinspect/panels/settingpanel.cpp 
b/src/ftinspect/panels/settingpanel.cpp
index 308a9e8..4673e3a 100644
--- a/src/ftinspect/panels/settingpanel.cpp
+++ b/src/ftinspect/panels/settingpanel.cpp
@@ -5,8 +5,8 @@
 
 #include "settingpanel.hpp"
 
-SettingPanel::SettingPanel(Engine* engine)
-: engine_(engine)
+SettingPanel::SettingPanel(QWidget* parent, Engine* engine)
+: QWidget(parent), engine_(engine)
 {
   createLayout();
   setDefaults();
@@ -278,35 +278,35 @@ SettingPanel::createConnections()
 void
 SettingPanel::createLayout()
 {
-  hintingCheckBox_ = new QCheckBox(tr("Hinting"));
+  hintingCheckBox_ = new QCheckBox(tr("Hinting"), this);
 
-  hintingModeLabel_ = new QLabel(tr("Hinting Mode"));
+  hintingModeLabel_ = new QLabel(tr("Hinting Mode"), this);
   hintingModeLabel_->setAlignment(Qt::AlignRight);
 
-  hintingModeComboBoxModel_ = new HintingModeComboBoxModel;
-  hintingModeComboBox_ = new QComboBox;
+  hintingModeComboBoxModel_ = new HintingModeComboBoxModel(this);
+  hintingModeComboBox_ = new QComboBox(this);
   hintingModeComboBox_->setModel(hintingModeComboBoxModel_);
   hintingModeLabel_->setBuddy(hintingModeComboBox_);
 
-  autoHintingCheckBox_ = new QCheckBox(tr("Auto-Hinting"));
-  horizontalHintingCheckBox_ = new QCheckBox(tr("Horizontal Hinting"));
-  verticalHintingCheckBox_ = new QCheckBox(tr("Vertical Hinting"));
-  blueZoneHintingCheckBox_ = new QCheckBox(tr("Blue-Zone Hinting"));
-  segmentDrawingCheckBox_ = new QCheckBox(tr("Segment Drawing"));
+  autoHintingCheckBox_ = new QCheckBox(tr("Auto-Hinting"), this);
+  horizontalHintingCheckBox_ = new QCheckBox(tr("Horizontal Hinting"), this);
+  verticalHintingCheckBox_ = new QCheckBox(tr("Vertical Hinting"), this);
+  blueZoneHintingCheckBox_ = new QCheckBox(tr("Blue-Zone Hinting"), this);
+  segmentDrawingCheckBox_ = new QCheckBox(tr("Segment Drawing"), this);
 
-  antiAliasingLabel_ = new QLabel(tr("Anti-Aliasing"));
+  antiAliasingLabel_ = new QLabel(tr("Anti-Aliasing"), this);
   antiAliasingLabel_->setAlignment(Qt::AlignRight);
 
-  antiAliasingComboBoxModel_ = new AntiAliasingComboBoxModel;
-  antiAliasingComboBox_ = new QComboBox;
+  antiAliasingComboBoxModel_ = new AntiAliasingComboBoxModel(this);
+  antiAliasingComboBox_ = new QComboBox(this);
   antiAliasingComboBox_->setModel(antiAliasingComboBoxModel_);
   antiAliasingLabel_->setBuddy(antiAliasingComboBox_);
 
   lcdFilterLabel_ = new QLabel(tr("LCD Filter"));
   lcdFilterLabel_->setAlignment(Qt::AlignRight);
 
-  lcdFilterComboboxModel_ = new LCDFilterComboBoxModel;
-  lcdFilterComboBox_ = new QComboBox;
+  lcdFilterComboboxModel_ = new LCDFilterComboBoxModel(this);
+  lcdFilterComboBox_ = new QComboBox(this);
   lcdFilterComboBox_->setModel(lcdFilterComboboxModel_);
   lcdFilterLabel_->setBuddy(lcdFilterComboBox_);
 
@@ -328,18 +328,18 @@ SettingPanel::createLayout()
   antiAliasingComboBox_->setMinimumWidth(width);
   lcdFilterComboBox_->setMinimumWidth(width);
 
-  gammaLabel_ = new QLabel(tr("Gamma"));
+  gammaLabel_ = new QLabel(tr("Gamma"), this);
   gammaLabel_->setAlignment(Qt::AlignRight);
-  gammaSlider_ = new QSlider(Qt::Horizontal);
+  gammaSlider_ = new QSlider(Qt::Horizontal, this);
   gammaSlider_->setRange(0, 30); // in 1/10th
   gammaSlider_->setTickPosition(QSlider::TicksBelow);
   gammaSlider_->setTickInterval(5);
   gammaLabel_->setBuddy(gammaSlider_);
 
-  showBitmapCheckBox_ = new QCheckBox(tr("Show Bitmap"));
-  showPointsCheckBox_ = new QCheckBox(tr("Show Points"));
-  showPointNumbersCheckBox_ = new QCheckBox(tr("Show Point Numbers"));
-  showOutlinesCheckBox_ = new QCheckBox(tr("Show Outlines"));
+  showBitmapCheckBox_ = new QCheckBox(tr("Show Bitmap"), this);
+  showPointsCheckBox_ = new QCheckBox(tr("Show Points"), this);
+  showPointNumbersCheckBox_ = new QCheckBox(tr("Show Point Numbers"), this);
+  showOutlinesCheckBox_ = new QCheckBox(tr("Show Outlines"), this);
 
   hintingModeLayout_ = new QHBoxLayout;
   hintingModeLayout_->addWidget(hintingModeLabel_);
@@ -399,12 +399,12 @@ SettingPanel::createLayout()
   generalTabLayout_->addLayout(pointNumbersLayout_);
   generalTabLayout_->addWidget(showOutlinesCheckBox_);
 
-  generalTab_ = new QWidget;
+  generalTab_ = new QWidget(this);
   generalTab_->setLayout(generalTabLayout_);
 
-  mmgxTab_ = new QWidget;
+  mmgxTab_ = new QWidget(this);
 
-  tab_ = new QTabWidget;
+  tab_ = new QTabWidget(this);
   tab_->addTab(generalTab_, tr("General"));
   tab_->addTab(mmgxTab_, tr("MM/GX"));
 
diff --git a/src/ftinspect/panels/settingpanel.hpp 
b/src/ftinspect/panels/settingpanel.hpp
index d917f14..ba133c7 100644
--- a/src/ftinspect/panels/settingpanel.hpp
+++ b/src/ftinspect/panels/settingpanel.hpp
@@ -19,7 +19,7 @@ class SettingPanel
 {
   Q_OBJECT
 public:
-  SettingPanel(Engine* engine);
+  SettingPanel(QWidget* parent, Engine* engine);
   ~SettingPanel() = default;
 
   void syncSettings();
diff --git a/src/ftinspect/widgets/custom_widgets.cpp 
b/src/ftinspect/widgets/custom_widgets.cpp
index 15ed26f..6856a26 100644
--- a/src/ftinspect/widgets/custom_widgets.cpp
+++ b/src/ftinspect/widgets/custom_widgets.cpp
@@ -12,8 +12,8 @@
 // >>>>>>>> QGraphicsViewx <<<<<<<<
 // --------------------------------
 
-QGraphicsViewx::QGraphicsViewx()
-: lastBottomLeftPointInitialized_(false)
+QGraphicsViewx::QGraphicsViewx(QWidget* parent)
+: QGraphicsView(parent), lastBottomLeftPointInitialized_(false)
 {
   // empty
 }
@@ -104,6 +104,12 @@ QSpinBoxx::valueFromText(const QString& text) const
 }
 
 
+QSpinBoxx::QSpinBoxx(QWidget* parent)
+: QSpinBox(parent)
+{
+}
+
+
 void
 QSpinBoxx::stepBy(int steps)
 {
diff --git a/src/ftinspect/widgets/custom_widgets.hpp 
b/src/ftinspect/widgets/custom_widgets.hpp
index bbe1d28..18dd6d2 100644
--- a/src/ftinspect/widgets/custom_widgets.hpp
+++ b/src/ftinspect/widgets/custom_widgets.hpp
@@ -24,7 +24,7 @@ class QGraphicsViewx
   Q_OBJECT
 
 public:
-  QGraphicsViewx();
+  QGraphicsViewx(QWidget* parent);
 
 protected:
   void resizeEvent(QResizeEvent* event);
@@ -57,6 +57,7 @@ class QSpinBoxx
   Q_OBJECT
 
 public:
+  QSpinBoxx(QWidget* parent);
   void stepBy(int val);
   int valueFromText(const QString& text) const;
 };



reply via email to

[Prev in Thread] Current Thread [Next in Thread]