CtfVisualizer: Do some cleanup

Remove unused headers.
Use using namespace and drop unneeded namespace scopes.
Replace QVector with QList.
Return default constructed objects in default return statements.
Avoid empty arg brackets in some lambdas.
Use default member initializers.

Change-Id: I11e62a291be3fa5bde4156e7a316765ee697b852
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Jarek Kobus
2023-09-27 19:36:19 +02:00
parent 5c52bdd0e9
commit bc5a2dbf14
15 changed files with 71 additions and 125 deletions

View File

@@ -2,21 +2,18 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "ctfstatisticsmodel.h"
#include "ctfvisualizerconstants.h"
#include "ctfvisualizertr.h"
#include "json/json.hpp"
#include <tracing/timelineformattime.h>
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
using json = nlohmann::json;
using namespace Constants;
CtfStatisticsModel::CtfStatisticsModel(QObject *parent)
: QAbstractTableModel(parent)
{
}
void CtfStatisticsModel::beginLoading()
@@ -59,7 +56,7 @@ int CtfStatisticsModel::columnCount(const QModelIndex &parent) const
QVariant CtfStatisticsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
return {};
auto it = m_data.cbegin();
std::advance(it, index.row());
@@ -79,7 +76,7 @@ QVariant CtfStatisticsModel::data(const QModelIndex &index, int role) const
return Qt::AlignRight;
default:
Q_UNREACHABLE();
return QVariant();
return {};
}
case SortRole:
switch (index.column()) {
@@ -106,7 +103,7 @@ QVariant CtfStatisticsModel::data(const QModelIndex &index, int role) const
case Column::MaxDuration:
return m_data.value(title).maxDuration;
default:
return QVariant();
return {};
}
case Qt::DisplayRole:
switch (index.column()) {
@@ -158,7 +155,7 @@ QVariant CtfStatisticsModel::data(const QModelIndex &index, int role) const
}
}
return QVariant();
return {};
}
QVariant CtfStatisticsModel::headerData(int section, Qt::Orientation orientation, int role) const
@@ -186,5 +183,4 @@ QVariant CtfStatisticsModel::headerData(int section, Qt::Orientation orientation
}
}
} // Internal
} // CtfVisualizer
} // CtfVisualizer::Internal

View File

@@ -3,16 +3,10 @@
#pragma once
#include "json/json.hpp"
#include <QHash>
#include <QStack>
#include <QVector>
#include <QPointer>
#include <QAbstractTableModel>
#include <QHash>
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
class CtfStatisticsModel : public QAbstractTableModel
{
@@ -61,5 +55,4 @@ private:
};
} // Internal
} // CtfVisualizer
} // CtfVisualizer::Internal

View File

@@ -7,8 +7,7 @@
#include <QHeaderView>
#include <QSortFilterProxyModel>
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
CtfStatisticsView::CtfStatisticsView(CtfStatisticsModel *model, QWidget *parent)
: Utils::TreeView(parent)
@@ -31,7 +30,7 @@ CtfStatisticsView::CtfStatisticsView(CtfStatisticsModel *model, QWidget *parent)
setSortingEnabled(true);
connect(selectionModel(), &QItemSelectionModel::currentChanged, this,
[this] (const QModelIndex &current, const QModelIndex &previous)
[this](const QModelIndex &current, const QModelIndex &previous)
{
Q_UNUSED(previous);
QModelIndex index = this->model()->index(current.row(), CtfStatisticsModel::Title);
@@ -56,5 +55,4 @@ void CtfStatisticsView::selectByTitle(const QString &title)
}
}
} // Internal
} // CtfVisualizer
} // CtfVisualizer::Internal

View File

@@ -3,12 +3,9 @@
#pragma once
#include "ctfvisualizerconstants.h"
#include <utils/itemviews.h>
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
class CtfStatisticsModel;
@@ -25,5 +22,4 @@ signals:
void eventTypeSelected(const QString &title);
};
} // Internal
} // CtfVisualizer
} // CtfVisualizer::Internal

View File

@@ -8,16 +8,12 @@
#include "ctfvisualizertr.h"
#include <tracing/timelineformattime.h>
#include <tracing/timelinemodelaggregator.h>
#include <utils/qtcassert.h>
#include <QDebug>
#include <utils/qtcassert.h>
#include <string>
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
using json = nlohmann::json;
using namespace Constants;
@@ -46,7 +42,7 @@ QVariantList CtfTimelineModel::labels() const
{
QVariantList result;
QVector<std::string> sortedCounterNames = m_counterNames;
QList<std::string> sortedCounterNames = m_counterNames;
std::sort(sortedCounterNames.begin(), sortedCounterNames.end());
for (int i = 0; i < sortedCounterNames.size(); ++i) {
QVariantMap element;
@@ -190,7 +186,7 @@ void CtfTimelineModel::finalize(double traceBegin, double traceEnd, const QStrin
m_rows = computeRows(&m_maxStackSize);
++m_maxStackSize; // index -> count
QVector<std::string> sortedCounterNames = m_counterNames;
QList<std::string> sortedCounterNames = m_counterNames;
std::sort(sortedCounterNames.begin(), sortedCounterNames.end());
m_counterIndexToRow.resize(m_counterNames.size());
for (int i = 0; i < m_counterIndexToRow.size(); ++i) {
@@ -376,7 +372,5 @@ const QString &CtfTimelineModel::reuse(const QString &value)
return *it;
}
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal

View File

@@ -6,17 +6,14 @@
#include <tracing/timelinemodel.h>
#include <QList>
#include <QMap>
#include <QSet>
#include <QStack>
#include <QVector>
namespace Timeline {
class TimelineModelAggregator;
}
namespace Timeline { class TimelineModelAggregator; }
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
class CtfTraceManager;
@@ -73,8 +70,8 @@ protected:
QString m_processName;
int m_maxStackSize = 0;
QVector<int> m_rows;
QVector<QMap<int, QPair<QString, QString>>> m_details;
QList<int> m_rows;
QList<QMap<int, QPair<QString, QString>>> m_details;
QSet<int> m_handledTypeIds;
QStack<int> m_openEventIds;
QSet<QString> m_reusableStrings;
@@ -86,12 +83,11 @@ protected:
float max = std::numeric_limits<float>::min();
};
QVector<std::string> m_counterNames;
QVector<CounterData> m_counterData;
QVector<float> m_counterValues;
QVector<int> m_itemToCounterIdx;
QVector<int> m_counterIndexToRow;
QList<std::string> m_counterNames;
QList<CounterData> m_counterData;
QList<float> m_counterValues;
QList<int> m_itemToCounterIdx;
QList<int> m_counterIndexToRow;
};
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal

View File

@@ -13,11 +13,9 @@
#include <QMessageBox>
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
using json = nlohmann::json;
using namespace Constants;
CtfTraceManager::CtfTraceManager(QObject *parent,
@@ -152,7 +150,7 @@ QList<CtfTimelineModel *> CtfTraceManager::getSortedThreads() const
QList<CtfTimelineModel *> models = m_threadModels.values();
std::sort(models.begin(),
models.end(),
[](const CtfTimelineModel *a, const CtfTimelineModel *b) -> bool {
[](const CtfTimelineModel *a, const CtfTimelineModel *b) {
return (a->m_processId != b->m_processId) ? (a->m_processId < b->m_processId)
: (a->m_threadId < b->m_threadId);
});
@@ -238,5 +236,4 @@ QString CtfTraceManager::errorString() const
return m_errorString;
}
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal

View File

@@ -11,8 +11,7 @@
namespace Timeline { class TimelineModelAggregator; }
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
class CtfStatisticsModel;
class CtfTimelineModel;
@@ -71,5 +70,4 @@ protected:
QString m_errorString;
};
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal

View File

@@ -4,8 +4,7 @@
#include <string>
namespace CtfVisualizer {
namespace Constants {
namespace CtfVisualizer::Constants {
const char CtfVisualizerMenuId[] = "Analyzer.Menu.CtfVisualizer";
const char CtfVisualizerTaskLoadJson[] =
@@ -31,5 +30,4 @@ const char CtfEventTypeInstant[] = "i";
const char CtfEventTypeInstantDeprecated[] = "I";
const char CtfEventTypeCounter[] = "C";
} // namespace Constants
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Constants

View File

@@ -5,8 +5,7 @@
#include "ctfvisualizertool.h"
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
class CtfVisualizerPluginPrivate
{
@@ -24,5 +23,4 @@ void CtfVisualizerPlugin::initialize()
d = new CtfVisualizerPluginPrivate;
}
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal

View File

@@ -5,8 +5,7 @@
#include <extensionsystem/iplugin.h>
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
class CtfVisualizerPlugin : public ExtensionSystem::IPlugin
{
@@ -21,5 +20,4 @@ public:
class CtfVisualizerPluginPrivate *d = nullptr;
};
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal

View File

@@ -31,17 +31,14 @@ using namespace Core;
using namespace CtfVisualizer::Constants;
using namespace Utils;
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
using json = nlohmann::json;
CtfVisualizerTool::CtfVisualizerTool()
: QObject (nullptr)
, m_loadJson(nullptr)
, m_traceView(nullptr)
, m_modelAggregator(new Timeline::TimelineModelAggregator(this))
: m_modelAggregator(new Timeline::TimelineModelAggregator(this))
, m_zoomControl(new Timeline::TimelineZoomControl(this))
, m_statisticsModel(new CtfStatisticsModel(this))
, m_statisticsView(nullptr)
, m_traceManager(new CtfTraceManager(this, m_modelAggregator.get(), m_statisticsModel.get()))
, m_restrictToThreadsButton(new QToolButton)
, m_restrictToThreadsMenu(new QMenu(m_restrictToThreadsButton))
@@ -68,12 +65,12 @@ CtfVisualizerTool::CtfVisualizerTool()
});
options->addAction(command);
m_perspective.setAboutToActivateCallback([this]() { createViews(); });
m_perspective.setAboutToActivateCallback([this] { createViews(); });
m_restrictToThreadsButton->setIcon(Utils::Icons::FILTER.icon());
m_restrictToThreadsButton->setIcon(Icons::FILTER.icon());
m_restrictToThreadsButton->setToolTip(Tr::tr("Restrict to Threads"));
m_restrictToThreadsButton->setPopupMode(QToolButton::InstantPopup);
m_restrictToThreadsButton->setProperty(Utils::StyleHelper::C_NO_ARROW, true);
m_restrictToThreadsButton->setProperty(StyleHelper::C_NO_ARROW, true);
m_restrictToThreadsButton->setMenu(m_restrictToThreadsMenu);
connect(m_restrictToThreadsMenu, &QMenu::triggered,
this, &CtfVisualizerTool::toggleThreadRestriction);
@@ -90,7 +87,7 @@ void CtfVisualizerTool::createViews()
QMenu *contextMenu = new QMenu(m_traceView);
contextMenu->addAction(m_loadJson.get());
connect(contextMenu->addAction(Tr::tr("Reset Zoom")), &QAction::triggered, this, [this](){
connect(contextMenu->addAction(Tr::tr("Reset Zoom")), &QAction::triggered, this, [this] {
m_zoomControl->setRange(m_zoomControl->traceStart(), m_zoomControl->traceEnd());
});
@@ -100,7 +97,7 @@ void CtfVisualizerTool::createViews()
contextMenu->exec(m_traceView->mapToGlobal(pos));
});
m_perspective.addWindow(m_traceView, Utils::Perspective::OperationType::SplitVertical, nullptr);
m_perspective.addWindow(m_traceView, Perspective::OperationType::SplitVertical, nullptr);
m_statisticsView = new CtfStatisticsView(m_statisticsModel.get());
m_statisticsView->setWindowTitle(Tr::tr("Statistics"));
@@ -111,9 +108,9 @@ void CtfVisualizerTool::createViews()
connect(m_traceManager.get(), &CtfTraceManager::detailsRequested, m_statisticsView,
&CtfStatisticsView::selectByTitle);
m_perspective.addWindow(m_statisticsView, Utils::Perspective::AddToTab, m_traceView);
m_perspective.addWindow(m_statisticsView, Perspective::AddToTab, m_traceView);
m_perspective.setAboutToActivateCallback(Utils::Perspective::Callback());
m_perspective.setAboutToActivateCallback(Perspective::Callback());
}
void CtfVisualizerTool::setAvailableThreads(const QList<CtfTimelineModel *> &threads)
@@ -152,12 +149,11 @@ Timeline::TimelineZoomControl *CtfVisualizerTool::zoomControl() const
class CtfJsonParserFunctor
{
public:
CtfJsonParserFunctor(QPromise<nlohmann::json> &promise)
CtfJsonParserFunctor(QPromise<json> &promise)
: m_promise(promise) {}
bool operator()(int depth, nlohmann::json::parse_event_t event, nlohmann::json &parsed)
bool operator()(int depth, json::parse_event_t event, json &parsed)
{
using json = nlohmann::json;
if ((event == json::parse_event_t::array_start && depth == 0)
|| (event == json::parse_event_t::key && depth == 1 && parsed == json(CtfTraceEventsKey))) {
m_isInTraceArray = true;
@@ -182,15 +178,13 @@ public:
}
protected:
QPromise<nlohmann::json> &m_promise;
QPromise<json> &m_promise;
bool m_isInTraceArray = false;
int m_traceArrayDepth = 0;
};
static void load(QPromise<nlohmann::json> &promise, const QString &fileName)
static void load(QPromise<json> &promise, const QString &fileName)
{
using json = nlohmann::json;
std::ifstream file(fileName.toStdString());
if (!file.is_open()) {
promise.future().cancel();
@@ -218,7 +212,7 @@ void CtfVisualizerTool::loadJson(const QString &fileName)
if (m_loader || fileName.isEmpty())
return;
const auto onSetup = [this, fileName](Async<nlohmann::json> &async) {
const auto onSetup = [this, fileName](Async<json> &async) {
m_traceManager->clearAll();
async.setConcurrentCallData(load, fileName);
connect(&async, &AsyncBase::resultReadyAt, this, [this, asyncPtr = &async](int index) {
@@ -251,7 +245,7 @@ void CtfVisualizerTool::loadJson(const QString &fileName)
m_loader.release()->deleteLater();
};
const Group recipe { AsyncTask<nlohmann::json>(onSetup) };
const Group recipe { AsyncTask<json>(onSetup) };
m_loader.reset(new TaskTree(recipe));
connect(m_loader.get(), &TaskTree::done, this, onDone);
connect(m_loader.get(), &TaskTree::errorOccurred, this, onError);
@@ -260,5 +254,4 @@ void CtfVisualizerTool::loadJson(const QString &fileName)
m_loader->start();
}
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal

View File

@@ -15,8 +15,7 @@
namespace Tasking { class TaskTree; }
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
class CtfTraceManager;
class CtfStatisticsModel;
@@ -47,19 +46,19 @@ private:
void setAvailableThreads(const QList<CtfTimelineModel *> &threads);
void toggleThreadRestriction(QAction *action);
Utils::Perspective m_perspective{CtfVisualizer::Constants::CtfVisualizerPerspectiveId,
Utils::Perspective m_perspective{Constants::CtfVisualizerPerspectiveId,
QCoreApplication::translate("QtC::CtfVisualizer",
"Chrome Trace Format Visualizer")};
std::unique_ptr<Tasking::TaskTree> m_loader;
QScopedPointer<QAction> m_loadJson;
CtfVisualizerTraceView *m_traceView;
CtfVisualizerTraceView *m_traceView = nullptr;
const QScopedPointer<Timeline::TimelineModelAggregator> m_modelAggregator;
const QScopedPointer<Timeline::TimelineZoomControl> m_zoomControl;
const QScopedPointer<CtfStatisticsModel> m_statisticsModel;
CtfStatisticsView *m_statisticsView;
CtfStatisticsView *m_statisticsView = nullptr;
const QScopedPointer<CtfTraceManager> m_traceManager;
@@ -67,5 +66,4 @@ private:
QMenu *const m_restrictToThreadsMenu;
};
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal

View File

@@ -13,8 +13,7 @@
#include <QQmlContext>
#include <QQmlEngine>
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
CtfVisualizerTraceView::CtfVisualizerTraceView(QWidget *parent, CtfVisualizerTool *tool)
: QQuickWidget(parent)
@@ -36,8 +35,8 @@ CtfVisualizerTraceView::CtfVisualizerTraceView(QWidget *parent, CtfVisualizerToo
setSource(QUrl(QLatin1String("qrc:/qt/qml/QtCreator/Tracing/MainView.qml")));
// Avoid ugly warnings when reading from null properties in QML.
connect(tool->modelAggregator(), &QObject::destroyed, this, [this]{ setSource(QUrl()); });
connect(tool->zoomControl(), &QObject::destroyed, this, [this]{ setSource(QUrl()); });
connect(tool->modelAggregator(), &QObject::destroyed, this, [this] { setSource({}); });
connect(tool->zoomControl(), &QObject::destroyed, this, [this] { setSource({}); });
}
CtfVisualizerTraceView::~CtfVisualizerTraceView() = default;
@@ -48,7 +47,5 @@ void CtfVisualizerTraceView::selectByTypeId(int typeId)
Q_ARG(QVariant,QVariant::fromValue<int>(typeId)));
}
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal

View File

@@ -3,10 +3,8 @@
#pragma once
#include <QQuickWidget>
#include <QWidget>
namespace CtfVisualizer {
namespace Internal {
namespace CtfVisualizer::Internal {
class CtfVisualizerTool;
@@ -22,7 +20,5 @@ public:
void selectByTypeId(int typeId);
};
} // namespace Internal
} // namespace CtfVisualizer
} // namespace CtfVisualizer::Internal