mirror of
https://github.com/tnodir/fort
synced 2024-11-15 05:25:56 +00:00
UI: AppListModel: Minor refactor
This commit is contained in:
parent
fa08577c4f
commit
5ce8cb64b2
@ -86,9 +86,13 @@ QVariant appGroupColor(const AppRow &appRow)
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon appActionIcon(const AppRow &appRow)
|
QIcon appIcon(const AppRow &appRow)
|
||||||
{
|
{
|
||||||
return IconCache::icon(appActionIconPath(appRow));
|
if (appRow.isWildcard) {
|
||||||
|
return IconCache::icon(":/icons/coding.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
return IoC<AppInfoCache>()->appIcon(appRow.appPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon appZonesIcon(const AppRow &appRow)
|
QIcon appZonesIcon(const AppRow &appRow)
|
||||||
@ -109,6 +113,31 @@ QIcon appScheduledIcon(const AppRow &appRow)
|
|||||||
return IconCache::icon(appScheduleIconPath(appRow));
|
return IconCache::icon(appScheduleIconPath(appRow));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QIcon appActionIcon(const AppRow &appRow)
|
||||||
|
{
|
||||||
|
return IconCache::icon(appActionIconPath(appRow));
|
||||||
|
}
|
||||||
|
|
||||||
|
using dataDecorationIcon_func = QIcon (*)(const AppRow &appRow);
|
||||||
|
|
||||||
|
static const dataDecorationIcon_func dataDecorationIcon_funcList[] = {
|
||||||
|
&appIcon,
|
||||||
|
&appZonesIcon,
|
||||||
|
&appRuleIcon,
|
||||||
|
&appScheduledIcon,
|
||||||
|
&appActionIcon,
|
||||||
|
};
|
||||||
|
|
||||||
|
inline QVariant dataDecorationIcon(int column, const AppRow &appRow)
|
||||||
|
{
|
||||||
|
if (column < 0 || column >= std::size(dataDecorationIcon_funcList))
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
const dataDecorationIcon_func func = dataDecorationIcon_funcList[column];
|
||||||
|
|
||||||
|
return func(appRow);
|
||||||
|
}
|
||||||
|
|
||||||
QVariant headerDataDisplayName(int /*role*/)
|
QVariant headerDataDisplayName(int /*role*/)
|
||||||
{
|
{
|
||||||
return AppListModel::tr("Name");
|
return AppListModel::tr("Name");
|
||||||
@ -419,20 +448,7 @@ QVariant AppListModel::dataDecoration(const QModelIndex &index) const
|
|||||||
if (appRow.isNull())
|
if (appRow.isNull())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
switch (column) {
|
return dataDecorationIcon(column, appRow);
|
||||||
case 0:
|
|
||||||
return appIcon(appRow);
|
|
||||||
case 1:
|
|
||||||
return appZonesIcon(appRow);
|
|
||||||
case 2:
|
|
||||||
return appRuleIcon(appRow);
|
|
||||||
case 3:
|
|
||||||
return appScheduledIcon(appRow);
|
|
||||||
case 4:
|
|
||||||
return appActionIcon(appRow);
|
|
||||||
}
|
|
||||||
|
|
||||||
return QVariant();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant AppListModel::dataForeground(const QModelIndex &index) const
|
QVariant AppListModel::dataForeground(const QModelIndex &index) const
|
||||||
@ -463,15 +479,6 @@ QVariant AppListModel::dataTextAlignment(const QModelIndex &index) const
|
|||||||
return QVariant();
|
return QVariant();
|
||||||
}
|
}
|
||||||
|
|
||||||
QIcon AppListModel::appIcon(const AppRow &appRow) const
|
|
||||||
{
|
|
||||||
if (appRow.isWildcard) {
|
|
||||||
return IconCache::icon(":/icons/coding.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
return appInfoCache()->appIcon(appRow.appPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppListModel::updateAppRow(const QString &sql, const QVariantHash &vars, AppRow &appRow) const
|
bool AppListModel::updateAppRow(const QString &sql, const QVariantHash &vars, AppRow &appRow) const
|
||||||
{
|
{
|
||||||
SqliteStmt stmt;
|
SqliteStmt stmt;
|
||||||
@ -583,15 +590,8 @@ QString AppListModel::sqlWhere() const
|
|||||||
|
|
||||||
if (filters() != FilterNone) {
|
if (filters() != FilterNone) {
|
||||||
QStringList list;
|
QStringList list;
|
||||||
|
addSqlFilter(list, "t.is_wildcard", FilterWildcard);
|
||||||
if (filters().testFlag(FilterWildcard)) {
|
addSqlFilter(list, "t.parked", FilterParked);
|
||||||
list << QString("t.is_wildcard = %1")
|
|
||||||
.arg(filterValues().testFlag(FilterWildcard) ? "1" : "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filters().testFlag(FilterParked)) {
|
|
||||||
list << QString("t.parked = %1").arg(filterValues().testFlag(FilterParked) ? "1" : "0");
|
|
||||||
}
|
|
||||||
|
|
||||||
sql += QLatin1String(sql.isEmpty() ? " WHERE " : " AND ") + list.join(" AND ");
|
sql += QLatin1String(sql.isEmpty() ? " WHERE " : " AND ") + list.join(" AND ");
|
||||||
}
|
}
|
||||||
@ -638,3 +638,12 @@ QString AppListModel::sqlOrderColumn() const
|
|||||||
|
|
||||||
return columnsStr + sqlOrderAsc() + ", " + postColumnsStr;
|
return columnsStr + sqlOrderAsc() + ", " + postColumnsStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppListModel::addSqlFilter(QStringList &list, const QString &name, FilterFlag flag) const
|
||||||
|
{
|
||||||
|
if (filters().testFlag(flag)) {
|
||||||
|
const QLatin1String value(filterValues().testFlag(flag) ? "1" : "0");
|
||||||
|
|
||||||
|
list << QString("%1 = %2").arg(name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -71,14 +71,14 @@ protected:
|
|||||||
QString sqlWhereFts() const override;
|
QString sqlWhereFts() const override;
|
||||||
QString sqlOrderColumn() const override;
|
QString sqlOrderColumn() const override;
|
||||||
|
|
||||||
|
void addSqlFilter(QStringList &list, const QString &name, FilterFlag flag) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant dataDisplay(const QModelIndex &index, int role) const;
|
QVariant dataDisplay(const QModelIndex &index, int role) const;
|
||||||
QVariant dataDecoration(const QModelIndex &index) const;
|
QVariant dataDecoration(const QModelIndex &index) const;
|
||||||
QVariant dataForeground(const QModelIndex &index) const;
|
QVariant dataForeground(const QModelIndex &index) const;
|
||||||
QVariant dataTextAlignment(const QModelIndex &index) const;
|
QVariant dataTextAlignment(const QModelIndex &index) const;
|
||||||
|
|
||||||
QIcon appIcon(const AppRow &appRow) const;
|
|
||||||
|
|
||||||
bool updateAppRow(const QString &sql, const QVariantHash &vars, AppRow &appRow) const;
|
bool updateAppRow(const QString &sql, const QVariantHash &vars, AppRow &appRow) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user