Commit ff6cc853 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

More const'ify variables

parent 634691b8
Pipeline #136773 passed with stage
in 1 minute and 51 seconds
......@@ -54,7 +54,7 @@ public:
MultipleDirsFound,
};
DocumentDirFinder(const QUrl &rootUrl);
explicit DocumentDirFinder(const QUrl &rootUrl);
~DocumentDirFinder() override;
void start();
......
......@@ -67,12 +67,12 @@ QString FileNameFormater::format(const QUrl &url, const QDateTime &dateTime)
const int length = d->mFormat.length();
for (int pos = 0; pos < length; ++pos) {
QChar ch = d->mFormat[pos];
if (ch == '{') {
if (ch == QLatin1Char('{')) {
if (pos == length - 1) {
// We are at the end, ignore this
break;
}
if (d->mFormat[pos + 1] == '{') {
if (d->mFormat[pos + 1] == QLatin1Char('{')) {
// This is an escaped '{', skip one
name += '{';
++pos;
......@@ -84,7 +84,7 @@ QString FileNameFormater::format(const QUrl &url, const QDateTime &dateTime)
return name;
}
// Replace keyword with its value
QString keyword = d->mFormat.mid(pos + 1, end - pos - 1);
const QString keyword = d->mFormat.mid(pos + 1, end - pos - 1);
name += dict.value(keyword);
pos = end;
} else {
......
......@@ -40,7 +40,7 @@ class FileNameFormater
public:
using HelpMap = QMap<QString, QString>;
FileNameFormater(const QString &format);
explicit FileNameFormater(const QString &format);
~FileNameFormater();
/**
......
......@@ -190,7 +190,7 @@ ImportDialog::ImportDialog()
QUrl url = ImporterConfig::destinationUrl();
if (!url.isValid()) {
url = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation));
int year = QDate::currentDate().year();
const int year = QDate::currentDate().year();
url.setPath(url.path() + '/' + QString::number(year));
}
d->mThumbnailPage->setDestinationUrl(url);
......
......@@ -96,7 +96,7 @@ struct ImporterPrivate {
return false;
}
mTempImportDirUrl = QUrl::fromLocalFile(mTempImportDir->path() + '/');
mTempImportDirUrl = QUrl::fromLocalFile(mTempImportDir->path() + QLatin1Char('/'));
if (!mTempImportDirUrl.isValid()) {
Q_EMIT q->error(i18n("Could not create temporary upload folder."));
return false;
......@@ -131,7 +131,7 @@ struct ImporterPrivate {
// 'src' url is temporary: if we import "foo/image.jpg" and
// "bar/image.jpg", both images will be temporarily saved in the
// 'src' url.
QDateTime dateTime = TimeUtils::dateTimeForFileItem(item, TimeUtils::SkipCache);
const QDateTime dateTime = TimeUtils::dateTimeForFileItem(item, TimeUtils::SkipCache);
fileName = mFileNameFormater->format(src, dateTime);
} else {
fileName = src.fileName();
......
......@@ -46,9 +46,9 @@ struct ImporterConfigDialogPrivate : public Ui_ImporterConfigDialog {
FileNameFormater::HelpMap map = FileNameFormater::helpMap();
FileNameFormater::HelpMap::ConstIterator it = map.constBegin(), end = map.constEnd();
for (; it != end; ++it) {
QString keyword = '{' + it.key() + '}';
QString explanation = it.value().toHtmlEscaped();
QString link = QStringLiteral("<a href='%1'>%1</a>").arg(keyword);
const QString keyword = '{' + it.key() + '}';
const QString explanation = it.value().toHtmlEscaped();
const QString link = QStringLiteral("<a href='%1'>%1</a>").arg(keyword);
helpText +=
QLatin1String("<li>") + i18nc("%1 is the importer keyword, %2 is keyword explanation", "%1: %2", link, explanation) + QLatin1String("</li>");
}
......
......@@ -49,13 +49,13 @@ struct SerializedUrlMapPrivate {
{
mMap.clear();
for (int idx = 0;; ++idx) {
QString idxString = QString::number(idx);
QString key = idxString + QLatin1String(KEY_SUFFIX);
const QString idxString = QString::number(idx);
const QString key = idxString + QLatin1String(KEY_SUFFIX);
if (!mGroup.hasKey(key)) {
break;
}
QVariant keyUrl = mGroup.readEntry(key, QVariant());
QVariant valueUrl = mGroup.readEntry(idxString + QLatin1String(VALUE_SUFFIX), QVariant());
const QVariant keyUrl = mGroup.readEntry(key, QVariant());
const QVariant valueUrl = mGroup.readEntry(idxString + QLatin1String(VALUE_SUFFIX), QVariant());
mMap.insert(keyUrl.toUrl(), valueUrl.toUrl());
}
}
......@@ -66,7 +66,7 @@ struct SerializedUrlMapPrivate {
QMap<QUrl, QUrl>::ConstIterator it = mMap.constBegin(), end = mMap.constEnd();
int idx = 0;
for (; it != end; ++it, ++idx) {
QString idxString = QString::number(idx);
const QString idxString = QString::number(idx);
mGroup.writeEntry(idxString + QLatin1String(KEY_SUFFIX), QVariant(it.key()));
mGroup.writeEntry(idxString + QLatin1String(VALUE_SUFFIX), QVariant(it.value()));
}
......
......@@ -229,13 +229,13 @@ struct CropWidgetPrivate : public QWidget {
QRect cropRect() const
{
QRect rect(leftSpinBox->value(), topSpinBox->value(), widthSpinBox->value(), heightSpinBox->value());
const QRect rect(leftSpinBox->value(), topSpinBox->value(), widthSpinBox->value(), heightSpinBox->value());
return rect;
}
void initSpinBoxes()
{
QSize size = mDocument->size();
const QSize size = mDocument->size();
leftSpinBox->setMaximum(size.width());
widthSpinBox->setMaximum(size.width());
topSpinBox->setMaximum(size.height());
......
......@@ -52,7 +52,7 @@ inline int getMaxUnreferencedImages()
}
LOG("Custom value for max unreferenced images:" << ba);
bool ok;
int value = ba.toInt(&ok);
const int value = ba.toInt(&ok);
return ok ? value : defaultValue;
}
......
......@@ -336,13 +336,13 @@ void AbstractImageView::focusInEvent(QFocusEvent *event)
qreal AbstractImageView::computeZoomToFit() const
{
QSizeF docSize = dipDocumentSize();
const QSizeF docSize = dipDocumentSize();
if (docSize.isEmpty()) {
return 1;
}
QSizeF viewSize = boundingRect().size();
qreal fitWidth = viewSize.width() / docSize.width();
qreal fitHeight = viewSize.height() / docSize.height();
const QSizeF viewSize = boundingRect().size();
const qreal fitWidth = viewSize.width() / docSize.width();
const qreal fitHeight = viewSize.height() / docSize.height();
qreal fit = qMin(fitWidth, fitHeight);
if (!d->mEnlargeSmallerImages) {
fit = qMin(fit, qreal(1.));
......@@ -352,13 +352,13 @@ qreal AbstractImageView::computeZoomToFit() const
qreal AbstractImageView::computeZoomToFill() const
{
QSizeF docSize = dipDocumentSize();
const QSizeF docSize = dipDocumentSize();
if (docSize.isEmpty()) {
return 1;
}
QSizeF viewSize = boundingRect().size();
qreal fitWidth = viewSize.width() / docSize.width();
qreal fitHeight = viewSize.height() / docSize.height();
const QSizeF viewSize = boundingRect().size();
const qreal fitWidth = viewSize.width() / docSize.width();
const qreal fitHeight = viewSize.height() / docSize.height();
qreal fill = qMax(fitWidth, fitHeight);
if (!d->mEnlargeSmallerImages) {
fill = qMin(fill, qreal(1.));
......@@ -465,7 +465,7 @@ void AbstractImageView::keyPressEvent(QKeyEvent *event)
}
QPointF delta(0, 0);
qreal pageStep = boundingRect().height();
const qreal pageStep = boundingRect().height();
qreal unitStep;
if (event->modifiers() & Qt::ShiftModifier) {
......
......@@ -86,7 +86,7 @@ struct BirdEyeViewPrivate {
// No recent activity
visible = false;
}
qreal wantedOpacity = visible ? 1 : 0;
const qreal wantedOpacity = visible ? 1 : 0;
if (!qFuzzyCompare(wantedOpacity, q->opacity())) {
mOpacityAnim->setEndValue(wantedOpacity);
mOpacityAnim->start();
......@@ -147,10 +147,10 @@ void BirdEyeView::adjustGeometry()
if (size.width() > maxBevWidth) {
size.scale(maxBevWidth, MIN_SIZE, Qt::KeepAspectRatio);
}
QRectF geom = QRectF(QApplication::isRightToLeft() ? docViewRect.left() + VIEW_OFFSET : docViewRect.right() - VIEW_OFFSET - size.width(),
docViewRect.bottom() - VIEW_OFFSET - size.height(),
size.width(),
size.height());
const QRectF geom = QRectF(QApplication::isRightToLeft() ? docViewRect.left() + VIEW_OFFSET : docViewRect.right() - VIEW_OFFSET - size.width(),
docViewRect.bottom() - VIEW_OFFSET - size.height(),
size.width(),
size.height());
setGeometry(alignedRectF(geom));
adjustVisibleRect();
}
......
......@@ -116,7 +116,7 @@ struct DocumentViewPrivate {
QPointer<ThumbnailProvider> mDragThumbnailProvider;
QPointer<QDrag> mDrag;
Touch *mTouch;
Touch *mTouch = nullptr;
int mMinTimeBetweenPinch;
void setCurrentAdapter(AbstractDocumentViewAdapter *adapter)
......@@ -270,7 +270,7 @@ struct DocumentViewPrivate {
void updateZoomSnapValues()
{
qreal min = q->minimumZoom();
const qreal min = q->minimumZoom();
mZoomSnapValues.clear();
for (qreal zoom = MINSTEP; zoom > min; zoom *= MINSTEP) {
......
......@@ -48,7 +48,7 @@ struct DocumentViewContainerPrivate {
DocumentViewSet mViews;
DocumentViewSet mAddedViews;
DocumentViewSet mRemovedViews;
QTimer *mLayoutUpdateTimer;
QTimer *mLayoutUpdateTimer = nullptr;
void scheduleLayoutUpdate()
{
......
......@@ -50,24 +50,24 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
namespace Gwenview
{
struct VideoViewAdapterPrivate {
VideoViewAdapter *q;
Phonon::MediaObject *mMediaObject;
Phonon::VideoWidget *mVideoWidget;
Phonon::AudioOutput *mAudioOutput;
HudWidget *mHud;
GraphicsWidgetFloater *mFloater;
HudSlider *mSeekSlider;
VideoViewAdapter *q = nullptr;
Phonon::MediaObject *mMediaObject = nullptr;
Phonon::VideoWidget *mVideoWidget = nullptr;
Phonon::AudioOutput *mAudioOutput = nullptr;
HudWidget *mHud = nullptr;
GraphicsWidgetFloater *mFloater = nullptr;
HudSlider *mSeekSlider = nullptr;
QElapsedTimer mLastSeekSliderActionTime;
QLabel *mCurrentTime;
QLabel *mRemainingTime;
QLabel *mCurrentTime = nullptr;
QLabel *mRemainingTime = nullptr;
QAction *mPlayPauseAction;
QAction *mMuteAction;
QGraphicsProxyWidget *mProxy;
QAction *mPlayPauseAction = nullptr;
QAction *mMuteAction = nullptr;
QGraphicsProxyWidget *mProxy = nullptr;
HudSlider *mVolumeSlider;
HudSlider *mVolumeSlider = nullptr;
QElapsedTimer mLastVolumeSliderChangeTime;
Document::Ptr mDocument;
......
......@@ -64,21 +64,21 @@ struct HudButtonPrivate {
QSize minInnerSize = constraint.toSize() - QSize(2 * padding, 2 * padding);
if (!mLightIcon.isNull()) {
int size = KIconLoader::global()->currentSize(mIconGroup);
const int size = KIconLoader::global()->currentSize(mIconGroup);
info->iconRect = QRect(padding, padding, size, qMax(size, minInnerSize.height()));
minInnerSize.rwidth() -= size;
}
if (!mText.isEmpty()) {
QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
const QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
QFontMetrics fm(font);
QSize size = fm.size(0, mText).expandedTo(minInnerSize);
const QSize size = fm.size(0, mText).expandedTo(minInnerSize);
info->textRect = QRect(padding, padding, size.width(), size.height());
if (!info->iconRect.isNull()) {
info->textRect.translate(info->iconRect.right(), 0);
}
}
QRectF rect = info->iconRect | info->textRect;
const QRectF rect = info->iconRect | info->textRect;
info->size = QSize(rect.right() + padding, rect.bottom() + padding);
}
......
......@@ -38,7 +38,7 @@ struct HudButtonBoxPrivate {
QGraphicsLinearLayout *mLayout = nullptr;
HudLabel *mLabel = nullptr;
QList<HudButton *> mButtonList;
HudCountDown *mCountDown;
HudCountDown *mCountDown = nullptr;
void updateButtonWidths()
{
......@@ -90,7 +90,7 @@ void HudButtonBox::addCountDown(qreal ms)
HudButton *HudButtonBox::addAction(QAction *action, const QString &overrideText)
{
QString text = overrideText.isEmpty() ? action->text() : overrideText;
const QString text = overrideText.isEmpty() ? action->text() : overrideText;
HudButton *button = addButton(text);
connect(button, &HudButton::clicked, action, &QAction::trigger);
return button;
......
......@@ -71,8 +71,8 @@ void HudCountDown::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QW
painter->setPen(info.borderPen);
QRectF square = boundingRect().adjusted(.5, .5, -.5, -.5);
qreal width = square.width();
qreal height = square.height();
const qreal width = square.width();
const qreal height = square.height();
if (width < height) {
square.setHeight(width);
square.moveTop((height - width) / 2);
......
......@@ -56,9 +56,9 @@ HudLabel::~HudLabel()
void HudLabel::setText(const QString &text)
{
d->mText = text;
QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
const QFont font = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
QFontMetrics fm(font);
QSize minSize = fm.size(0, d->mText);
const QSize minSize = fm.size(0, d->mText);
setMinimumSize(minSize);
setPreferredSize(minSize);
}
......
......@@ -64,8 +64,8 @@ struct PrintHelperPrivate {
} else {
// No scale
const double INCHES_PER_METER = 100. / 2.54;
int dpmX = doc->image().dotsPerMeterX();
int dpmY = doc->image().dotsPerMeterY();
const int dpmX = doc->image().dotsPerMeterX();
const int dpmY = doc->image().dotsPerMeterY();
if (dpmX > 0 && dpmY > 0) {
double wImg = double(size.width()) / double(dpmX) * INCHES_PER_METER;
double hImg = double(size.height()) / double(dpmY) * INCHES_PER_METER;
......@@ -133,9 +133,9 @@ struct PrintHelperPrivate {
}
QPainter painter(printer);
QRect rect = painter.viewport();
QSize size = adjustSize(optionsPage, doc, printer->resolution(), rect.size());
QPoint pos = adjustPosition(optionsPage, size, rect.size());
const QRect rect = painter.viewport();
const QSize size = adjustSize(optionsPage, doc, printer->resolution(), rect.size());
const QPoint pos = adjustPosition(optionsPage, size, rect.size());
painter.setViewport(pos.x(), pos.y(), size.width(), size.height());
if (!dialog) {
delete optionsPage;
......
......@@ -133,7 +133,7 @@ PrintOptionsPage::~PrintOptionsPage()
Qt::Alignment PrintOptionsPage::alignment() const
{
int id = d->mPositionGroup.checkedId();
const int id = d->mPositionGroup.checkedId();
qCWarning(GWENVIEW_LIB_LOG) << "alignment=" << id;
return Qt::Alignment(id);
}
......
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