Skip to content

Commit ef0668a

Browse files
committed
App: minor code improvements
1 parent 4cf8d89 commit ef0668a

File tree

4 files changed

+30
-28
lines changed

4 files changed

+30
-28
lines changed

src/app/grid_helper.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ void ProxyModel::setSourceModel(QAbstractItemModel* newModel)
6363
QVariant ProxyModel::data(const QModelIndex& index, int role) const
6464
{
6565
const std::optional<QModelIndex> sourceIndex = this->mapToSource(index);
66-
return sourceIndex ? this->sourceModel()->data(*sourceIndex, role) : QVariant();
66+
return sourceIndex ? this->sourceModel()->data(*sourceIndex, role) : QVariant{};
6767
}
6868

6969
Qt::ItemFlags ProxyModel::flags(const QModelIndex& index) const
7070
{
7171
const std::optional<QModelIndex> sourceIndex = this->mapToSource(index);
72-
return sourceIndex ? this->sourceModel()->flags(*sourceIndex) : Qt::ItemFlags();
72+
return sourceIndex ? this->sourceModel()->flags(*sourceIndex) : Qt::ItemFlags{};
7373
}
7474

7575
bool ProxyModel::hasChildren(const QModelIndex& parent) const
@@ -83,7 +83,7 @@ int ProxyModel::rowCount(const QModelIndex& parent) const
8383
if (parent.isValid())
8484
return 0;
8585

86-
const int rows = this->sourceModel()->rowCount(QModelIndex());
86+
const int rows = this->sourceModel()->rowCount({});
8787
return (rows + m_columnCount - 1) / m_columnCount;
8888
}
8989

@@ -109,7 +109,7 @@ QModelIndex ProxyModel::index(int row, int column, const QModelIndex&) const
109109
std::optional<QModelIndex> ProxyModel::mapToSource(const QModelIndex& proxyIndex) const
110110
{
111111
if (!proxyIndex.isValid())
112-
return QModelIndex();
112+
return QModelIndex{};
113113

114114
const int sourceRow = proxyIndex.row() * m_columnCount + proxyIndex.column();
115115
if (sourceRow < sourceModel()->rowCount())
@@ -121,15 +121,16 @@ std::optional<QModelIndex> ProxyModel::mapToSource(const QModelIndex& proxyIndex
121121
QModelIndex ProxyModel::mapFromSource(const QModelIndex& sourceIndex) const
122122
{
123123
if (!sourceIndex.isValid())
124-
return QModelIndex();
124+
return QModelIndex{};
125125

126126
const int proxyRow = sourceIndex.row() / m_columnCount;
127127
const int proxyColumn = sourceIndex.row() % m_columnCount;
128128
return this->index(proxyRow, proxyColumn, QModelIndex());
129129
}
130130

131131
void ProxyModel::onDataChanged(
132-
const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles)
132+
const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles
133+
)
133134
{
134135
emit this->dataChanged(this->mapFromSource(topLeft), this->mapFromSource(bottomRight), roles);
135136
}

src/app/grid_helper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ProxyModel : public QAbstractItemModel {
2222
Qt::ItemFlags flags(const QModelIndex& index) const override;
2323
bool hasChildren(const QModelIndex& parent) const override;
2424
QModelIndex index(int row, int column, const QModelIndex&) const override;
25-
QModelIndex parent(const QModelIndex&) const override { return QModelIndex(); }
25+
QModelIndex parent(const QModelIndex&) const override { return {}; }
2626
int rowCount(const QModelIndex& parent) const override;
2727

2828
int columnCount(const QModelIndex& parent) const override;

src/app/list_helper.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ int Model::rowCount(const QModelIndex&) const
5757
QVariant Model::data(const QModelIndex& index, int role) const
5858
{
5959
if (!this->hasStorage())
60-
return QVariant();
60+
return {};
6161

6262
if (!index.isValid() || index.row() >= this->storage()->count())
63-
return QVariant();
63+
return {};
6464

6565
const ModelItem* item = this->storage()->at(index.row());
6666
switch (role) {
@@ -76,7 +76,7 @@ QVariant Model::data(const QModelIndex& index, int role) const
7676
return this->findPixmap(item->imageUrl);
7777
}
7878
default:
79-
return QVariant();
79+
return {};
8080
}
8181
}
8282

@@ -107,8 +107,7 @@ ItemDelegate::ItemDelegate(QObject* parent)
107107
m_itemAnimation.setStartValue(0);
108108
m_itemAnimation.setEndValue(m_itemSize.height());
109109
QObject::connect(
110-
&m_itemAnimation, &QVariantAnimation::valueChanged,
111-
this, &ItemDelegate::drawItem
110+
&m_itemAnimation, &QVariantAnimation::valueChanged, this, &ItemDelegate::drawItem
112111
);
113112
}
114113

@@ -130,7 +129,7 @@ void ItemDelegate::paint(
130129
const bool hovered = option.state & QStyle::State_MouseOver;
131130
const int yShift = itemBottom - 20;
132131
const int yName = itemBottom - 20;
133-
const QRect rectText = QRect(x, y + yName, w, h);
132+
const QRect rectText{x, y + yName, w, h};
134133
const QPixmap pm = Model::itemPixmapAt(index);
135134

136135
QTextOption textOption;
@@ -169,9 +168,10 @@ void ItemDelegate::paint(
169168
painter->setPen(m_textColor);
170169
painter->setFont(fontChange(option.widget).adjustSize(-1));
171170
painter->drawText(
172-
rectPixmap.adjusted(6, m_itemSpacing, -6, -m_itemSpacing),
173-
item->description,
174-
textOption);
171+
rectPixmap.adjusted(6, m_itemSpacing, -6, -m_itemSpacing),
172+
item->description,
173+
textOption
174+
);
175175
}
176176

177177
painter->setPen(m_pixmapColor);

src/app/theme.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616

1717
namespace Mayo {
1818

19-
namespace Internal {
19+
namespace {
2020

21-
static const QIcon& nullQIcon()
21+
const QIcon& nullQIcon()
2222
{
2323
static const QIcon null;
2424
return null;
2525
}
2626

27-
static QString cssFlatComboBox(
27+
QString cssFlatComboBox(
2828
const QString& urlPixDownArrow,
29-
const QString& urlPixDownArrowDisabled)
29+
const QString& urlPixDownArrowDisabled
30+
)
3031
{
3132
const QPalette appPalette = qApp->palette();
3233
const QString css = QString(
@@ -59,14 +60,14 @@ static QString cssFlatComboBox(
5960
return css;
6061
}
6162

62-
static QPixmap invertedPixmap(const QPixmap& pix)
63+
QPixmap invertedPixmap(const QPixmap& pix)
6364
{
6465
QImage img = pix.toImage();
6566
img.invertPixels();
6667
return QPixmap::fromImage(img);
6768
}
6869

69-
static QString iconFileName(Theme::Icon icn)
70+
QString iconFileName(Theme::Icon icn)
7071
{
7172
switch (icn) {
7273
case Theme::Icon::AddFile: return "add-file.svg";
@@ -112,7 +113,7 @@ static QString iconFileName(Theme::Icon icn)
112113
case Theme::Icon::XdeAssembly: return "xde-assembly.svg";
113114
case Theme::Icon::XdeSimpleShape: return "xde-simple-shape.svg";
114115
}
115-
return QString();
116+
return {};
116117
}
117118

118119
class ThemeClassic : public Theme {
@@ -156,7 +157,7 @@ class ThemeClassic : public Theme {
156157
case Theme::Color::MessageIndicator_ErrorBackground:
157158
return QColor(225, 127, 127, 140);
158159
}
159-
return QColor();
160+
return {};
160161
}
161162

162163
const QIcon& icon(Icon icn) const override
@@ -226,7 +227,7 @@ class ThemeDark : public Theme {
226227
case Theme::Color::MessageIndicator_ErrorBackground:
227228
return QColor(225, 127, 127, 140);
228229
}
229-
return QColor();
230+
return {};
230231
}
231232

232233
const QIcon& icon(Icon icn) const override
@@ -332,15 +333,15 @@ class ThemeDark : public Theme {
332333
std::unordered_map<Theme::Icon, QIcon> m_mapIcon;
333334
};
334335

335-
} // namespace Internal
336+
} // namespace
336337

337338
Theme* createTheme(const QString& key)
338339
{
339340
if (key == "classic")
340-
return new Internal::ThemeClassic;
341+
return new ThemeClassic;
341342

342343
if (key == "dark")
343-
return new Internal::ThemeDark;
344+
return new ThemeDark;
344345

345346
return nullptr;
346347
}

0 commit comments

Comments
 (0)