TaskTree: Qt-ify the code

Make it more conforming to the current Qt style:
1. Remove trailing semicolons after inlined functions.
2. Use Q_SIGNALS / Q_EMIT in headers.
3. Use QString::fromLatin1() where needed (as otherwise the string
   c'tor is deprecated).
4. Use module names in Qt includes.
5. Simplify local asserts in barrier.cpp.

Change-Id: I13cadee6ff61a24d792efcf3b613f7cf5563076b
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-06-04 17:16:05 +02:00
parent dfef293aa4
commit 6621c68ca9
11 changed files with 51 additions and 54 deletions

View File

@@ -6,23 +6,20 @@
namespace Tasking {
// That's cut down qtcassert.{c,h} to avoid the dependency.
#define QTC_STRINGIFY_HELPER(x) #x
#define QTC_STRINGIFY(x) QTC_STRINGIFY_HELPER(x)
#define QTC_STRING(cond) qDebug("SOFT ASSERT: \"%s\" in %s: %s", cond, __FILE__, QTC_STRINGIFY(__LINE__))
#define QTC_ASSERT(cond, action) if (Q_LIKELY(cond)) {} else { QTC_STRING(#cond); action; } do {} while (0)
#define QTC_CHECK(cond) if (cond) {} else { QTC_STRING(#cond); } do {} while (0)
#define QT_STRING(cond) qDebug("SOFT ASSERT: \"%s\" in %s: %s", cond, __FILE__, QT_STRINGIFY(__LINE__))
#define QT_ASSERT(cond, action) if (Q_LIKELY(cond)) {} else { QT_STRING(#cond); action; } do {} while (0)
void Barrier::setLimit(int value)
{
QTC_ASSERT(!isRunning(), return);
QTC_ASSERT(value > 0, return);
QT_ASSERT(!isRunning(), return);
QT_ASSERT(value > 0, return);
m_limit = value;
}
void Barrier::start()
{
QTC_ASSERT(!isRunning(), return);
QT_ASSERT(!isRunning(), return);
m_current = 0;
m_result = {};
}
@@ -30,7 +27,7 @@ void Barrier::start()
void Barrier::advance()
{
// Calling advance on finished is OK
QTC_ASSERT(isRunning() || m_result, return);
QT_ASSERT(isRunning() || m_result, return);
if (!isRunning()) // no-op
return;
++m_current;
@@ -41,7 +38,7 @@ void Barrier::advance()
void Barrier::stopWithResult(DoneResult result)
{
// Calling stopWithResult on finished is OK when the same success is passed
QTC_ASSERT(isRunning() || (m_result && *m_result == result), return);
QT_ASSERT(isRunning() || (m_result && *m_result == result), return);
if (!isRunning()) // no-op
return;
m_current = -1;

View File

@@ -25,7 +25,7 @@ public:
int current() const { return m_current; }
std::optional<DoneResult> result() const { return m_result; }
signals:
Q_SIGNALS:
void done(DoneResult success);
private:

View File

@@ -5,7 +5,7 @@
#include "tasktree.h"
#include <QtConcurrent>
#include <QtConcurrent/QtConcurrent>
namespace Tasking {
@@ -76,7 +76,7 @@ public:
}
}
void start() {
void start() final {
if (!this->task()->m_startHandler) {
emit this->done(DoneResult::Error); // TODO: Add runtime assert
return;

View File

@@ -3,7 +3,7 @@
#include "networkquery.h"
#include <QNetworkAccessManager>
#include <QtNetwork/QNetworkAccessManager>
namespace Tasking {

View File

@@ -7,8 +7,8 @@
#include "tasktree.h"
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkRequest>
#include <memory>
@@ -37,7 +37,7 @@ public:
QNetworkReply *reply() const { return m_reply.get(); }
void start();
signals:
Q_SIGNALS:
void started();
void done(DoneResult result);

View File

@@ -3,12 +3,12 @@
#include "qprocesstask.h"
#include <QCoreApplication>
#include <QDebug>
#include <QMutex>
#include <QThread>
#include <QTimer>
#include <QWaitCondition>
#include <QtCore/QCoreApplication>
#include <QtCore/QDebug>
#include <QtCore/QMutex>
#include <QtCore/QThread>
#include <QtCore/QTimer>
#include <QtCore/QWaitCondition>
namespace Tasking {
@@ -60,7 +60,7 @@ public:
terminate();
}
signals:
Q_SIGNALS:
void finished();
private:

View File

@@ -7,7 +7,7 @@
#include "tasktree.h"
#include <QProcess>
#include <QtCore/QProcess>
namespace Tasking {
@@ -45,17 +45,17 @@ public:
class TASKING_EXPORT QProcessAdapter : public TaskAdapter<QProcess, QProcessDeleter>
{
private:
void start() override {
void start() final {
connect(task(), &QProcess::finished, this, [this] {
const bool success = task()->exitStatus() == QProcess::NormalExit
&& task()->error() == QProcess::UnknownError
&& task()->exitCode() == 0;
emit done(toDoneResult(success));
Q_EMIT done(toDoneResult(success));
});
connect(task(), &QProcess::errorOccurred, this, [this](QProcess::ProcessError error) {
if (error != QProcess::FailedToStart)
return;
emit done(DoneResult::Error);
Q_EMIT done(DoneResult::Error);
});
task()->start();
}

View File

@@ -3,7 +3,7 @@
#pragma once
#include <qglobal.h>
#include <QtCore/qglobal.h>
#if defined(TASKING_LIBRARY)
# define TASKING_EXPORT Q_DECL_EXPORT

View File

@@ -5,17 +5,17 @@
#include "barrier.h"
#include <QDebug>
#include <QEventLoop>
#include <QFutureWatcher>
#include <QHash>
#include <QMetaEnum>
#include <QMutex>
#include <QPromise>
#include <QPointer>
#include <QSet>
#include <QTime>
#include <QTimer>
#include <QtCore/QDebug>
#include <QtCore/QEventLoop>
#include <QtCore/QFutureWatcher>
#include <QtCore/QHash>
#include <QtCore/QMetaEnum>
#include <QtCore/QMutex>
#include <QtCore/QPointer>
#include <QtCore/QPromise>
#include <QtCore/QSet>
#include <QtCore/QTime>
#include <QtCore/QTimer>
using namespace std::chrono;
@@ -1461,7 +1461,7 @@ static QString currentTime() { return QTime::currentTime().toString(Qt::ISODateW
ExecutableItem ExecutableItem::withLog(const QString &logName) const
{
const auto header = [logName] {
return QString("TASK TREE LOG [%1] \"%2\"").arg(currentTime(), logName);
return QString::fromLatin1("TASK TREE LOG [%1] \"%2\"").arg(currentTime(), logName);
};
struct LogStorage
{
@@ -1482,8 +1482,8 @@ ExecutableItem ExecutableItem::withLog(const QString &logName) const
const int asyncCountDiff = activeTaskTree()->asyncCount() - storage->asyncCount;
QT_CHECK(asyncCountDiff >= 0);
const QMetaEnum doneWithEnum = QMetaEnum::fromType<DoneWith>();
const QString syncType = asyncCountDiff ? QString("asynchronously")
: QString("synchronously");
const QString syncType = asyncCountDiff ? QString::fromLatin1("asynchronously")
: QString::fromLatin1("synchronously");
qDebug().noquote().nospace() << header() << " finished " << syncType << " with "
<< doneWithEnum.valueToKey(int(result)) << " within " << elapsed.count() << "ms.";
})

View File

@@ -5,8 +5,8 @@
#include "tasking_global.h"
#include <QObject>
#include <QList>
#include <QtCore/QList>
#include <QtCore/QObject>
#include <memory>
@@ -84,7 +84,7 @@ class TASKING_EXPORT TaskInterface : public QObject
{
Q_OBJECT
signals:
Q_SIGNALS:
void done(DoneResult result);
private:
@@ -345,7 +345,7 @@ private:
std::invoke(handler);
return SetupResult::Continue;
};
};
}
template <typename Handler>
static GroupDoneHandler wrapGroupDone(Handler &&handler)
{
@@ -368,7 +368,7 @@ private:
std::invoke(handler);
return result == DoneWith::Success ? DoneResult::Success : DoneResult::Error;
};
};
}
};
template <typename Handler>
@@ -433,7 +433,7 @@ private:
std::invoke(handler);
return SetupResult::StopWithSuccess;
};
};
}
};
template <typename Task, typename Deleter = std::default_delete<Task>>
@@ -490,7 +490,7 @@ private:
std::invoke(handler, *adapter.task());
return SetupResult::Continue;
};
};
}
template <typename Handler>
static InterfaceDoneHandler wrapDone(Handler &&handler) {
@@ -529,7 +529,7 @@ private:
std::invoke(handler);
return result == DoneWith::Success ? DoneResult::Success : DoneResult::Error;
};
};
}
};
class TASKING_EXPORT TaskTree final : public QObject
@@ -579,7 +579,7 @@ public:
wrapHandler<const StorageStruct>(std::forward<Handler>(handler)));
}
signals:
Q_SIGNALS:
void started();
void done(DoneWith result);
void asyncCountChanged(int count);

View File

@@ -6,7 +6,7 @@
#include "tasking_global.h"
#include "tasktree.h"
#include <QObject>
#include <QtCore/QObject>
namespace Tasking {
@@ -33,7 +33,7 @@ public:
// No done() signal is emitted.
void reset();
signals:
Q_SIGNALS:
void aboutToStart(TaskTree *taskTree);
void done(DoneWith result);