Skip to content

Commit c75dcde

Browse files
committed
minor cleanup of QtSLiM code thanks to clang-tidy and clazy
1 parent 6c8832a commit c75dcde

23 files changed

+145
-135
lines changed

QtSLiM/QtSLiMAppDelegate.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,11 @@ void QtSLiMAppDelegate::updateRecentFileActions()
543543

544544
const QStringList recentFiles = readRecentFiles(settings);
545545
const int count = qMin(int(MaxRecentFiles), recentFiles.size());
546+
QList<QAction *> actions = menu->actions();
546547

547548
for (int i = 0 ; i < MaxRecentFiles; ++i)
548549
{
549-
QAction *recentAction = menu->actions()[i];
550+
QAction *recentAction = actions[i];
550551

551552
if (i < count)
552553
{
@@ -711,9 +712,9 @@ void QtSLiMAppDelegate::findRecipe(void)
711712

712713
if (result == QDialog::Accepted)
713714
{
714-
QStringList resourceNames = findRecipePanel.selectedRecipeFilenames();
715+
const QStringList resourceNames = findRecipePanel.selectedRecipeFilenames();
715716

716-
for (QString resourceName : resourceNames)
717+
for (const QString &resourceName : resourceNames)
717718
{
718719
//qDebug() << "recipe name:" << resourceName;
719720

@@ -769,8 +770,9 @@ void QtSLiMAppDelegate::openRecipe(void)
769770
void QtSLiMAppDelegate::playStateChanged(void)
770771
{
771772
bool anyPlaying = false;
773+
const QWidgetList topLevelWidgets = qApp->topLevelWidgets();
772774

773-
for (QWidget *widget : qApp->topLevelWidgets())
775+
for (QWidget *widget : topLevelWidgets)
774776
{
775777
QtSLiMWindow *mainWin = qobject_cast<QtSLiMWindow *>(widget);
776778

@@ -1168,7 +1170,6 @@ QWidget *QtSLiMAppDelegate::globalImageWindowWithPath(const QString &path, const
11681170
return nullptr;
11691171
}
11701172

1171-
QFileInfo fileInfo(path);
11721173
int window_width = round(image.width() * scaleFactor);
11731174
int window_height = round(image.height() * scaleFactor);
11741175

QtSLiM/QtSLiMConsoleTextEdit.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
#include <algorithm>
3232

33-
#include "QtSLiMPreferences.h"
3433
#include "QtSLiMExtras.h"
3534
#include "eidos_globals.h"
3635
#include "slim_globals.h"

QtSLiM/QtSLiMEidosConsole.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
#include <string>
3131

3232
#include "QtSLiMWindow.h"
33-
#include "QtSLiMPreferences.h"
3433
#include "QtSLiMVariableBrowser.h"
3534
#include "QtSLiMExtras.h"
3635

QtSLiM/QtSLiMEidosConsole_glue.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <QKeyEvent>
2626
#include <QDesktopServices>
2727

28-
#include "QtSLiMWindow.h"
2928
#include "QtSLiMAppDelegate.h"
3029

3130

QtSLiM/QtSLiMEidosPrettyprinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ bool Eidos_prettyprintTokensFromScript(const std::vector<EidosToken> &tokens, Ei
154154
{
155155
// We use QString to get intelligent treatment of Unicode and UTF-8; std::string is just too dumb.
156156
// In SLiMGui this is done with NSString. We want to count newlines in a mac/unix/windows agnostic way.
157-
QString q_tokenString = QString::fromStdString(tokenString);
157+
const QString q_tokenString = QString::fromStdString(tokenString);
158158
int newlineCount = 0;
159159
bool prevWasCR = false, prevWasLF = false;
160160

QtSLiM/QtSLiMExtras.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ QStringList QtSLiMRunLineEditArrayDialog(QWidget *p_parent, QString title, QStri
751751
{
752752
QStringList returnList;
753753

754-
for (QLineEdit *lineEdit : lineEdits)
754+
for (QLineEdit *lineEdit : qAsConst(lineEdits))
755755
returnList.append(lineEdit->text());
756756

757757
delete dialog;

QtSLiM/QtSLiMFindRecipe.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ QtSLiMFindRecipe::~QtSLiMFindRecipe()
7979

8080
QStringList QtSLiMFindRecipe::selectedRecipeFilenames(void)
8181
{
82-
QList<QListWidgetItem *> selectedItems = ui->matchListWidget->selectedItems();
82+
const QList<QListWidgetItem *> selectedItems = ui->matchListWidget->selectedItems();
8383
QStringList selectedFilenames;
8484

8585
for (QListWidgetItem *selectedItem : selectedItems)
@@ -182,7 +182,7 @@ void QtSLiMFindRecipe::updateMatchListWidget(void)
182182

183183
matchList->clear();
184184

185-
for (const QString &match : matchRecipeFilenames)
185+
for (const QString &match : qAsConst(matchRecipeFilenames))
186186
matchList->addItem(displayStringForRecipeFilename(match));
187187
}
188188

@@ -238,14 +238,14 @@ void QtSLiMFindRecipe::highlightPreview(void)
238238
QString keyword1 = ui->keyword1LineEdit->text();
239239
QString keyword2 = ui->keyword2LineEdit->text();
240240
QString keyword3 = ui->keyword3LineEdit->text();
241-
std::vector<QString> keywords{keyword1, keyword2, keyword3};
241+
const std::vector<QString> keywords{keyword1, keyword2, keyword3};
242242

243243
QList<QTextEdit::ExtraSelection> extraSelections;
244244
QTextCharFormat format;
245245

246246
format.setBackground(Qt::yellow);
247247

248-
for (QString keyword : keywords)
248+
for (const QString &keyword : keywords)
249249
{
250250
if (keyword.length() == 0)
251251
continue;

QtSLiM/QtSLiMGraphView.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,16 @@ void QtSLiMGraphView::addedToWindow(void)
118118

119119
QtSLiMGraphView::~QtSLiMGraphView()
120120
{
121-
cleanup();
121+
// It would be nice if we could call these methods automatically for subclasses, but we cannot. By the time
122+
// this destructor has been called, the subclass has already been destructed, and a virtual function call
123+
// here calls the QtSLiMGraphView implementation, not the subclass implementation. Subclasses that use these
124+
// methods must call them themselves in their destructors.
125+
QtSLiMGraphView::invalidateDrawingCache();
126+
QtSLiMGraphView::invalidateCachedData();
122127

123128
controller_ = nullptr;
124129
}
125130

126-
void QtSLiMGraphView::cleanup()
127-
{
128-
invalidateDrawingCache();
129-
invalidateCachedData();
130-
}
131-
132131
void QtSLiMGraphView::setFocalDisplaySpecies(Species *species)
133132
{
134133
if (species)
@@ -875,11 +874,13 @@ void QtSLiMGraphView::paintEvent(QPaintEvent * /* p_paintEvent */)
875874
void QtSLiMGraphView::invalidateCachedData()
876875
{
877876
// GraphView has no cached data, but it supports the idea of it
877+
// If anything ever gets added here, calls to super will need to be added in subclasses
878878
}
879879

880880
void QtSLiMGraphView::invalidateDrawingCache(void)
881881
{
882-
// GraphView has no drawing cache, but it supports the idea of one
882+
// GraphView has no drawing cache, but it supports the idea of one
883+
// If anything ever gets added here, calls to super will need to be added in subclasses
883884
}
884885

885886
void QtSLiMGraphView::graphWindowResized(void)

QtSLiM/QtSLiMGraphView.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,13 @@ class QtSLiMGraphView : public QWidget
6565

6666
public slots:
6767
virtual void addedToWindow(void);
68-
virtual void invalidateCachedData(void);
69-
virtual void invalidateDrawingCache(void);
68+
virtual void invalidateCachedData(void); // subclasses must call this themselves in their destructor - super cannot do it!
69+
virtual void invalidateDrawingCache(void); // subclasses must call this themselves in their destructor - super cannot do it!
7070
virtual void graphWindowResized(void);
71-
virtual void controllerRecycled(void);
71+
virtual void controllerRecycled(void); // subclasses must call super: QtSLiMGraphView::controllerRecycled()
7272
virtual void controllerChromosomeSelectionChanged(void);
7373
virtual void controllerTickFinished(void);
74-
virtual void updateAfterTick(void);
74+
virtual void updateAfterTick(void); // subclasses must call super: QtSLiMGraphView::updateAfterTick()
7575
void actionButtonRunMenu(QtSLiMPushButton *actionButton);
7676

7777
protected:
@@ -106,7 +106,6 @@ public slots:
106106
virtual void appendStringForData(QString &string) = 0;
107107

108108
// Optional subclass overrides
109-
virtual void cleanup();
110109
virtual void willDraw(QPainter &painter, QRect interiorRect);
111110
virtual bool providesStringForData(void);
112111
virtual QtSLiMLegendSpec legendKey(void);

QtSLiM/QtSLiMGraphView_1DSampleSFS.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ void QtSLiMGraphView_1DSampleSFS::addedToWindow(void)
8888

8989
QtSLiMGraphView_1DSampleSFS::~QtSLiMGraphView_1DSampleSFS()
9090
{
91+
// We are responsible for our own destruction
92+
QtSLiMGraphView_1DSampleSFS::invalidateCachedData();
9193
}
9294

9395
void QtSLiMGraphView_1DSampleSFS::subpopulation1PopupChanged(int /* index */)

0 commit comments

Comments
 (0)