Skip to content

Commit

Permalink
Infrastructure: move away from constructor initialisation lists - par…
Browse files Browse the repository at this point in the history
…t 2 (#5937)

For classes from "T2*" to "TM*" (approximately)...

I have steered away from using `{}` to initialise simple, POD data types in
favour of explicitly stating what their default values are.

Also:
* remove unused `(QColor) TAction::mButtonColor` and it's associated
  getter and setter. Also remove the save code from the `XMLexport`
  class and ensure it is skipped and silently discarded in the load
  code in `XMLimport`.
* Make `private` some members of the `TFlipButton` class that probably
  weren't ever intended to be `public`
* Remove unneeded named argument for `lua_State*` type in many (but not
  all) function declarations in `TLuaInterpreter.h` file - they aren't
  needed and whether an `L` was present or not seems to entirely down to
  the whim of the individual coder of each function...!
* Rejig some of the initiliasations in the `TLuaInterpreter` class
* Refactor a chunk of code n the `TMap` class used to (re)initialise the
  16 colours user settable from the preferences dialogue to a method:
  `(void) TMap::restore16ColorSet()` - so that it can be used in three
  other places as well as the constuctor.
* Remove unused `(int) T2DMap::gzoom`.
* Add missing `TMediaData.h` file to qmake project file.

Note: `QPointer<T>` instances do NOT need initialisation, they are
automagically instantiated with a `nullptr` value.

Revised to change code to fit in with PR #6133

There were some pre-Qt 5.14.0 version checks that are no longer relevant.

Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
Co-authored-by: Vadim Peretokin <vperetokin@gmail.com>
  • Loading branch information
SlySven and vadi2 committed Jun 27, 2022
1 parent 1fd3f68 commit 4655c93
Show file tree
Hide file tree
Showing 48 changed files with 762 additions and 953 deletions.
61 changes: 2 additions & 59 deletions src/T2DMap.cpp
@@ -1,6 +1,6 @@
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2013-2016, 2018-2021 by Stephen Lyons *
* Copyright (C) 2013-2016, 2018-2022 by Stephen Lyons *
* - slysven@virginmedia.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2021-2022 by Piotr Wilczynski - delwing@gmail.com *
Expand Down Expand Up @@ -81,60 +81,6 @@ const QString& key_icon_dialog_cancel = qsl(":/icons/dialog-cancel.png");

T2DMap::T2DMap(QWidget* parent)
: QWidget(parent)
, xyzoom(20)
, mRX()
, mRY()
, mTarget()
, mStartSpeedWalk()
, mRoomBeingMoved()
, mRoomWidth()
, mRoomHeight()
, mChosenRoomColor(5)
, xspan()
, yspan()
, mMultiSelection()
, mMultiRect()
, mPopupMenu()
, mNewMoveAction()
, mMapInfoRect()
, mFontHeight(20)
, mShowRoomID(false)
, gzoom(20)
, rSize(0.5)
, eSize(3.0)
, mRoomID()
, mAreaID()
, mOx()
, mOy()
, mOz()
, mShiftMode()
, arealist_combobox()
, mpCustomLinesDialog()
, mCustomLinesRoomFrom()
, mCustomLinesRoomTo()
, mpCurrentLineStyle()
, mpCurrentLineColor()
, mpCurrentLineArrow()
, mCurrentLineStyle(Qt::SolidLine)
, mCurrentLineColor(Qt::red)
, mCurrentLineArrow(true)
, mBubbleMode()
, mMapperUseAntiAlias(true)
, mLabelHighlighted(false)
, mMoveLabel()
, mCustomLineSelectedRoom()
, mCustomLineSelectedExit()
, mCustomLineSelectedPoint(-1)
, mMultiSelectionListWidget(this)
, mSizeLabel()
, isCenterViewCall()
, mDialogLock()
, mMultiSelectionHighlightRoomId(0)
, mIsSelectionSorting(true)
, mIsSelectionSortByNames()
, mIsSelectionUsingNames(false)
, mSymbolFontSize(1)
, mMaxRoomIdDigits(0)
{
mMultiSelectionListWidget.setColumnCount(2);
mMultiSelectionListWidget.hideColumn(1);
Expand Down Expand Up @@ -171,8 +117,6 @@ void T2DMap::init()
return;
}

isCenterViewCall = false;

eSize = mpHost->mLineSize;
rSize = mpHost->mRoomSize;
mMapperUseAntiAlias = mpHost->mMapperUseAntiAlias;
Expand Down Expand Up @@ -2080,12 +2024,11 @@ void T2DMap::paintRoomExits(QPainter& painter, QPen& pen, QList<int>& exitList,
}

// draw exit stubs
QMap<int, QVector3D> unitVectors = mpMap->unitVectors;
for (int direction : qAsConst(room->exitStubs)) {
if (direction >= DIR_NORTH && direction <= DIR_SOUTHWEST) {
// Stubs on non-XY plane exits are handled differently and we
// do not support special exit stubs (yet?)
QVector3D uDirection = unitVectors[direction];
QVector3D uDirection = mpMap->scmUnitVectors.value(direction);
QLineF stubLine(rx, ry, rx + uDirection.x() * 0.5 * mRoomWidth, ry + uDirection.y() * 0.5 * mRoomHeight);
const QString doorKey{TRoom::dirCodeToShortString(direction)};
// Draw the door lines before we draw the stub or the filled
Expand Down
98 changes: 51 additions & 47 deletions src/T2DMap.h
Expand Up @@ -4,7 +4,7 @@
/***************************************************************************
* Copyright (C) 2008-2012 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2016, 2018-2019 by Stephen Lyons *
* Copyright (C) 2016, 2018-2019, 2022 by Stephen Lyons *
* - slysven@virginmedia.com *
* Copyright (C) 2021-2022 by Piotr Wilczynski - delwing@gmail.com *
* *
Expand Down Expand Up @@ -92,13 +92,13 @@ class T2DMap : public QWidget

TMap* mpMap = nullptr;
QPointer<Host> mpHost;
qreal xyzoom;
int mRX;
int mRY;
qreal xyzoom = 20.0;
int mRX = 0;
int mRY = 0;
QPoint mPHighlight;
bool mPick = false;
int mTarget;
bool mStartSpeedWalk;
int mTarget = 0;
bool mStartSpeedWalk = false;


// string list: 0 is event name, 1 is menu it is under if it is
Expand All @@ -107,43 +107,47 @@ class T2DMap : public QWidget
// unique name, List:parent name ("" if null), display name
QMap<QString, QStringList> mUserMenus;

bool mRoomBeingMoved;
bool mRoomBeingMoved = false;
// These are the on-screen width and height pixel numbers of the area for a
// room symbol, (for the non-grid map mode case what gets filled in is
// multiplied by rsize which is 1.0 to exactly fill space between adjacent
// coordinates):
float mRoomWidth;
float mRoomHeight;
int mChosenRoomColor;
float xspan;
float yspan;
float mRoomWidth = 0.0f;
float mRoomHeight = 0.0f;
int mChosenRoomColor = 5;
float xspan = 0.0f;
float yspan = 0.0f;

// Flag that the "drag to select rectangle"
// (mMultiRect) is active and is being *resized*
// by dragging
bool mMultiSelection;
bool mMultiSelection = false;

QRectF mMultiRect;
bool mPopupMenu;
bool mPopupMenu = false;
QSet<int> mMultiSelectionSet;
bool mNewMoveAction;
bool mNewMoveAction = false;
QRect mMapInfoRect;
int mFontHeight;
bool mShowRoomID;
int mFontHeight = 20;
bool mShowRoomID = false;
QMap<int, QPixmap> mPixMap;
int gzoom;
double rSize;
double eSize;
int mRoomID;
int mAreaID;
qreal mOx;
qreal mOy;
int mOz;
bool mShiftMode;
QComboBox* arealist_combobox;
double rSize = 0.5;
double eSize = 3.0;
int mRoomID = 0;
int mAreaID = 0;
// These next three represent the room coordinates at the middle of the map
// the first pair needs to not be integer types as a more flexible zoom
// in/out mechanism was adopted that meant non-integral coordinates were
// needed, OTOH a "snap to a fractional (power of 2?) value" might help to
// keep the decimal numbers reasonable:
qreal mOx = 0.0;
qreal mOy = 0.0;
int mOz = 0;
bool mShiftMode = false;
QComboBox* arealist_combobox = nullptr;
QPointer<QDialog> mpCustomLinesDialog;
int mCustomLinesRoomFrom;
int mCustomLinesRoomTo;
int mCustomLinesRoomFrom = 0;
int mCustomLinesRoomTo = 0;
QString mCustomLinesRoomExit;

// Pointers to controls that hold the settings
Expand All @@ -152,24 +156,24 @@ class T2DMap : public QWidget
QPointer<QCheckBox> mpCurrentLineArrow;

// Variables that hold the current or last used setting:
Qt::PenStyle mCurrentLineStyle;
QColor mCurrentLineColor;
bool mCurrentLineArrow;
Qt::PenStyle mCurrentLineStyle = Qt::SolidLine;
QColor mCurrentLineColor = QColorConstants::Red;
bool mCurrentLineArrow = true;

bool mBubbleMode;
bool mMapperUseAntiAlias;
bool mBubbleMode = false;
bool mMapperUseAntiAlias = true;

// Controls if the mapper is in view-only mode
bool mMapViewOnly = true;

bool mLabelHighlighted;
bool mMoveLabel;
int mCustomLineSelectedRoom;
bool mLabelHighlighted = false;
bool mMoveLabel = false;
int mCustomLineSelectedRoom = 0;
QString mCustomLineSelectedExit;
int mCustomLineSelectedPoint;
int mCustomLineSelectedPoint = -1;
QTreeWidget mMultiSelectionListWidget;
bool mSizeLabel;
bool isCenterViewCall;
bool mSizeLabel = false;
bool isCenterViewCall = false;
QString mHelpMsg;
QColor mOpenDoorColor = QColor(10, 155, 10);
QColor mClosedDoorColor = QColor(155, 155, 10);
Expand Down Expand Up @@ -245,7 +249,7 @@ public slots:
void updateMapLabel(QRectF labelRectangle, int labelId, TArea* pArea);


bool mDialogLock;
bool mDialogLock = false;
struct ClickPosition {
int x;
int y;
Expand All @@ -264,21 +268,21 @@ public slots:
// implemented, slot_setExits(),
// slot_movePosition(), etc.} - previously have
// used -1 but is now reset to 0 if it is not valid.
int mMultiSelectionHighlightRoomId;
int mMultiSelectionHighlightRoomId = 0;

bool mIsSelectionSorting;
bool mIsSelectionSortByNames;
bool mIsSelectionSorting = true;
bool mIsSelectionSortByNames = false;

// Used to keep track of if sorting the multiple
// room listing/selection widget, and by what,
// as we now show room names (if present) as well.
bool mIsSelectionUsingNames;
bool mIsSelectionUsingNames = false;
QCache<QString, QPixmap> mSymbolPixmapCache;
ushort mSymbolFontSize;
ushort mSymbolFontSize = 1;
QFont mMapSymbolFont;
QPointer<QAction> mpCreateRoomAction;
// in the players current area, how many digits does the biggest room number have?
quint8 mMaxRoomIdDigits;
quint8 mMaxRoomIdDigits = 0;

// Holds the QRadialGradient details to use for the player room:
QGradientStops mPlayerRoomColorGradentStops;
Expand Down
49 changes: 2 additions & 47 deletions src/TAction.cpp
@@ -1,7 +1,8 @@
/***************************************************************************
* Copyright (C) 2008-2013 by Heiko Koehn - KoehnHeiko@googlemail.com *
* Copyright (C) 2014 by Ahmed Charles - acharles@outlook.com *
* Copyright (C) 2017, 2021 by Stephen Lyons - slysven@virginmedia.com *
* Copyright (C) 2017, 2021-2022 by Stephen Lyons *
* - slysven@virginmedia.com *
* *
* 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 *
Expand Down Expand Up @@ -34,60 +35,14 @@

TAction::TAction(TAction* parent, Host* pHost)
: Tree<TAction>(parent)
, mpToolBar(nullptr)
, mpEasyButtonBar(nullptr)
, mButtonState(false)
, mPosX(0)
, mPosY(0)
, mOrientation()
, mLocation()
, mIsPushDownButton()
, mNeedsToBeCompiled(true)
, mButtonRotation()
, mButtonColumns(1)
, mButtonFlat()
, mSizeX()
, mSizeY()
, mIsLabel(false)
, mUseCustomLayout(false)
, mButtonColor(QColor(Qt::white))
, mpHost(pHost)
, exportItem(true)
, mModuleMasterFolder(false)
, mToolbarLastDockArea(Qt::LeftDockWidgetArea)
, mToolbarLastFloatingState(true)
, mModuleMember(false)
, mDataChanged(true)
{
}

TAction::TAction(const QString& name, Host* pHost)
: Tree<TAction>(nullptr)
, mpToolBar(nullptr)
, mpEasyButtonBar(nullptr)
, mButtonState(false)
, mPosX(0)
, mPosY(0)
, mOrientation()
, mLocation()
, mIsPushDownButton()
, mNeedsToBeCompiled(true)
, mButtonRotation()
, mButtonColumns(1)
, mButtonFlat()
, mSizeX()
, mSizeY()
, mIsLabel(false)
, mUseCustomLayout(false)
, mButtonColor(QColor(Qt::white))
, mpHost(pHost)
, exportItem(true)
, mModuleMasterFolder(false)
, mToolbarLastDockArea(Qt::LeftDockWidgetArea)
, mToolbarLastFloatingState(true)
, mName(name)
, mModuleMember(false)
, mDataChanged(true)
{
}

Expand Down

0 comments on commit 4655c93

Please sign in to comment.