Commit 93b3e120 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Modernize code

parent 2a41c2a7
......@@ -110,7 +110,7 @@ void FileMetadataDateDisplayTest::shouldDisplayLongAndShortDates()
widget->setItems(KFileItemList() << file);
QVERIFY(spy.wait());
QLabel *dateWidget = widget->findChild<QLabel *>(QStringLiteral("kfileitem#modified"), Qt::FindDirectChildrenOnly);
auto dateWidget = widget->findChild<QLabel *>(QStringLiteral("kfileitem#modified"), Qt::FindDirectChildrenOnly);
QVERIFY2(dateWidget, "Date widget not found");
QVERIFY2(regex.match(dateWidget->text()).hasMatch(), qPrintable(QStringLiteral("\"%1\" did not match %2").arg(dateWidget->text(), regex.pattern())));
}
......@@ -120,13 +120,13 @@ void FileMetadataWidgetTest::shouldShowProperties()
QCOMPARE(spy.count(), 1);
// simple property
QLabel *valueWidget = m_widget->findChild<QLabel *>(QStringLiteral("kfileitem#type"));
auto valueWidget = m_widget->findChild<QLabel *>(QStringLiteral("kfileitem#type"));
QVERIFY2(valueWidget, "Type data missing");
QCOMPARE(valueWidget->text(), QLatin1String("MP3 audio"));
if (m_mayTestRating) {
// editable property
KRatingWidget *ratingWidget = m_widget->findChild<KRatingWidget *>(QStringLiteral("rating"));
auto ratingWidget = m_widget->findChild<KRatingWidget *>(QStringLiteral("rating"));
QVERIFY2(ratingWidget, "Rating data missing");
QCOMPARE(ratingWidget->rating(), 5u);
} else {
......@@ -147,7 +147,7 @@ void FileMetadataWidgetTest::shouldShowCommonProperties()
QCOMPARE(spy.count(), 1);
// simple property
QLabel *valueWidget = m_widget->findChild<QLabel *>(QStringLiteral("kfileitem#type"));
auto valueWidget = m_widget->findChild<QLabel *>(QStringLiteral("kfileitem#type"));
QVERIFY(!valueWidget);
valueWidget = m_widget->findChild<QLabel *>(QStringLiteral("kfileitem#totalSize"));
......@@ -156,7 +156,7 @@ void FileMetadataWidgetTest::shouldShowCommonProperties()
// editable property
if (m_mayTestRating) {
KRatingWidget *ratingWidget = m_widget->findChild<KRatingWidget *>(QStringLiteral("rating"));
auto ratingWidget = m_widget->findChild<KRatingWidget *>(QStringLiteral("rating"));
QVERIFY2(ratingWidget, "Rating data missing");
QCOMPARE(ratingWidget->rating(), 5u);
} else {
......
......@@ -55,7 +55,7 @@ FileMetaDataConfigWidgetPrivate::FileMetaDataConfigWidgetPrivate(FileMetaDataCon
m_metaDataList->setSelectionMode(QAbstractItemView::NoSelection);
m_metaDataList->setSortingEnabled(true);
QVBoxLayout *layout = new QVBoxLayout(q);
auto layout = new QVBoxLayout(q);
layout->addWidget(m_metaDataList);
m_provider = new FileMetaDataProvider(q);
......@@ -98,7 +98,7 @@ void FileMetaDataConfigWidgetPrivate::addItem(const QString &key)
const QString label = m_provider->label(key);
QListWidgetItem *item = new QListWidgetItem(label, m_metaDataList);
auto item = new QListWidgetItem(label, m_metaDataList);
item->setData(Qt::UserRole, key);
const bool show = settings.readEntry(key, true);
item->setCheckState(show ? Qt::Checked : Qt::Unchecked);
......
......@@ -33,7 +33,7 @@ namespace
QVariant intersect(const QVariant &v1, const QVariant &v2)
{
if (!v1.isValid() || !v2.isValid()) {
return QVariant();
return {};
}
// List and String
......@@ -72,7 +72,7 @@ QVariant intersect(const QVariant &v1, const QVariant &v2)
return v1;
}
return QVariant();
return {};
}
/**
......@@ -118,7 +118,7 @@ void FileMetaDataProvider::totalPropertyAndInsert(const QString &prop, const QLi
void FileMetaDataProvider::slotFileFetchFinished(KJob *job)
{
FileFetchJob *fetchJob = static_cast<FileFetchJob *>(job);
auto fetchJob = static_cast<FileFetchJob *>(job);
QList<QVariantMap> files = fetchJob->data();
Q_ASSERT(!files.isEmpty());
......@@ -345,9 +345,7 @@ FileMetaDataProvider::FileMetaDataProvider(QObject *parent)
{
}
FileMetaDataProvider::~FileMetaDataProvider()
{
}
FileMetaDataProvider::~FileMetaDataProvider() = default;
void FileMetaDataProvider::setFileItem()
{
......@@ -405,7 +403,7 @@ void FileMetaDataProvider::setFileItems()
// Editing only if all URLs are local
bool canEdit = (urls.size() == m_fileItems.size());
FileFetchJob *job = new FileFetchJob(urls, canEdit, FileFetchJob::UseRealtimeIndexing::Disabled, this);
auto job = new FileFetchJob(urls, canEdit, FileFetchJob::UseRealtimeIndexing::Disabled, this);
connect(job, &FileFetchJob::finished, this, &FileMetaDataProvider::slotFileFetchFinished);
job->start();
......
......@@ -103,7 +103,7 @@ void FileMetaDataWidgetPrivate::deleteRows()
QLabel *FileMetaDataWidgetPrivate::createLabel(const QString &key, const QString &itemLabel, FileMetaDataWidget *parent)
{
QLabel *label = new QLabel(itemLabel + QLatin1Char(':'), parent);
auto label = new QLabel(itemLabel + QLatin1Char(':'), parent);
label->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
label->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred);
label->setForegroundRole(parent->foregroundRole());
......@@ -348,7 +348,7 @@ QSize FileMetaDataWidget::sizeHint() const
const int width = d->m_gridLayout->margin() * 2 + leftWidthMax + d->m_gridLayout->spacing() + rightWidthMax;
return QSize(width, height);
return {width, height};
}
void FileMetaDataWidget::setConfigurationMode(ConfigurationMode mode)
......
......@@ -24,16 +24,16 @@ BalooFilePropertiesPlugin::BalooFilePropertiesPlugin(QObject *parent, const QLis
{
Q_UNUSED(args);
QWidget *widgetContainer = new QWidget();
auto widgetContainer = new QWidget();
QVBoxLayout *containerLayout = new QVBoxLayout(widgetContainer);
auto containerLayout = new QVBoxLayout(widgetContainer);
containerLayout->setContentsMargins(0, 0, 0, 0);
containerLayout->setSpacing(0);
auto *metaDataWidget = new Baloo::FileMetaDataWidget();
auto metaDataWidget = new Baloo::FileMetaDataWidget();
metaDataWidget->setItems(properties->items());
connect(metaDataWidget, &Baloo::FileMetaDataWidget::urlActivated, this, [this](const QUrl &url) {
KIO::OpenUrlJob *job = new KIO::OpenUrlJob(url);
auto job = new KIO::OpenUrlJob(url);
job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, properties));
job->start();
});
......@@ -41,7 +41,7 @@ BalooFilePropertiesPlugin::BalooFilePropertiesPlugin(QObject *parent, const QLis
containerLayout->addWidget(metaDataWidget);
containerLayout->addStretch(1);
QScrollArea *metaDataArea = new QScrollArea();
auto metaDataArea = new QScrollArea();
metaDataArea->setWidget(widgetContainer);
metaDataArea->setWidgetResizable(true);
......
......@@ -28,7 +28,7 @@ public:
if (!parent) {
return -1;
} else if (parent->isWidgetType()) {
QWidget *pw = static_cast<QWidget *>(parent);
auto pw = static_cast<QWidget *>(parent);
return pw->style()->pixelMetric(pm, nullptr, pw);
} else {
return static_cast<QLayout *>(parent)->spacing();
......
......@@ -29,16 +29,14 @@ KCommentWidget::KCommentWidget(QWidget *parent)
m_sizeHintHelper->hide();
QVBoxLayout *layout = new QVBoxLayout(this);
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_label);
setText(m_comment);
}
KCommentWidget::~KCommentWidget()
{
}
KCommentWidget::~KCommentWidget() = default;
void KCommentWidget::setText(const QString &comment)
{
......
......@@ -21,13 +21,13 @@ KEditCommentDialog::KEditCommentDialog(QWidget *parent, const QString &commentTe
{
setWindowTitle(captionText);
QVBoxLayout *layout = new QVBoxLayout(this);
auto layout = new QVBoxLayout(this);
m_editor->setText(commentText);
layout->addWidget(m_editor);
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
auto buttonBox = new QDialogButtonBox(this);
layout->addWidget(buttonBox);
buttonBox->addButton(i18n("Save"), QDialogButtonBox::AcceptRole);
......@@ -39,9 +39,7 @@ KEditCommentDialog::KEditCommentDialog(QWidget *parent, const QString &commentTe
resize(sizeHint());
}
KEditCommentDialog::~KEditCommentDialog()
{
}
KEditCommentDialog::~KEditCommentDialog() = default;
QString KEditCommentDialog::getCommentText() const
{
......
......@@ -30,7 +30,7 @@ KEditTagsDialog::KEditTagsDialog(const QStringList &tags, QWidget *parent)
{
const QString captionText = (tags.count() > 0) ? i18nc("@title:window", "Edit Tags") : i18nc("@title:window", "Add Tags");
setWindowTitle(captionText);
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
auto buttonBox = new QDialogButtonBox(this);
buttonBox->addButton(i18n("Save"), QDialogButtonBox::AcceptRole);
buttonBox->addButton(QDialogButtonBox::Cancel);
......@@ -38,27 +38,27 @@ KEditTagsDialog::KEditTagsDialog(const QStringList &tags, QWidget *parent)
connect(buttonBox, &QDialogButtonBox::accepted, this, &KEditTagsDialog::slotAcceptedButtonClicked);
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
QVBoxLayout *topLayout = new QVBoxLayout;
auto topLayout = new QVBoxLayout;
setLayout(topLayout);
QLabel *label = new QLabel(i18nc("@label:textbox",
"Configure which tags should "
"be applied."),
this);
auto label = new QLabel(i18nc("@label:textbox",
"Configure which tags should "
"be applied."),
this);
m_tagTree = new QTreeWidget();
m_tagTree->setSortingEnabled(true);
m_tagTree->setSelectionMode(QAbstractItemView::NoSelection);
m_tagTree->setHeaderHidden(true);
QLabel *newTagLabel = new QLabel(i18nc("@label", "Create new tag:"));
auto newTagLabel = new QLabel(i18nc("@label", "Create new tag:"));
m_newTagEdit = new QLineEdit(this);
m_newTagEdit->setClearButtonEnabled(true);
m_newTagEdit->setFocus();
connect(m_newTagEdit, &QLineEdit::textEdited, this, &KEditTagsDialog::slotTextEdited);
connect(m_tagTree, &QTreeWidget::itemActivated, this, &KEditTagsDialog::slotItemActivated);
QHBoxLayout *newTagLayout = new QHBoxLayout();
auto newTagLayout = new QHBoxLayout();
newTagLayout->addWidget(newTagLabel);
newTagLayout->addWidget(m_newTagEdit, 1);
......@@ -69,9 +69,9 @@ KEditTagsDialog::KEditTagsDialog(const QStringList &tags, QWidget *parent)
resize(sizeHint());
Baloo::TagListJob *job = new Baloo::TagListJob();
auto job = new Baloo::TagListJob();
connect(job, &Baloo::TagListJob::finished, [this](KJob *job) {
Baloo::TagListJob *tjob = static_cast<Baloo::TagListJob *>(job);
auto tjob = static_cast<Baloo::TagListJob *>(job);
m_allTags = tjob->tags();
loadTagWidget();
});
......@@ -79,9 +79,7 @@ KEditTagsDialog::KEditTagsDialog(const QStringList &tags, QWidget *parent)
job->start();
}
KEditTagsDialog::~KEditTagsDialog()
{
}
KEditTagsDialog::~KEditTagsDialog() = default;
QStringList KEditTagsDialog::tags() const
{
......@@ -105,7 +103,7 @@ void KEditTagsDialog::slotItemActivated(const QTreeWidgetItem *item, int column)
{
Q_UNUSED(column)
const QString tag = qvariant_cast<QString>(item->data(0, Qt::UserRole));
const auto tag = qvariant_cast<QString>(item->data(0, Qt::UserRole));
m_newTagEdit->setText(tag + QLatin1Char('/'));
m_newTagEdit->setFocus();
}
......
......@@ -21,9 +21,7 @@ MetadataFilter::MetadataFilter(QObject *parent)
initMetaInformationSettings();
}
MetadataFilter::~MetadataFilter()
{
}
MetadataFilter::~MetadataFilter() = default;
void MetadataFilter::initMetaInformationSettings()
{
......
......@@ -20,9 +20,7 @@ OnDemandExtractor::OnDemandExtractor(QObject *parent)
{
}
OnDemandExtractor::~OnDemandExtractor()
{
}
OnDemandExtractor::~OnDemandExtractor() = default;
void OnDemandExtractor::process(const QString &filePath)
{
......
......@@ -18,7 +18,7 @@ TagCheckBox::TagCheckBox(const QString &tag, QWidget *parent)
: QWidget(parent)
, m_tag(tag)
{
QHBoxLayout *layout = new QHBoxLayout(this);
auto layout = new QHBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
m_label = new QLabel(tag.split(QLatin1Char('/'), Qt::SkipEmptyParts).last(), this);
......@@ -33,9 +33,7 @@ TagCheckBox::TagCheckBox(const QString &tag, QWidget *parent)
layout->addWidget(m_child);
}
TagCheckBox::~TagCheckBox()
{
}
TagCheckBox::~TagCheckBox() = default;
void TagCheckBox::leaveEvent(QEvent *event)
{
......@@ -48,13 +46,13 @@ bool TagCheckBox::eventFilter(QObject *watched, QEvent *event)
if (watched == m_child) {
switch (event->type()) {
case QEvent::MouseMove: {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
auto me = static_cast<QMouseEvent *>(event);
enableUrlHover(tagRect().contains(me->pos()));
break;
}
case QEvent::MouseButtonRelease: {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
auto me = static_cast<QMouseEvent *>(event);
if (me->button() == Qt::LeftButton && tagRect().contains(me->pos())) {
Q_EMIT tagClicked(m_tag);
return true;
......
......@@ -27,7 +27,7 @@ void TagWidgetPrivate::init(TagWidget *parent)
m_showAllLinkLabel = nullptr;
m_editTagsDialog = nullptr;
QGridLayout *mainLayout = new QGridLayout(q);
auto mainLayout = new QGridLayout(q);
mainLayout->setContentsMargins(0, 0, 0, 0);
// TODO spacingHint should be declared. Old code m_flowLayout = new KBlockLayout( 0, KDialog::spacingHint()*3 );
m_flowLayout = new KBlockLayout(0);
......@@ -75,7 +75,7 @@ TagCheckBox *TagWidgetPrivate::getTagCheckBox(const QString &tag)
QMap<QString, TagCheckBox *>::iterator it = m_checkBoxHash.find(tag);
if (it == m_checkBoxHash.end()) {
// kDebug() << "Creating checkbox for" << tag.genericLabel();
TagCheckBox *checkBox = new TagCheckBox(tag, q);
auto checkBox = new TagCheckBox(tag, q);
q->connect(checkBox, SIGNAL(tagClicked(QString)), SIGNAL(tagClicked(QString)));
m_checkBoxHash.insert(tag, checkBox);
m_flowLayout->addWidget(checkBox);
......
......@@ -34,9 +34,7 @@ WidgetFactory::WidgetFactory(QObject *parent)
{
}
WidgetFactory::~WidgetFactory()
{
}
WidgetFactory::~WidgetFactory() = default;
//
// Widget Creation
......@@ -140,7 +138,7 @@ QWidget *WidgetFactory::createWidget(const QString &prop, const QVariant &value,
QWidget *WidgetFactory::createTagWidget(const QStringList &tags, QWidget *parent)
{
TagWidget *tagWidget = new TagWidget(parent);
auto tagWidget = new TagWidget(parent);
tagWidget->setReadyOnly(m_readOnly);
tagWidget->setSelectedTags(tags);
......@@ -155,7 +153,7 @@ QWidget *WidgetFactory::createTagWidget(const QStringList &tags, QWidget *parent
QWidget *WidgetFactory::createCommentWidget(const QString &comment, QWidget *parent)
{
KCommentWidget *commentWidget = new KCommentWidget(parent);
auto commentWidget = new KCommentWidget(parent);
commentWidget->setText(comment);
commentWidget->setReadOnly(m_readOnly);
......@@ -168,7 +166,7 @@ QWidget *WidgetFactory::createCommentWidget(const QString &comment, QWidget *par
QWidget *WidgetFactory::createRatingWidget(int rating, QWidget *parent)
{
KRatingWidget *ratingWidget = new KRatingWidget(parent);
auto ratingWidget = new KRatingWidget(parent);
const Qt::Alignment align = (ratingWidget->layoutDirection() == Qt::LeftToRight) ? Qt::AlignLeft : Qt::AlignRight;
ratingWidget->setAlignment(align);
ratingWidget->setRating(rating);
......@@ -210,7 +208,7 @@ QSize ValueWidget::sizeHint() const
QLabel *WidgetFactory::createValueWidget(QWidget *parent)
{
ValueWidget *valueWidget = new ValueWidget(parent);
auto valueWidget = new ValueWidget(parent);
valueWidget->setTextInteractionFlags(Qt::TextSelectableByMouse);
valueWidget->setTextFormat(Qt::PlainText);
valueWidget->setWordWrap(true);
......
......@@ -34,7 +34,7 @@ FileMetadataWidgetTest::FileMetadataWidgetTest(QWidget *parent, Qt::WindowFlags
m_button = new QPushButton(QLatin1String("Select files"), this);
connect(m_button, SIGNAL(clicked(bool)), this, SLOT(slotChooseFiles()));
QVBoxLayout *layout = new QVBoxLayout(this);
auto layout = new QVBoxLayout(this);
layout->addWidget(m_button);
layout->addWidget(m_metadataWidget);
}
......
......@@ -20,7 +20,7 @@ int main(int argc, char **argv)
parser.addPositionalArgument(QStringLiteral("filename"), QStringLiteral("files"));
parser.process(app);
Baloo::FileMetaDataWidget *widget = new Baloo::FileMetaDataWidget();
auto widget = new Baloo::FileMetaDataWidget();
KFileItemList list;
const auto args = parser.positionalArguments();
......
......@@ -14,12 +14,12 @@ TagWidgetTest::TagWidgetTest()
: QWidget()
{
m_tagWidget = new Baloo::TagWidget(this);
QVBoxLayout *lay = new QVBoxLayout(this);
auto lay = new QVBoxLayout(this);
lay->addWidget(m_tagWidget);
connect(m_tagWidget, SIGNAL(tagClicked(QString)), this, SLOT(slotTagClicked(QString)));
connect(m_tagWidget, SIGNAL(selectionChanged(QStringList)), this, SLOT(slotSelectionChanged(QStringList)));
QCheckBox *box = new QCheckBox(QStringLiteral("Align Right"), this);
auto box = new QCheckBox(QStringLiteral("Align Right"), this);
connect(box, SIGNAL(toggled(bool)), this, SLOT(alignRight(bool)));
lay->addWidget(box);
......@@ -28,9 +28,7 @@ TagWidgetTest::TagWidgetTest()
lay->addWidget(box);
}
TagWidgetTest::~TagWidgetTest()
{
}
TagWidgetTest::~TagWidgetTest() = default;
void TagWidgetTest::slotTagClicked(const QString &tag)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment