mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Fixed db Fixed data base info retrieving in ComicModel.
This commit is contained in:
parent
d6898e9a4e
commit
6de499e566
@ -695,100 +695,47 @@ QString ComicModel::getComicPath(QModelIndex mi)
|
|||||||
|
|
||||||
void ComicModel::setupModelData(QSqlQuery &sqlquery)
|
void ComicModel::setupModelData(QSqlQuery &sqlquery)
|
||||||
{
|
{
|
||||||
ComicItem * currentItem;
|
int numColumns = sqlquery.record().count();
|
||||||
while (sqlquery.next())
|
|
||||||
|
while (sqlquery.next())
|
||||||
{
|
{
|
||||||
QList<QVariant> data;
|
QList<QVariant> data;
|
||||||
QSqlRecord record = sqlquery.record();
|
|
||||||
for(int i=0;i<record.count();i++)
|
|
||||||
data << record.value(i);
|
|
||||||
|
|
||||||
currentItem = new ComicItem(data);
|
for(int i=0;i<numColumns;i++)
|
||||||
bool lessThan = false;
|
data << sqlquery.value(i);
|
||||||
if(_data.isEmpty())
|
|
||||||
_data.append(currentItem);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
ComicItem * last = _data.back();
|
|
||||||
QString nameLast = last->data(ComicModel::FileName).toString();
|
|
||||||
QString nameCurrent = currentItem->data(ComicModel::FileName).toString();
|
|
||||||
int numberLast,numberCurrent;
|
|
||||||
int max = (std::numeric_limits<int>::max)();
|
|
||||||
numberLast = numberCurrent = max;
|
|
||||||
|
|
||||||
if(!last->data(ComicModel::Number).isNull())
|
_data.append(new ComicItem(data));
|
||||||
numberLast = last->data(ComicModel::Number).toInt();
|
|
||||||
|
|
||||||
if(!currentItem->data(ComicModel::Number).isNull())
|
|
||||||
numberCurrent = currentItem->data(ComicModel::Number).toInt();
|
|
||||||
|
|
||||||
QList<ComicItem *>::iterator i;
|
|
||||||
i = _data.end();
|
|
||||||
i--;
|
|
||||||
|
|
||||||
if(numberCurrent != max) //sort the current item by issue number
|
|
||||||
{
|
|
||||||
while ((lessThan =numberCurrent < numberLast) && i != _data.begin())
|
|
||||||
{
|
|
||||||
i--;
|
|
||||||
numberLast = max;
|
|
||||||
|
|
||||||
if(!(*i)->data(ComicModel::Number).isNull())
|
|
||||||
numberLast = (*i)->data(ComicModel::Number).toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(lessThan)
|
|
||||||
_data.insert(i,currentItem);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(numberCurrent == numberLast)
|
|
||||||
if(currentItem->data(ComicModel::IsBis).toBool())
|
|
||||||
{
|
|
||||||
_data.insert(++i,currentItem);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
_data.insert(i,currentItem);
|
|
||||||
else
|
|
||||||
_data.insert(++i,currentItem);
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
else //sort the current item by title
|
|
||||||
{
|
|
||||||
while ((lessThan = naturalSortLessThanCI(nameCurrent,nameLast)) && i != _data.begin() && numberLast == max)
|
|
||||||
{
|
|
||||||
i--;
|
|
||||||
nameLast = (*i)->data(ComicModel::FileName).toString();
|
|
||||||
numberLast = max;
|
|
||||||
|
|
||||||
if(!(*i)->data(ComicModel::Number).isNull())
|
|
||||||
numberLast = (*i)->data(ComicModel::Number).toInt();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(numberLast != max)
|
|
||||||
_data.insert(++i,currentItem);
|
|
||||||
else
|
|
||||||
if(lessThan)
|
|
||||||
_data.insert(i,currentItem);
|
|
||||||
else
|
|
||||||
_data.insert(++i,currentItem);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::sort(_data.begin(), _data.end(), [](const ComicItem *c1, const ComicItem *c2) {
|
||||||
|
if(c1->data(ComicModel::Number).isNull() && c2->data(ComicModel::Number).isNull())
|
||||||
|
{
|
||||||
|
return naturalSortLessThanCI(c1->data(ComicModel::FileName).toString(), c2->data(ComicModel::FileName).toString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (c1->data(ComicModel::Number).isNull() == false && c2->data(ComicModel::Number).isNull() == false)
|
||||||
|
{
|
||||||
|
return c1->data(ComicModel::Number).toInt() < c2->data(ComicModel::Number).toInt();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return c2->data(ComicModel::Number).isNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//comics are sorted by "ordering", the sorting is done in the sql query
|
//comics are sorted by "ordering", the sorting is done in the sql query
|
||||||
void ComicModel::setupModelDataForList(QSqlQuery &sqlquery)
|
void ComicModel::setupModelDataForList(QSqlQuery &sqlquery)
|
||||||
{
|
{
|
||||||
|
int numColumns = sqlquery.record().count();
|
||||||
|
|
||||||
while (sqlquery.next())
|
while (sqlquery.next())
|
||||||
{
|
{
|
||||||
QList<QVariant> data;
|
QList<QVariant> data;
|
||||||
QSqlRecord record = sqlquery.record();
|
for(int i=0;i<numColumns;i++)
|
||||||
for(int i=0;i<record.count();i++)
|
data << sqlquery.value(i);
|
||||||
data << record.value(i);
|
|
||||||
|
|
||||||
_data.append(new ComicItem(data));
|
_data.append(new ComicItem(data));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user