From c2f85dd23dc686ed64f41cf580498392cba6ca46 Mon Sep 17 00:00:00 2001 From: Montel Laurent Date: Mon, 23 Oct 2017 09:36:27 +0200 Subject: [PATCH] Initialize pointer/value. Minor optimization --- kcm/src/collapsablebutton.cpp | 2 +- kcm/src/controlpanel.h | 2 +- kcm/src/declarative/qmloutputcomponent.cpp | 9 +++------ kcm/src/declarative/qmlscreen.cpp | 10 +++++----- kcm/src/declarative/qmlscreen.h | 9 ++++++--- kcm/src/kcm_kscreen.h | 4 ++-- kcm/src/outputconfig.h | 14 +++++++------- kcm/src/previewwidget.h | 4 ++-- kcm/src/primaryoutputcombo.h | 4 ++-- kcm/src/resolutionslider.h | 12 ++++++------ kcm/src/widget.cpp | 2 +- kcm/src/widget.h | 22 +++++++++++----------- 12 files changed, 47 insertions(+), 47 deletions(-) diff --git a/kcm/src/collapsablebutton.cpp b/kcm/src/collapsablebutton.cpp index 6be807e..f4a3b2b 100644 --- a/kcm/src/collapsablebutton.cpp +++ b/kcm/src/collapsablebutton.cpp @@ -30,7 +30,7 @@ CollapsableButton::CollapsableButton(const QString &text, QWidget *parent) : QWidget(parent) , mCollapsed(false) - , mWidget(0) + , mWidget(nullptr) { QHBoxLayout *layout = new QHBoxLayout(this); mLabel = new QLabel(text, this); diff --git a/kcm/src/controlpanel.h b/kcm/src/controlpanel.h index ec18646..7bab7e4 100644 --- a/kcm/src/controlpanel.h +++ b/kcm/src/controlpanel.h @@ -40,7 +40,7 @@ class ControlPanel : public QFrame Q_OBJECT public: - explicit ControlPanel(QWidget *parent = 0); + explicit ControlPanel(QWidget *parent = nullptr); virtual ~ControlPanel(); void setConfig(const KScreen::ConfigPtr &config); diff --git a/kcm/src/declarative/qmloutputcomponent.cpp b/kcm/src/declarative/qmloutputcomponent.cpp index 98bf832..4dc6838 100644 --- a/kcm/src/declarative/qmloutputcomponent.cpp +++ b/kcm/src/declarative/qmloutputcomponent.cpp @@ -44,16 +44,13 @@ QMLOutputComponent::~QMLOutputComponent() QMLOutput* QMLOutputComponent::createForOutput(const KScreen::OutputPtr &output) { - QObject *instance; - - instance = beginCreate(m_engine->rootContext()); + QObject *instance = beginCreate(m_engine->rootContext()); if (!instance) { qWarning() << errorString(); - return 0; + return nullptr; } - bool success = false; - success = instance->setProperty("outputPtr", QVariant::fromValue(output)); + bool success = instance->setProperty("outputPtr", QVariant::fromValue(output)); Q_ASSERT(success); success = instance->setProperty("screen", QVariant::fromValue(qobject_cast(parent()))); Q_ASSERT(success); diff --git a/kcm/src/declarative/qmlscreen.cpp b/kcm/src/declarative/qmlscreen.cpp index 6f44312..5b8e2f9 100644 --- a/kcm/src/declarative/qmlscreen.cpp +++ b/kcm/src/declarative/qmlscreen.cpp @@ -33,13 +33,13 @@ QMLScreen::QMLScreen(QQuickItem *parent): QQuickItem(parent), - m_config(0), + m_config(nullptr), m_connectedOutputsCount(0), m_enabledOutputsCount(0), - m_leftmost(0), - m_topmost(0), - m_rightmost(0), - m_bottommost(0) + m_leftmost(nullptr), + m_topmost(nullptr), + m_rightmost(nullptr), + m_bottommost(nullptr) { connect(this, &QMLScreen::widthChanged, this, &QMLScreen::viewSizeChanged); connect(this, &QMLScreen::heightChanged, this, &QMLScreen::viewSizeChanged); diff --git a/kcm/src/declarative/qmlscreen.h b/kcm/src/declarative/qmlscreen.h index d74fbbc..1c3d54b 100644 --- a/kcm/src/declarative/qmlscreen.h +++ b/kcm/src/declarative/qmlscreen.h @@ -56,7 +56,7 @@ class QMLScreen : public QQuickItem MEMBER m_engine) public: - explicit QMLScreen(QQuickItem *parent = 0); + explicit QMLScreen(QQuickItem *parent = nullptr); virtual ~QMLScreen(); @@ -111,8 +111,11 @@ class QMLScreen : public QQuickItem int m_connectedOutputsCount; int m_enabledOutputsCount; - QQmlEngine* m_engine; - QMLOutput *m_leftmost, *m_topmost, *m_rightmost, *m_bottommost; + QQmlEngine* m_engine = nullptr; + QMLOutput *m_leftmost = nullptr; + QMLOutput *m_topmost = nullptr; + QMLOutput *m_rightmost = nullptr; + QMLOutput *m_bottommost = nullptr; }; diff --git a/kcm/src/kcm_kscreen.h b/kcm/src/kcm_kscreen.h index 93837c4..fc72ab8 100644 --- a/kcm/src/kcm_kscreen.h +++ b/kcm/src/kcm_kscreen.h @@ -34,7 +34,7 @@ class KCMKScreen : public KCModule Q_OBJECT public: - explicit KCMKScreen (QWidget* parent = 0, const QVariantList& args = QVariantList()); + explicit KCMKScreen (QWidget* parent = nullptr, const QVariantList& args = QVariantList()); virtual ~KCMKScreen(); virtual QSize sizeHint() const Q_DECL_OVERRIDE; @@ -48,7 +48,7 @@ class KCMKScreen : public KCModule private: void configReady(KScreen::ConfigOperation *op); - Widget *mKScreenWidget; + Widget *mKScreenWidget = nullptr; bool m_blockChanges = false; QHBoxLayout *mMainLayout = nullptr; diff --git a/kcm/src/outputconfig.h b/kcm/src/outputconfig.h index 08535df..b85dfda 100644 --- a/kcm/src/outputconfig.h +++ b/kcm/src/outputconfig.h @@ -40,7 +40,7 @@ class OutputConfig : public QWidget public: explicit OutputConfig(QWidget *parent); - explicit OutputConfig(const KScreen::OutputPtr &output, QWidget *parent = 0); + explicit OutputConfig(const KScreen::OutputPtr &output, QWidget *parent = nullptr); virtual ~OutputConfig(); virtual void setOutput(const KScreen::OutputPtr &output); @@ -63,13 +63,13 @@ class OutputConfig : public QWidget virtual void initUi(); protected: - QLabel *mTitle; + QLabel *mTitle = nullptr; KScreen::OutputPtr mOutput; - QCheckBox *mEnabled; - ResolutionSlider *mResolution; - QComboBox *mRotation; - QComboBox *mScale; - QComboBox *mRefreshRate; + QCheckBox *mEnabled = nullptr; + ResolutionSlider *mResolution = nullptr; + QComboBox *mRotation = nullptr; + QComboBox *mScale = nullptr; + QComboBox *mRefreshRate = nullptr; bool mShowScaleOption = false; }; diff --git a/kcm/src/previewwidget.h b/kcm/src/previewwidget.h index f0c07a8..7b81e9c 100644 --- a/kcm/src/previewwidget.h +++ b/kcm/src/previewwidget.h @@ -28,7 +28,7 @@ class PreviewWidget : public QLabel { Q_OBJECT public: - PreviewWidget(QWidget *parent=0); + explicit PreviewWidget(QWidget *parent=nullptr); ~PreviewWidget(); void setScale(qreal scale); public Q_SLOTS: @@ -36,7 +36,7 @@ public Q_SLOTS: private: qreal pointSizeToPixelSize(qreal pointSize) const; qreal m_scale; - QWidget *m_internalPreview; + QWidget *m_internalPreview = nullptr; }; #endif // PREVIEWWIDGET_H diff --git a/kcm/src/primaryoutputcombo.h b/kcm/src/primaryoutputcombo.h index 8077534..eb7a223 100644 --- a/kcm/src/primaryoutputcombo.h +++ b/kcm/src/primaryoutputcombo.h @@ -30,7 +30,7 @@ class PrimaryOutputCombo : public QComboBox { Q_OBJECT public: - explicit PrimaryOutputCombo(QWidget *parent = 0); + explicit PrimaryOutputCombo(QWidget *parent = nullptr); virtual ~PrimaryOutputCombo(); void setConfig(const KScreen::ConfigPtr &config); @@ -55,4 +55,4 @@ private: KScreen::ConfigPtr mConfig; }; -#endif \ No newline at end of file +#endif diff --git a/kcm/src/resolutionslider.h b/kcm/src/resolutionslider.h index 0224416..403314d 100644 --- a/kcm/src/resolutionslider.h +++ b/kcm/src/resolutionslider.h @@ -36,7 +36,7 @@ class ResolutionSlider : public QWidget Q_OBJECT public: - explicit ResolutionSlider(const KScreen::OutputPtr &output, QWidget *parent = 0); + explicit ResolutionSlider(const KScreen::OutputPtr &output, QWidget *parent = nullptr); virtual ~ResolutionSlider(); QSize currentResolution() const; @@ -53,11 +53,11 @@ class ResolutionSlider : public QWidget QList mModes; - QLabel *mSmallestLabel; - QLabel *mBiggestLabel; - QLabel *mCurrentLabel; - QSlider *mSlider; - QComboBox *mComboBox; + QLabel *mSmallestLabel = nullptr; + QLabel *mBiggestLabel = nullptr; + QLabel *mCurrentLabel = nullptr; + QSlider *mSlider = nullptr; + QComboBox *mComboBox = nullptr; }; #endif // RESOLUTIONSLIDER_H diff --git a/kcm/src/widget.cpp b/kcm/src/widget.cpp index 248f5bd..b5a8ab1 100644 --- a/kcm/src/widget.cpp +++ b/kcm/src/widget.cpp @@ -190,7 +190,7 @@ void Widget::setConfig(const KScreen::ConfigPtr &config) if (qmlOutput) { mScreen->setActiveOutput(qmlOutput); } else { - if (mScreen->outputs().count() > 0) { + if (!mScreen->outputs().isEmpty()) { mScreen->setActiveOutput(mScreen->outputs()[0]); } } diff --git a/kcm/src/widget.h b/kcm/src/widget.h index 326349a..d95df89 100644 --- a/kcm/src/widget.h +++ b/kcm/src/widget.h @@ -46,7 +46,7 @@ class Widget : public QWidget Q_OBJECT public: - explicit Widget(QWidget *parent = 0); + explicit Widget(QWidget *parent = nullptr); virtual ~Widget(); void setConfig(const KScreen::ConfigPtr &config); @@ -80,23 +80,23 @@ class Widget : public QWidget KScreen::OutputPtr findOutput(const KScreen::ConfigPtr &config, const QVariantMap &info); private: - QMLScreen *mScreen; + QMLScreen *mScreen = nullptr; KScreen::ConfigPtr mConfig; KScreen::ConfigPtr mPrevConfig; - QQuickView *mDeclarativeView; - ControlPanel *mControlPanel; + QQuickView *mDeclarativeView = nullptr; + ControlPanel *mControlPanel = nullptr; - ProfilesModel *mProfilesModel; - PrimaryOutputCombo *mPrimaryCombo; - QComboBox *mProfilesCombo; + ProfilesModel *mProfilesModel = nullptr; + PrimaryOutputCombo *mPrimaryCombo = nullptr; + QComboBox *mProfilesCombo = nullptr; - QPushButton *mScaleAllOutputsButton; - QPushButton *mUnifyButton; - QPushButton *mSaveProfileButton; + QPushButton *mScaleAllOutputsButton = nullptr; + QPushButton *mUnifyButton = nullptr; + QPushButton *mSaveProfileButton = nullptr; QList mOutputIdentifiers; - QTimer *mOutputTimer; + QTimer *mOutputTimer = nullptr; }; -- GitLab