Skip to content

Commit 1552aca

Browse files
committed
build: fix new clang-tidy lints
1 parent 0a36e3e commit 1552aca

File tree

12 files changed

+84
-378
lines changed

12 files changed

+84
-378
lines changed

.clang-tidy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Checks: >
2020
-cppcoreguidelines-avoid-do-while,
2121
-cppcoreguidelines-pro-type-reinterpret-cast,
2222
-cppcoreguidelines-pro-type-vararg,
23+
-cppcoreguidelines-use-enum-class,
2324
google-global-names-in-headers,
2425
google-readability-casting,
2526
google-runtime-int,
@@ -63,6 +64,8 @@ CheckOptions:
6364
readability-identifier-naming.ParameterCase: camelBack
6465
readability-identifier-naming.VariableCase: camelBack
6566

67+
misc-const-correctness.WarnPointersAsPointers: false
68+
6669
# does not appear to work
6770
readability-operators-representation.BinaryOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^='
6871
readability-operators-representation.OverloadedOperators: '&&;&=;&;|;~;!;!=;||;|=;^;^='

src/core/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ qt_add_library(quickshell-core STATIC
2424
elapsedtimer.cpp
2525
desktopentry.cpp
2626
desktopentrymonitor.cpp
27-
objectrepeater.cpp
2827
platformmenu.cpp
2928
qsmenu.cpp
3029
retainable.cpp

src/core/logging.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,11 +746,11 @@ bool EncodedLogReader::readVarInt(quint32* slot) {
746746
if (!this->reader.skip(1)) return false;
747747
*slot = qFromLittleEndian(n);
748748
} else if ((bytes[1] != 0xff || bytes[2] != 0xff) && readLength >= 3) {
749-
auto n = *reinterpret_cast<quint16*>(bytes.data() + 1);
749+
auto n = *reinterpret_cast<quint16*>(bytes.data() + 1); // NOLINT
750750
if (!this->reader.skip(3)) return false;
751751
*slot = qFromLittleEndian(n);
752752
} else if (readLength == 7) {
753-
auto n = *reinterpret_cast<quint32*>(bytes.data() + 3);
753+
auto n = *reinterpret_cast<quint32*>(bytes.data() + 3); // NOLINT
754754
if (!this->reader.skip(7)) return false;
755755
*slot = qFromLittleEndian(n);
756756
} else return false;

src/core/model.cpp

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,13 @@
11
#include "model.hpp"
22

3-
#include <qabstractitemmodel.h>
43
#include <qhash.h>
4+
#include <qbytearray.h>
55
#include <qnamespace.h>
6-
#include <qobject.h>
7-
#include <qqmllist.h>
8-
#include <qtmetamacros.h>
9-
#include <qtypes.h>
10-
#include <qvariant.h>
11-
12-
qint32 UntypedObjectModel::rowCount(const QModelIndex& parent) const {
13-
if (parent != QModelIndex()) return 0;
14-
return static_cast<qint32>(this->valuesList.length());
15-
}
16-
17-
QVariant UntypedObjectModel::data(const QModelIndex& index, qint32 role) const {
18-
if (role != Qt::UserRole) return QVariant();
19-
return QVariant::fromValue(this->valuesList.at(index.row()));
20-
}
216

227
QHash<int, QByteArray> UntypedObjectModel::roleNames() const {
238
return {{Qt::UserRole, "modelData"}};
249
}
2510

26-
void UntypedObjectModel::insertObject(QObject* object, qsizetype index) {
27-
auto iindex = index == -1 ? this->valuesList.length() : index;
28-
emit this->objectInsertedPre(object, iindex);
29-
30-
auto intIndex = static_cast<qint32>(iindex);
31-
this->beginInsertRows(QModelIndex(), intIndex, intIndex);
32-
this->valuesList.insert(iindex, object);
33-
this->endInsertRows();
34-
35-
emit this->valuesChanged();
36-
emit this->objectInsertedPost(object, iindex);
37-
}
38-
39-
void UntypedObjectModel::removeAt(qsizetype index) {
40-
auto* object = this->valuesList.at(index);
41-
emit this->objectRemovedPre(object, index);
42-
43-
auto intIndex = static_cast<qint32>(index);
44-
this->beginRemoveRows(QModelIndex(), intIndex, intIndex);
45-
this->valuesList.removeAt(index);
46-
this->endRemoveRows();
47-
48-
emit this->valuesChanged();
49-
emit this->objectRemovedPost(object, index);
50-
}
51-
52-
bool UntypedObjectModel::removeObject(const QObject* object) {
53-
auto index = this->valuesList.indexOf(object);
54-
if (index == -1) return false;
55-
56-
this->removeAt(index);
57-
return true;
58-
}
59-
60-
void UntypedObjectModel::diffUpdate(const QVector<QObject*>& newValues) {
61-
for (qsizetype i = 0; i < this->valuesList.length();) {
62-
if (newValues.contains(this->valuesList.at(i))) i++;
63-
else this->removeAt(i);
64-
}
65-
66-
qsizetype oi = 0;
67-
for (auto* object: newValues) {
68-
if (this->valuesList.length() == oi || this->valuesList.at(oi) != object) {
69-
this->insertObject(object, oi);
70-
}
71-
72-
oi++;
73-
}
74-
}
75-
76-
qsizetype UntypedObjectModel::indexOf(QObject* object) { return this->valuesList.indexOf(object); }
77-
7811
UntypedObjectModel* UntypedObjectModel::emptyInstance() {
79-
static auto* instance = new UntypedObjectModel(nullptr); // NOLINT
80-
return instance;
12+
return ObjectModel<void>::emptyInstance();
8113
}

src/core/model.hpp

Lines changed: 73 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <functional>
44

5-
#include <bit>
5+
#include <QtCore/qtmetamacros.h>
66
#include <qabstractitemmodel.h>
77
#include <qcontainerfwd.h>
88
#include <qobject.h>
@@ -49,14 +49,11 @@ class UntypedObjectModel: public QAbstractListModel {
4949
public:
5050
explicit UntypedObjectModel(QObject* parent): QAbstractListModel(parent) {}
5151

52-
[[nodiscard]] qint32 rowCount(const QModelIndex& parent) const override;
53-
[[nodiscard]] QVariant data(const QModelIndex& index, qint32 role) const override;
5452
[[nodiscard]] QHash<int, QByteArray> roleNames() const override;
5553

56-
[[nodiscard]] QList<QObject*> values() const { return this->valuesList; }
57-
void removeAt(qsizetype index);
54+
[[nodiscard]] virtual QList<QObject*> values() = 0;
5855

59-
Q_INVOKABLE qsizetype indexOf(QObject* object);
56+
Q_INVOKABLE virtual qsizetype indexOf(QObject* object) const = 0;
6057

6158
static UntypedObjectModel* emptyInstance();
6259

@@ -71,15 +68,6 @@ class UntypedObjectModel: public QAbstractListModel {
7168
/// Sent immediately after an object is removed from the list.
7269
void objectRemovedPost(QObject* object, qsizetype index);
7370

74-
protected:
75-
void insertObject(QObject* object, qsizetype index = -1);
76-
bool removeObject(const QObject* object);
77-
78-
// Assumes only one instance of a specific value
79-
void diffUpdate(const QVector<QObject*>& newValues);
80-
81-
QVector<QObject*> valuesList;
82-
8371
private:
8472
static qsizetype valuesCount(QQmlListProperty<QObject>* property);
8573
static QObject* valueAt(QQmlListProperty<QObject>* property, qsizetype index);
@@ -90,14 +78,20 @@ class ObjectModel: public UntypedObjectModel {
9078
public:
9179
explicit ObjectModel(QObject* parent): UntypedObjectModel(parent) {}
9280

93-
[[nodiscard]] QVector<T*>& valueList() { return *std::bit_cast<QVector<T*>*>(&this->valuesList); }
94-
95-
[[nodiscard]] const QVector<T*>& valueList() const {
96-
return *std::bit_cast<const QVector<T*>*>(&this->valuesList);
97-
}
81+
[[nodiscard]] const QList<T*>& valueList() const { return this->mValuesList; }
82+
[[nodiscard]] QList<T*>& valueList() { return this->mValuesList; }
9883

9984
void insertObject(T* object, qsizetype index = -1) {
100-
this->UntypedObjectModel::insertObject(object, index);
85+
auto iindex = index == -1 ? this->mValuesList.length() : index;
86+
emit this->objectInsertedPre(object, iindex);
87+
88+
auto intIndex = static_cast<qint32>(iindex);
89+
this->beginInsertRows(QModelIndex(), intIndex, intIndex);
90+
this->mValuesList.insert(iindex, object);
91+
this->endInsertRows();
92+
93+
emit this->valuesChanged();
94+
emit this->objectInsertedPost(object, iindex);
10195
}
10296

10397
void insertObjectSorted(T* object, const std::function<bool(T*, T*)>& compare) {
@@ -110,17 +104,71 @@ class ObjectModel: public UntypedObjectModel {
110104
}
111105

112106
auto idx = iter - list.begin();
113-
this->UntypedObjectModel::insertObject(object, idx);
107+
this->insertObject(object, idx);
108+
}
109+
110+
bool removeObject(const T* object) {
111+
auto index = this->mValuesList.indexOf(object);
112+
if (index == -1) return false;
113+
114+
this->removeAt(index);
115+
return true;
114116
}
115117

116-
void removeObject(const T* object) { this->UntypedObjectModel::removeObject(object); }
118+
void removeAt(qsizetype index) {
119+
auto* object = this->mValuesList.at(index);
120+
emit this->objectRemovedPre(object, index);
121+
122+
auto intIndex = static_cast<qint32>(index);
123+
this->beginRemoveRows(QModelIndex(), intIndex, intIndex);
124+
this->mValuesList.removeAt(index);
125+
this->endRemoveRows();
126+
127+
emit this->valuesChanged();
128+
emit this->objectRemovedPost(object, index);
129+
}
117130

118131
// Assumes only one instance of a specific value
119-
void diffUpdate(const QVector<T*>& newValues) {
120-
this->UntypedObjectModel::diffUpdate(*std::bit_cast<const QVector<QObject*>*>(&newValues));
132+
void diffUpdate(const QList<T*>& newValues) {
133+
for (qsizetype i = 0; i < this->mValuesList.length();) {
134+
if (newValues.contains(this->mValuesList.at(i))) i++;
135+
else this->removeAt(i);
136+
}
137+
138+
qsizetype oi = 0;
139+
for (auto* object: newValues) {
140+
if (this->mValuesList.length() == oi || this->mValuesList.at(oi) != object) {
141+
this->insertObject(object, oi);
142+
}
143+
144+
oi++;
145+
}
121146
}
122147

123148
static ObjectModel<T>* emptyInstance() {
124149
return static_cast<ObjectModel<T>*>(UntypedObjectModel::emptyInstance());
125150
}
151+
152+
[[nodiscard]] qint32 rowCount(const QModelIndex& parent) const override {
153+
if (parent != QModelIndex()) return 0;
154+
return static_cast<qint32>(this->mValuesList.length());
155+
}
156+
157+
[[nodiscard]] QVariant data(const QModelIndex& index, qint32 role) const override {
158+
if (role != Qt::UserRole) return QVariant();
159+
// Values must be QObject derived, but we can't assert that here without breaking forward decls,
160+
// so no static_cast.
161+
return QVariant::fromValue(reinterpret_cast<QObject*>(this->mValuesList.at(index.row())));
162+
}
163+
164+
qsizetype indexOf(QObject* object) const override {
165+
return this->mValuesList.indexOf(reinterpret_cast<T*>(object));
166+
}
167+
168+
[[nodiscard]] QList<QObject*> values() override {
169+
return *reinterpret_cast<QList<QObject*>*>(&this->mValuesList);
170+
}
171+
172+
private:
173+
QList<T*> mValuesList;
126174
};

src/core/module.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ headers = [
2121
"model.hpp",
2222
"elapsedtimer.hpp",
2323
"desktopentry.hpp",
24-
"objectrepeater.hpp",
2524
"qsmenu.hpp",
2625
"retainable.hpp",
2726
"popupanchor.hpp",

0 commit comments

Comments
 (0)