Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix clazy warnings #1000

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/remotemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ QVariant RemoteModel::requestCreationDeclarationLocation(const QModelIndex &inde

QEventLoop loop;

auto conn = connect(this, &RemoteModel::declarationCreationLocationsReceived, this, [&creationLoc, &declarationLoc, &loop](const QVariant &d, const QVariant &c) {
auto conn = connect(this, &RemoteModel::declarationCreationLocationsReceived, this, [&creationLoc, &declarationLoc, &loop](const QVariant &d, const QVariant &c) { // clazy:exclude=lambda-in-connect
if (d.isValid())
declarationLoc = d;
if (c.isValid())
Expand Down
8 changes: 4 additions & 4 deletions core/tools/messagehandler/messagehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static MessageHandlerCallback (*const installMessageHandler)(MessageHandlerCallb
static MessageModel *s_model = nullptr;
static MessageHandlerCallback s_handler = nullptr;
static bool s_handlerDisabled = false;
static QRecursiveMutex s_mutex;
Q_GLOBAL_STATIC(QRecursiveMutex, s_mutex)

static void handleMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
Expand Down Expand Up @@ -86,7 +86,7 @@ static void handleMessage(QtMsgType type, const QMessageLogContext &context, con
// reset msg handler so the app still works as usual
// but make sure we don't let other threads bypass our
// handler during that time
QMutexLocker lock(&s_mutex);
QMutexLocker lock(s_mutex());
s_handlerDisabled = true;
if (s_handler) { // try a direct call to the previous handler first, that avoids triggering the recursion detection in Qt5
s_handler(type, context, msg);
Expand Down Expand Up @@ -139,7 +139,7 @@ MessageHandler::MessageHandler(Probe *probe, QObject *parent)

MessageHandler::~MessageHandler()
{
QMutexLocker lock(&s_mutex);
QMutexLocker lock(s_mutex());

s_model = nullptr;
MessageHandlerCallback oldHandler = installMessageHandler(s_handler);
Expand All @@ -157,7 +157,7 @@ void MessageHandler::generateFullTrace()

void MessageHandler::ensureHandlerInstalled()
{
QMutexLocker lock(&s_mutex);
QMutexLocker lock(s_mutex());

if (s_handlerDisabled)
return;
Expand Down
6 changes: 3 additions & 3 deletions launcher/ui/processlist_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include <algorithm>

static GammaRay::ProbeABIDetector s_abiDetector;
Q_GLOBAL_STATIC(GammaRay::ProbeABIDetector, s_abiDetector)

static bool isUnixProcessId(const QString &procname)
{
Expand Down Expand Up @@ -108,7 +108,7 @@ static ProcDataList unixProcessListPS(const ProcDataList &previous)
if (it != previous.constEnd())
procData.abi = it->abi;
else
procData.abi = s_abiDetector.abiForProcess(procData.ppid.toLongLong());
procData.abi = s_abiDetector->abiForProcess(procData.ppid.toLongLong());
rc.push_back(procData);
}
}
Expand Down Expand Up @@ -164,7 +164,7 @@ struct ProcIdToProcData
if (it != previous.constEnd())
proc.abi = it->abi;
else
proc.abi = s_abiDetector.abiForProcess(proc.ppid.toLongLong());
proc.abi = s_abiDetector->abiForProcess(proc.ppid.toLongLong());

return proc;
}
Expand Down
10 changes: 5 additions & 5 deletions plugins/quickinspector/quickscreengrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ class QQuickItemPropertyCache
}
};

// We need random colors, but we also want the item
// to keep its random color during scene changes to avoid
// flickering due to color change.
static QHash<QQuickItem *, QColor> s_itemsColor;

static QColor colorForItem(QQuickItem *item)
{
// We need random colors, but we also want the item
// to keep its random color during scene changes to avoid
// flickering due to color change.
static QHash<QQuickItem *, QColor> s_itemsColor;

QColor color = s_itemsColor.value(item, QColor());

if (!color.isValid()) {
Expand Down
47 changes: 27 additions & 20 deletions plugins/sysinfo/sysinfomodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,42 @@

#include <QLibraryInfo>
#include <QSysInfo>
#include <array>

using namespace GammaRay;

struct sysinfo_t
{
QString (*func)();
const char *name;
const QString name;
};

#define S(x) \
{ \
QSysInfo::x, #x \
#define S(x) \
sysinfo_t \
{ \
\
QSysInfo::x, QString::fromLatin1(#x) \
}
static const sysinfo_t sysInfoTable[] = {

static const std::array<sysinfo_t, 10> &sysInfoTable()
{
static const std::array<sysinfo_t, 10> t = {
#if !defined(Q_CC_MSVC) || _MSC_VER > 1600 // krazy:exclude=cpp to deal with older MS compilers
{ []() { return QString::fromLatin1(QLibraryInfo::build()); }, "build" },
sysinfo_t { []() { return QString::fromLatin1(QLibraryInfo::build()); }, "build" },
#endif
S(buildAbi),
S(buildCpuArchitecture),
S(currentCpuArchitecture),
S(kernelType),
S(kernelVersion),
S(machineHostName),
S(prettyProductName),
S(productType),
S(productVersion)
};
S(buildAbi),
S(buildCpuArchitecture),
S(currentCpuArchitecture),
S(kernelType),
S(kernelVersion),
S(machineHostName),
S(prettyProductName),
S(productType),
S(productVersion)
};
return t;
}
#undef S
static const auto sysInfoTableSize = sizeof(sysInfoTable) / sizeof(sysinfo_t);

SysInfoModel::SysInfoModel(QObject *parent)
: QAbstractTableModel(parent)
Expand All @@ -60,7 +67,7 @@ int SysInfoModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
return sysInfoTableSize;
return ( int )sysInfoTable().size();
}

QVariant SysInfoModel::data(const QModelIndex &index, int role) const
Expand All @@ -71,9 +78,9 @@ QVariant SysInfoModel::data(const QModelIndex &index, int role) const
if (role == Qt::DisplayRole) {
switch (index.column()) {
case 0:
return sysInfoTable[index.row()].name;
return sysInfoTable()[index.row()].name;
case 1:
return sysInfoTable[index.row()].func();
return sysInfoTable()[index.row()].func();
}
}

Expand Down
22 changes: 12 additions & 10 deletions plugins/timertop/timermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
using namespace GammaRay;
using namespace std;

static QPointer<TimerModel> s_timerModel;
Q_GLOBAL_STATIC(QPointer<TimerModel>, s_timerModel)
static const char s_qmlTimerClassName[] = "QQmlTimer";
static const int s_maxTimeoutEvents = 1000;
static const int s_maxTimeSpan = 10000;
Expand Down Expand Up @@ -300,21 +300,22 @@ bool TimerModel::eventNotifyCallback(void *data[])
}

{
QMutexLocker locker(&s_timerModel->m_mutex);
auto timerModel = s_timerModel->data();
QMutexLocker locker(&timerModel->m_mutex);
const TimerId id(timerEvent->timerId(), receiver);
auto it = s_timerModel->m_gatheredTimersData.find(id);
auto it = timerModel->m_gatheredTimersData.find(id);

if (it == s_timerModel->m_gatheredTimersData.end()) {
it = s_timerModel->m_gatheredTimersData.insert(id, TimerIdData());
if (it == timerModel->m_gatheredTimersData.end()) {
it = timerModel->m_gatheredTimersData.insert(id, TimerIdData());
}

const TimeoutEvent timeoutEvent(QTime::currentTime(), -1);
// safe, we are called from the receiver thread
it.value().update(id, receiver);
it.value().addEvent(timeoutEvent);

s_timerModel->checkDispatcherStatus(receiver);
s_timerModel->m_triggerPushChangesMethod.invoke(s_timerModel, Qt::QueuedConnection);
timerModel->checkDispatcherStatus(receiver);
timerModel->m_triggerPushChangesMethod.invoke(timerModel, Qt::QueuedConnection);
}
}

Expand All @@ -337,11 +338,12 @@ bool TimerModel::isInitialized()

TimerModel *TimerModel::instance()
{
if (!s_timerModel)
s_timerModel = new TimerModel;
if (s_timerModel->isNull()) {
*s_timerModel = new TimerModel;
}

Q_ASSERT(s_timerModel);
return s_timerModel;
return s_timerModel->data();
}

void TimerModel::preSignalActivate(QObject *caller, int methodIndex)
Expand Down
2 changes: 1 addition & 1 deletion probe/entry_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class HitMeBabyOneMoreTime
}
};

static HitMeBabyOneMoreTime britney;
static HitMeBabyOneMoreTime britney; // clazy:exclude=non-pod-global-static
8 changes: 5 additions & 3 deletions ui/uistatemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,11 @@ void UIStateManager::headerSectionCountChanged()
// Delay the call to restoreHeaderState to avoid multiple changes in flight at the QAIM level
// E.g. we might be here because of columnsInserted() (which just finished, but not all receivers were told yet)
// and restoring will sort() the model, which will emit layoutChanged(). Separate the two so QAbstractItemModelTester doesn't abort.
// clang-format off
QMetaObject::invokeMethod(this, "restoreHeaderState", Qt::QueuedConnection, Q_ARG(QHeaderView *, headerView));
// clang-format on
QMetaObject::invokeMethod(
this, [this, headerView] {
restoreHeaderState(headerView);
},
Qt::QueuedConnection);
}

void UIStateManager::widgetResized(QWidget *widget)
Expand Down