79 lines
2.0 KiB
C++
79 lines
2.0 KiB
C++
/*
|
|
* ModelRailroadTimetablePlanner
|
|
* Copyright 2016-2023, Filippo Gentile
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*
|
|
*/
|
|
|
|
#include "rslistondemandmodel.h"
|
|
|
|
#include "utils/delegates/sql/pageditemmodelhelper_impl.h"
|
|
|
|
#include <QFont>
|
|
|
|
RSListOnDemandModel::RSListOnDemandModel(sqlite3pp::database &db, QObject *parent) :
|
|
BaseClass(100, db, parent)
|
|
{
|
|
sortColumn = Name;
|
|
}
|
|
|
|
QVariant RSListOnDemandModel::data(const QModelIndex &idx, int role) const
|
|
{
|
|
const int row = idx.row();
|
|
if (!idx.isValid() || row >= curItemCount || idx.column() >= NCols)
|
|
return QVariant();
|
|
|
|
// qDebug() << "Data:" << idx.row();
|
|
|
|
if (row < cacheFirstRow || row >= cacheFirstRow + cache.size())
|
|
{
|
|
// Fetch above or below current cache
|
|
const_cast<RSListOnDemandModel *>(this)->fetchRow(row);
|
|
|
|
// Temporarily return null
|
|
return role == Qt::DisplayRole ? QVariant("...") : QVariant();
|
|
}
|
|
|
|
const RSItem &item = cache.at(row - cacheFirstRow);
|
|
|
|
switch (role)
|
|
{
|
|
case Qt::DisplayRole:
|
|
case Qt::EditRole:
|
|
{
|
|
switch (idx.column())
|
|
{
|
|
case Name:
|
|
return item.name;
|
|
}
|
|
|
|
break;
|
|
}
|
|
case Qt::FontRole:
|
|
{
|
|
if (item.type == RsType::Engine)
|
|
{
|
|
// Engines in bold
|
|
QFont f;
|
|
f.setBold(true);
|
|
return f;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
return QVariant();
|
|
}
|