Commit 2f3fbdbe authored by Nicolas Carion's avatar Nicolas Carion
Browse files

clang-tidy modernize

parent 8d03962a
......@@ -303,27 +303,27 @@ void fuzz(const std::string &input)
int compoId = get_compo(tim);
valid = valid && (compoId >= 0);
// std::cout << "got compo" << compoId << std::endl;
arguments.push_back(compoId);
arguments.emplace_back(compoId);
} else if (arg_name == "clipId") {
std::shared_ptr<TimelineModel> tim =
(ptr.can_convert<std::shared_ptr<TimelineModel>>() ? ptr.convert<std::shared_ptr<TimelineModel>>() : nullptr);
int clipId = get_clip(tim);
valid = valid && (clipId >= 0);
arguments.push_back(clipId);
arguments.emplace_back(clipId);
// std::cout << "got clipId" << clipId << std::endl;
} else if (arg_name == "trackId") {
std::shared_ptr<TimelineModel> tim =
(ptr.can_convert<std::shared_ptr<TimelineModel>>() ? ptr.convert<std::shared_ptr<TimelineModel>>() : nullptr);
int trackId = get_track(tim);
valid = valid && (trackId >= 0);
arguments.push_back(rttr::variant(trackId));
arguments.emplace_back(trackId);
// std::cout << "got trackId" << trackId << std::endl;
} else if (arg_name == "itemId") {
std::shared_ptr<TimelineModel> tim =
(ptr.can_convert<std::shared_ptr<TimelineModel>>() ? ptr.convert<std::shared_ptr<TimelineModel>>() : nullptr);
int itemId = get_item(tim);
valid = valid && (itemId >= 0);
arguments.push_back(itemId);
arguments.emplace_back(itemId);
// std::cout << "got itemId" << itemId << std::endl;
} else if (arg_name == "ids") {
int count = 0;
......@@ -339,7 +339,7 @@ void fuzz(const std::string &input)
valid = valid && (itemId >= 0);
ids.insert(itemId);
}
arguments.push_back(ids);
arguments.emplace_back(ids);
} else {
valid = false;
}
......@@ -349,12 +349,12 @@ void fuzz(const std::string &input)
int a = 0;
ss >> a;
// std::cout << "read int " << a << std::endl;
arguments.push_back(a);
arguments.emplace_back(a);
} else if (arg_type == rttr::type::get<bool>()) {
bool a = false;
ss >> a;
// std::cout << "read bool " << a << std::endl;
arguments.push_back(a);
arguments.emplace_back(a);
} else if (arg_type == rttr::type::get<QString>()) {
std::string str = "";
ss >> str;
......@@ -362,7 +362,7 @@ void fuzz(const std::string &input)
if (str == "$$") {
str = "";
}
arguments.push_back(QString::fromStdString(str));
arguments.emplace_back(QString::fromStdString(str));
} else if (arg_type.is_enumeration()) {
int a = 0;
ss >> a;
......@@ -375,7 +375,7 @@ void fuzz(const std::string &input)
}
} else {
if (p.get_type() == rttr::type::get<int>()) {
arguments.push_back(-1);
arguments.emplace_back(-1);
} else {
assert(false);
}
......@@ -410,8 +410,8 @@ void fuzz(const std::string &input)
all_clips.clear();
all_tracks.clear();
all_compositions.clear();
for (size_t i = 0; i < all_timelines.size(); ++i) {
all_timelines[i].reset();
for (auto &all_timeline : all_timelines) {
all_timeline.reset();
}
pCore->m_projectManager = nullptr;
......
......@@ -28,7 +28,7 @@
#include <QString>
#include <QStringList>
#include <QUrl>
#include <stdio.h>
#include <cstdio>
int main(int argc, char **argv)
{
......@@ -118,7 +118,7 @@ int main(int argc, char **argv)
out = consumer.attribute("out").toInt();
}
}
RenderJob *rJob = new RenderJob(render, playlist, target, pid, in, out);
auto *rJob = new RenderJob(render, playlist, target, pid, in, out);
rJob->start();
return app.exec();
} else {
......
......@@ -23,7 +23,7 @@
#include <QStringList>
#include <QThread>
#include <QtDBus>
#include <utility>
// Can't believe I need to do this to sleep.
class SleepThread : QThread
{
......@@ -35,9 +35,9 @@ public:
RenderJob::RenderJob(const QString &render, const QString &scenelist, const QString &target, int pid, int in, int out)
: QObject()
, m_scenelist(scenelist)
, m_dest(target)
, m_dest(std::move(target))
, m_progress(0)
, m_prog(render)
, m_prog(std::move(render))
, m_player()
, m_jobUiserver(nullptr)
, m_kdenliveinterface(nullptr)
......
......@@ -103,12 +103,12 @@ QModelIndex AbstractTreeModel::index(int row, int column, const QModelIndex &par
std::shared_ptr<TreeItem> childItem = parentItem->child(row);
if (childItem) return createIndex(row, column, quintptr(childItem->getId()));
return QModelIndex();
return {};
}
QModelIndex AbstractTreeModel::parent(const QModelIndex &index) const
{
if (!index.isValid()) return QModelIndex();
if (!index.isValid()) return {};
std::shared_ptr<TreeItem> childItem = getItemById((int)index.internalId());
std::shared_ptr<TreeItem> parentItem = childItem->parentItem().lock();
......@@ -136,7 +136,7 @@ int AbstractTreeModel::rowCount(const QModelIndex &parent) const
QModelIndex AbstractTreeModel::getIndexFromItem(const std::shared_ptr<TreeItem> &item) const
{
if (item == rootItem) {
return QModelIndex();
return {};
}
auto parentIndex = getIndexFromItem(item->parentItem().lock());
return index(item->row(), 0, parentIndex);
......@@ -151,7 +151,7 @@ QModelIndex AbstractTreeModel::getIndexFromId(int id) const
if (auto ptr = m_allItems.at(id).lock()) return getIndexFromItem(ptr);
Q_ASSERT(false);
return QModelIndex();
return {};
}
void AbstractTreeModel::notifyRowAboutToAppend(const std::shared_ptr<TreeItem> &item)
......
......@@ -46,7 +46,7 @@ protected:
explicit AbstractTreeModel(QObject *parent = nullptr);
public:
virtual ~AbstractTreeModel();
~AbstractTreeModel() override;
/* @brief Given an item from the hierarchy, construct the corresponding ModelIndex */
QModelIndex getIndexFromItem(const std::shared_ptr<TreeItem> &item) const;
......
......@@ -25,8 +25,8 @@
#include <numeric>
#include <utility>
TreeItem::TreeItem(const QList<QVariant> &data, const std::shared_ptr<AbstractTreeModel> &model, bool isRoot, int id)
: m_itemData(data)
TreeItem::TreeItem(QList<QVariant> data, const std::shared_ptr<AbstractTreeModel> &model, bool isRoot, int id)
: m_itemData(std::move(data))
, m_model(model)
, m_depth(0)
, m_id(id == -1 ? AbstractTreeModel::getNextId() : id)
......
......@@ -60,7 +60,7 @@ public:
protected:
// This is protected. Call construct instead
explicit TreeItem(const QList<QVariant> &data, const std::shared_ptr<AbstractTreeModel> &model, bool isRoot, int id = -1);
explicit TreeItem(QList<QVariant> data, const std::shared_ptr<AbstractTreeModel> &model, bool isRoot, int id = -1);
public:
virtual ~TreeItem();
......
......@@ -38,7 +38,8 @@ template <typename AssetType> class AbstractAssetsRepository
public:
AbstractAssetsRepository();
virtual ~AbstractAssetsRepository(){};
virtual ~AbstractAssetsRepository() = default;
;
/* @brief Returns true if a given asset exists
*/
......
......@@ -31,7 +31,7 @@
#include <xlocale.h>
#endif
template <typename AssetType> AbstractAssetsRepository<AssetType>::AbstractAssetsRepository() {}
template <typename AssetType> AbstractAssetsRepository<AssetType>::AbstractAssetsRepository() = default;
template <typename AssetType> void AbstractAssetsRepository<AssetType>::init()
{
......
......@@ -28,7 +28,7 @@
AssetFilter::AssetFilter(QObject *parent)
: QSortFilterProxyModel(parent)
, m_name_enabled(false)
{
setFilterRole(Qt::DisplayRole);
setSortRole(Qt::DisplayRole);
......
......@@ -64,7 +64,7 @@ protected:
/* @brief Apply all filter and returns true if the object should be kept after filtering */
virtual bool applyAll(std::shared_ptr<TreeItem> item) const;
bool m_name_enabled;
bool m_name_enabled{false};
QString m_name_value;
};
#endif
......@@ -34,7 +34,7 @@ class AssetTreeModel : public AbstractTreeModel
{
public:
explicit AssetTreeModel(QObject *parent = 0);
explicit AssetTreeModel(QObject *parent = nullptr);
enum { IdRole = Qt::UserRole + 1, NameRole, FavoriteRole };
......
......@@ -32,7 +32,7 @@
AssetListWidget::AssetListWidget(QWidget *parent)
: QQuickWidget(parent)
, m_assetIconProvider(nullptr)
{
KDeclarative::KDeclarative kdeclarative;
kdeclarative.setDeclarativeEngine(engine());
......
......@@ -41,7 +41,7 @@ class AssetListWidget : public QQuickWidget
public:
AssetListWidget(QWidget *parent = Q_NULLPTR);
virtual ~AssetListWidget();
~AssetListWidget() override;
/* @brief Returns the name of the asset given its model index */
QString getName(const QModelIndex &index) const;
......@@ -74,7 +74,7 @@ protected:
std::shared_ptr<AssetTreeModel> m_model;
std::unique_ptr<AssetFilter> m_proxyModel;
// the QmlEngine takes ownership of the image provider
AssetIconProvider *m_assetIconProvider;
AssetIconProvider *m_assetIconProvider{nullptr};
signals:
void activateAsset(const QVariantMap data);
......
......@@ -53,7 +53,7 @@ AssetPanel::AssetPanel(QWidget *parent)
, m_transitionWidget(new TransitionStackView(this))
, m_effectStackWidget(new EffectStackView(this))
{
QToolBar *buttonToolbar = new QToolBar(this);
auto *buttonToolbar = new QToolBar(this);
buttonToolbar->addWidget(m_assetTitle);
int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
QSize iconSize(size, size);
......@@ -99,11 +99,11 @@ AssetPanel::AssetPanel(QWidget *parent)
m_lay->addWidget(buttonToolbar);
m_lay->setContentsMargins(0, 0, 0, 0);
m_lay->setSpacing(0);
QVBoxLayout *lay = new QVBoxLayout(m_container);
auto *lay = new QVBoxLayout(m_container);
lay->setContentsMargins(0, 0, 0, 0);
lay->addWidget(m_transitionWidget);
lay->addWidget(m_effectStackWidget);
QScrollArea *sc = new QScrollArea;
auto *sc = new QScrollArea;
sc->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
sc->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
sc->setFrameStyle(QFrame::NoFrame);
......
......@@ -38,8 +38,8 @@ void CornersHelper::slotUpdateFromMonitorData(const QVariantList &v)
const QVariantList points = QVariant(v).toList();
QSize frameSize = pCore->getCurrentFrameSize();
int ix = 0;
for (int i = 0; i < points.size(); i++) {
QPointF pt = points.at(i).toPointF();
for (const auto &point : points) {
QPointF pt = point.toPointF();
double x = (pt.x() / frameSize.width() + 1) / 3;
double y = (pt.y() / frameSize.height() + 1) / 3;
emit updateKeyframeData(m_indexes.at(ix), x);
......@@ -54,7 +54,7 @@ void CornersHelper::refreshParams(int pos)
QList<double> coords;
QSize frameSize = pCore->getCurrentFrameSize();
for (const auto &ix : m_indexes) {
ParamType type = m_model->data(ix, AssetParameterModel::TypeRole).value<ParamType>();
auto type = m_model->data(ix, AssetParameterModel::TypeRole).value<ParamType>();
if (type != ParamType::KeyframeParam) {
continue;
}
......
......@@ -46,7 +46,7 @@ ObjectId KeyframeModelList::getOwnerId() const
if (auto ptr = m_model.lock()) {
return ptr->getOwnerId();
}
return ObjectId();
return {};
}
void KeyframeModelList::addParameter(const QModelIndex &index)
......@@ -98,7 +98,7 @@ bool KeyframeModelList::addKeyframe(int frame, double val)
bool isRectParam = false;
if (m_inTimelineIndex.isValid()) {
if (auto ptr = m_model.lock()) {
ParamType tp = ptr->data(m_inTimelineIndex, AssetParameterModel::TypeRole).value<ParamType>();
auto tp = ptr->data(m_inTimelineIndex, AssetParameterModel::TypeRole).value<ParamType>();
if (tp == ParamType::AnimatedRect) {
isRectParam = true;
}
......@@ -166,7 +166,7 @@ bool KeyframeModelList::updateKeyframe(GenTime oldPos, GenTime pos, const QVaria
bool isRectParam = false;
if (m_inTimelineIndex.isValid()) {
if (auto ptr = m_model.lock()) {
ParamType tp = ptr->data(m_inTimelineIndex, AssetParameterModel::TypeRole).value<ParamType>();
auto tp = ptr->data(m_inTimelineIndex, AssetParameterModel::TypeRole).value<ParamType>();
if (tp == ParamType::AnimatedRect) {
isRectParam = true;
}
......@@ -201,7 +201,7 @@ bool KeyframeModelList::updateKeyframe(GenTime pos, const QVariant &value, const
pos = kf.first;
}
if (auto ptr = m_model.lock()) {
AssetKeyframeCommand *command = new AssetKeyframeCommand(ptr, index, value, pos);
auto *command = new AssetKeyframeCommand(ptr, index, value, pos);
pCore->pushUndo(command);
}
return true;
......
......@@ -24,7 +24,7 @@ BPoint::BPoint()
: h1(-1, -1)
, p(-1, -1)
, h2(-1, -1)
, handlesLinked(true)
{
}
......
......@@ -66,7 +66,7 @@ public:
/** handle 2 */
QPointF h2;
/** handles are linked to achieve a natural locking spline => PH1 = -r*PH2 ; a line can be drawn through h1, p, h2 */
bool handlesLinked;
bool handlesLinked{true};
};
#endif
......@@ -65,10 +65,10 @@ void RotoHelper::refreshParams(int pos)
if (!keyframes->isEmpty()) {
QVariant splineData = keyframes->getInterpolatedValue(pos, m_indexes.first());
QList<BPoint> p = getPoints(splineData, pCore->getCurrentFrameSize());
for (int i = 0; i < p.size(); i++) {
centerPoints << QVariant(p.at(i).p);
controlPoints << QVariant(p.at(i).h1);
controlPoints << QVariant(p.at(i).h2);
for (const auto &i : p) {
centerPoints << QVariant(i.p);
controlPoints << QVariant(i.h1);
controlPoints << QVariant(i.h2);
}
if (m_monitor) {
m_monitor->setUpEffectGeometry(QRect(), centerPoints, controlPoints);
......
......@@ -24,12 +24,12 @@
#include "effects/effectsrepository.hpp"
#include "transitions/transitionsrepository.hpp"
#include <memory>
AssetCommand::AssetCommand(const std::shared_ptr<AssetParameterModel> &model, const QModelIndex &index, const QString &value, QUndoCommand *parent)
#include <utility>
AssetCommand::AssetCommand(const std::shared_ptr<AssetParameterModel> &model, const QModelIndex &index, QString value, QUndoCommand *parent)
: QUndoCommand(parent)
, m_model(model)
, m_index(index)
, m_value(value)
, m_value(std::move(value))
, m_updateView(false)
, m_stamp(QTime::currentTime())
{
......@@ -73,12 +73,12 @@ bool AssetCommand::mergeWith(const QUndoCommand *other)
return true;
}
AssetKeyframeCommand::AssetKeyframeCommand(const std::shared_ptr<AssetParameterModel> &model, const QModelIndex &index, const QVariant &value, GenTime pos,
AssetKeyframeCommand::AssetKeyframeCommand(const std::shared_ptr<AssetParameterModel> &model, const QModelIndex &index, QVariant value, GenTime pos,
QUndoCommand *parent)
: QUndoCommand(parent)
, m_model(model)
, m_index(index)
, m_value(value)
, m_value(std::move(value))
, m_pos(pos)
, m_updateView(false)
, m_stamp(QTime::currentTime())
......@@ -120,11 +120,10 @@ bool AssetKeyframeCommand::mergeWith(const QUndoCommand *other)
return true;
}
AssetUpdateCommand::AssetUpdateCommand(const std::shared_ptr<AssetParameterModel> &model, const QVector<QPair<QString, QVariant>> &parameters,
QUndoCommand *parent)
AssetUpdateCommand::AssetUpdateCommand(const std::shared_ptr<AssetParameterModel> &model, QVector<QPair<QString, QVariant>> parameters, QUndoCommand *parent)
: QUndoCommand(parent)
, m_model(model)
, m_value(parameters)
, m_value(std::move(parameters))
{
const QString id = model->getAssetId();
if (EffectsRepository::get()->exists(id)) {
......
......@@ -30,7 +30,7 @@
class AssetCommand : public QUndoCommand
{
public:
AssetCommand(const std::shared_ptr<AssetParameterModel> &model, const QModelIndex &index, const QString &value, QUndoCommand *parent = nullptr);
AssetCommand(const std::shared_ptr<AssetParameterModel> &model, const QModelIndex &index, QString value, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
int id() const override;
......@@ -49,7 +49,7 @@ private:
class AssetKeyframeCommand : public QUndoCommand
{
public:
AssetKeyframeCommand(const std::shared_ptr<AssetParameterModel> &model, const QModelIndex &index, const QVariant &value, GenTime pos,
AssetKeyframeCommand(const std::shared_ptr<AssetParameterModel> &model, const QModelIndex &index, QVariant value, GenTime pos,
QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
......@@ -69,7 +69,7 @@ private:
class AssetUpdateCommand : public QUndoCommand
{
public:
AssetUpdateCommand(const std::shared_ptr<AssetParameterModel> &model, const QVector<QPair<QString, QVariant>> &parameters, QUndoCommand *parent = nullptr);
AssetUpdateCommand(const std::shared_ptr<AssetParameterModel> &model, QVector<QPair<QString, QVariant>> parameters, QUndoCommand *parent = nullptr);
void undo() override;
void redo() override;
int id() const override;
......
......@@ -701,8 +701,8 @@ const QStringList AssetParameterModel::getPresetList(const QString &presetFile)
qDebug() << "// PRESET LIST IS AN ARRAY!!!";
QStringList result;
QJsonArray array = loadDoc.array();
for (int i = 0; i < array.size(); i++) {
QJsonValue val = array.at(i);
for (auto &&i : array) {
QJsonValue val = i;
if (val.isObject()) {
result << val.toObject().keys();
}
......@@ -733,14 +733,14 @@ const QVector<QPair<QString, QVariant>> AssetParameterModel::loadPreset(const QS
}
} else if (loadDoc.isArray()) {
QJsonArray array = loadDoc.array();
for (int i = 0; i < array.size(); i++) {
QJsonValue val = array.at(i);
for (auto &&i : array) {
QJsonValue val = i;
if (val.isObject() && val.toObject().contains(presetName)) {
QJsonValue preset = val.toObject().value(presetName);
if (preset.isArray()) {
QJsonArray paramArray = preset.toArray();
for (int j = 0; j < paramArray.size(); j++) {
QJsonValue v1 = paramArray.at(j);
for (auto &&j : paramArray) {
QJsonValue v1 = j;
if (v1.isObject()) {
QJsonObject ob = v1.toObject();
params.append({ob.value("name").toString(), ob.value("value").toVariant()});
......
......@@ -74,7 +74,7 @@ class AssetParameterModel : public QAbstractListModel, public enable_shared_from
public:
explicit AssetParameterModel(std::unique_ptr<Mlt::Properties> asset, const QDomElement &assetXml, const QString &assetId, ObjectId ownerId,
QObject *parent = nullptr);
virtual ~AssetParameterModel();
~AssetParameterModel() override;
enum DataRoles {
NameRole = Qt::UserRole + 1,
TypeRole,
......
......@@ -40,7 +40,7 @@
AssetParameterView::AssetParameterView(QWidget *parent)
: QWidget(parent)
, m_mainKeyframeWidget(nullptr)
{
m_lay = new QVBoxLayout(this);
m_lay->setContentsMargins(0, 0, 0, 2);
......@@ -123,7 +123,7 @@ QVector<QPair<QString, QVariant>> AssetParameterView::getDefaultValues() const
for (int i = 0; i < m_model->rowCount(); ++i) {
QModelIndex index = m_model->index(i, 0);
QString name = m_model->data(index, AssetParameterModel::NameRole).toString();
ParamType type = m_model->data(index, AssetParameterModel::TypeRole).value<ParamType>();
auto type = m_model->data(index, AssetParameterModel::TypeRole).value<ParamType>();
QVariant defaultValue = m_model->data(index, AssetParameterModel::DefaultRole);
if (type == ParamType::KeyframeParam || type == ParamType::AnimatedRect) {
QString val = type == ParamType::KeyframeParam ? locale.toString(defaultValue.toDouble()) : defaultValue.toString();
......@@ -140,7 +140,7 @@ QVector<QPair<QString, QVariant>> AssetParameterView::getDefaultValues() const
void AssetParameterView::resetValues()
{
const QVector<QPair<QString, QVariant>> values = getDefaultValues();
AssetUpdateCommand *command = new AssetUpdateCommand(m_model, values);
auto *command = new AssetUpdateCommand(m_model, values);
pCore->pushUndo(command);
/*if (m_mainKeyframeWidget) {
m_mainKeyframeWidget->resetKeyframes();
......@@ -150,7 +150,7 @@ void AssetParameterView::resetValues()
void AssetParameterView::commitChanges(const QModelIndex &index, const QString &value, bool storeUndo)
{
// Warning: please note that some widgets (for example keyframes) do NOT send the valueChanged signal and do modifications on their own
AssetCommand *command = new AssetCommand(m_model, index, value);
auto *command = new AssetCommand(m_model, index, value);
if (storeUndo) {
pCore->pushUndo(command);
} else {
......@@ -209,7 +209,7 @@ void AssetParameterView::refresh(const QModelIndex &topLeft, const QModelIndex &
return;
}
Q_ASSERT(bottomRight.row() < (int)m_widgets.size());
for (size_t i = (size_t)topLeft.row(); i <= (size_t)bottomRight.row(); ++i) {
for (auto i = (size_t)topLeft.row(); i <= (size_t)bottomRight.row(); ++i) {
if (m_widgets.size() > i) {
m_widgets[i]->slotRefresh();
}
......@@ -316,7 +316,7 @@ void AssetParameterView::slotSavePreset(QString presetName)
void AssetParameterView::slotLoadPreset()
{
QAction *action = qobject_cast<QAction *>(sender());
auto *action = qobject_cast<QAction *>(sender());
if (!action) {
return;
}
......@@ -324,7 +324,7 @@ void AssetParameterView::slotLoadPreset()
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/effects/presets/"));
const QString presetFile = dir.absoluteFilePath(QString("%1.json").arg(m_model->getAssetId()));
const QVector<QPair<QString, QVariant>> params = m_model->loadPreset(presetFile, presetName);
AssetUpdateCommand *command = new AssetUpdateCommand(m_model, params);
auto *command = new AssetUpdateCommand(m_model, params);
pCore->pushUndo(command);
}
......
......@@ -89,7 +89,7 @@ protected:
QMutex m_lock;
std::shared_ptr<AssetParameterModel> m_model;
std::vector<AbstractParamWidget *> m_widgets;
KeyframeWidget *m_mainKeyframeWidget;