Commit 7e2658ea authored by Camilo higuita's avatar Camilo higuita

start reusing the mauikit fmh modeling instead of custom one

parent 64e01418
......@@ -52,7 +52,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "./src/models/basemodel.h"
#include "./src/models/baselist.h"
#include "./src/models/gallery/gallery.h"
#include "./src/models/albums/albums.h"
//#include "./src/models/albums/albums.h"
#include "./src/models/folders/foldermodel.h"
#include "./src/models/folders/folders.h"
......@@ -135,13 +135,13 @@ int main(int argc, char *argv[])
context->setContextProperty("tag", dba->tag);
context->setContextProperty("dba", dba);
qmlRegisterUncreatableMetaObject(PIX::staticMetaObject, "PIX", 1, 0, "KEY", "Error");
// qmlRegisterUncreatableMetaObject(PIX::staticMetaObject, "PIX", 1, 0, "KEY", "Error");
qmlRegisterUncreatableType<BaseList>("BaseList", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));
qmlRegisterType<BaseModel>("PixModel", 1, 0, "PixModel");
qmlRegisterType<Gallery>("GalleryList", 1, 0, "GalleryList");
qmlRegisterType<Albums>("AlbumsList", 1, 0, "AlbumsList");
// qmlRegisterType<Albums>("AlbumsList", 1, 0, "AlbumsList");
qmlRegisterType<FolderModel>("FolderModel", 1, 0, "FolderModel");
qmlRegisterType<Folders>("FoldersList", 1, 0, "FoldersList");
......
......@@ -24,12 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QStringList>
#include <QSqlQuery>
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include <MauiKit/fmh.h>
#else
#include "fmh.h"
#endif
DB::DB(QObject *parent) : QObject(parent)
{
this->init();
......@@ -180,7 +174,7 @@ bool DB::insert(const QString &tableName, const QVariantMap &insertData)
return query.exec();
}
bool DB::update(const QString &tableName, const PIX::DB &updateData, const QVariantMap &where)
bool DB::update(const QString &tableName, const FMH::MODEL &updateData, const QVariantMap &where)
{
if (tableName.isEmpty())
{
......@@ -194,7 +188,7 @@ bool DB::update(const QString &tableName, const PIX::DB &updateData, const QVari
QStringList set;
for (auto key : updateData.keys())
set.append(PIX::KEYMAP[key]+" = '"+updateData[key]+"'");
set.append(FMH::MODEL_NAME[key]+" = '"+updateData[key]+"'");
QStringList condition;
for (auto key : where.keys())
......@@ -213,7 +207,7 @@ bool DB::update(const QString &table, const QString &column, const QVariant &new
return query.exec();
}
bool DB::remove(const QString &tableName, const PIX::DB &removeData)
bool DB::remove(const QString &tableName, const FMH::MODEL &removeData)
{
if (tableName.isEmpty())
{
......@@ -230,7 +224,7 @@ bool DB::remove(const QString &tableName, const PIX::DB &removeData)
auto i = 0;
for (auto key : removeData.keys())
{
strValues.append(QString("%1 = \"%2\"").arg(PIX::KEYMAP[key], removeData[key]));
strValues.append(QString("%1 = \"%2\"").arg(FMH::MODEL_NAME[key], removeData[key]));
i++;
if(removeData.keys().size() > 1 && i<removeData.keys().size())
......@@ -254,11 +248,11 @@ QVariantList DB::get(const QString &queryTxt)
while(query.next())
{
QVariantMap data;
for(auto key : PIX::KEYMAP.keys())
if(query.record().indexOf(PIX::KEYMAP[key])>-1)
data[PIX::KEYMAP[key]] = query.value(PIX::KEYMAP[key]).toString();
for(auto key : FMH::MODEL_NAME.keys())
if(query.record().indexOf(FMH::MODEL_NAME[key])>-1)
data[FMH::MODEL_NAME[key]] = query.value(FMH::MODEL_NAME[key]).toString();
auto url = data[PIX::KEYMAP[PIX::KEY::URL]].toString();
auto url = data[FMH::MODEL_NAME[FMH::MODEL_KEY::URL]].toString();
// if(!url.isEmpty())
// {
......
......@@ -36,7 +36,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QVariantMap>
#include "../utils/pic.h"
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include <MauiKit/fmh.h>
#else
#include "fmh.h"
#endif
class DB : public QObject
{
......@@ -52,9 +56,9 @@ public:
QSqlQuery getQuery(const QString &queryTxt);
bool insert(const QString &tableName, const QVariantMap &insertData);
bool update(const QString &tableName, const PIX::DB &updateData, const QVariantMap &where);
bool update(const QString &tableName, const FMH::MODEL &updateData, const QVariantMap &where);
bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id);
bool remove(const QString &tableName, const PIX::DB &removeData);
bool remove(const QString &tableName, const FMH::MODEL &removeData);
QVariantList get(const QString &queryTxt);
......
......@@ -62,58 +62,58 @@ bool DBActions::execQuery(const QString &queryTxt)
return query.exec();
}
bool DBActions::insertPic(const PIX::DB &img)
bool DBActions::insertPic(const FMH::MODEL &img)
{
auto url = img[PIX::KEY::URL];
auto title = img[PIX::KEY::TITLE];
auto rate = img[PIX::KEY::RATE];
auto fav = img[PIX::KEY::FAV];
auto color = img[PIX::KEY::COLOR];
auto addDate = img[PIX::KEY::ADD_DATE];
auto sourceUrl = img[PIX::KEY::SOURCES_URL];
auto picDate = img[PIX::KEY::PIC_DATE];
auto place = img[PIX::KEY::PLACE];
auto format = img[PIX::KEY::FORMAT];
auto url = img[FMH::MODEL_KEY::URL];
auto title = img[FMH::MODEL_KEY::TITLE];
auto rate = img[FMH::MODEL_KEY::RATE];
auto fav = img[FMH::MODEL_KEY::FAV];
auto color = img[FMH::MODEL_KEY::COLOR];
auto addDate = img[FMH::MODEL_KEY::ADDDATE];
auto sourceUrl = img[FMH::MODEL_KEY::SOURCE];
auto picDate = img[FMH::MODEL_KEY::DATE];
auto place = img[FMH::MODEL_KEY::PLACE];
auto format = img[FMH::MODEL_KEY::FORMAT];
qDebug()<< "writting to db: "<<title<<url;
/* first needs to insert album and artist*/
QVariantMap sourceMap {{PIX::KEYMAP[PIX::KEY::URL],sourceUrl}};
QVariantMap sourceMap {{FMH::MODEL_NAME[FMH::MODEL_KEY::URL], sourceUrl}};
this->insert(PIX::TABLEMAP[PIX::TABLE::SOURCES], sourceMap);
QVariantMap imgMap {{PIX::KEYMAP[PIX::KEY::URL], url},
{PIX::KEYMAP[PIX::KEY::SOURCES_URL], sourceUrl},
{PIX::KEYMAP[PIX::KEY::TITLE], title},
{PIX::KEYMAP[PIX::KEY::RATE], rate},
{PIX::KEYMAP[PIX::KEY::FAV], fav},
{PIX::KEYMAP[PIX::KEY::COLOR], color},
{PIX::KEYMAP[PIX::KEY::FORMAT], format},
{PIX::KEYMAP[PIX::KEY::PIC_DATE], picDate},
{PIX::KEYMAP[PIX::KEY::PLACE], place},
{PIX::KEYMAP[PIX::KEY::ADD_DATE], QDateTime::currentDateTime()}};
QVariantMap imgMap {{FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url},
{FMH::MODEL_NAME[FMH::MODEL_KEY::SOURCE], sourceUrl},
{FMH::MODEL_NAME[FMH::MODEL_KEY::TITLE], title},
{FMH::MODEL_NAME[FMH::MODEL_KEY::RATE], rate},
{FMH::MODEL_NAME[FMH::MODEL_KEY::FAV], fav},
{FMH::MODEL_NAME[FMH::MODEL_KEY::COLOR], color},
{FMH::MODEL_NAME[FMH::MODEL_KEY::FORMAT], format},
{FMH::MODEL_NAME[FMH::MODEL_KEY::DATE], picDate},
{FMH::MODEL_NAME[FMH::MODEL_KEY::PLACE], place},
{FMH::MODEL_NAME[FMH::MODEL_KEY::ADDDATE], QDateTime::currentDateTime()}};
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES], imgMap);
}
bool DBActions::addPic(const QString &url)
{
if(!this->checkExistance(PIX::TABLEMAP[PIX::TABLE::IMAGES], PIX::KEYMAP[PIX::KEY::URL], url))
if(!this->checkExistance(PIX::TABLEMAP[PIX::TABLE::IMAGES], FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url))
{
QFileInfo info(url);
auto title = info.baseName();
auto format = info.suffix();
auto sourceUrl = info.dir().path();
PIX::DB picMap =
FMH::MODEL picMap =
{
{PIX::KEY::URL, url},
{PIX::KEY::TITLE, title},
{PIX::KEY::FAV, "0"},
{PIX::KEY::RATE, "0"},
{PIX::KEY::COLOR, ""},
{PIX::KEY::SOURCES_URL, sourceUrl},
{PIX::KEY::PIC_DATE, info.birthTime().toString()},
{PIX::KEY::FORMAT, format}
{FMH::MODEL_KEY::URL, url},
{FMH::MODEL_KEY::TITLE, title},
{FMH::MODEL_KEY::FAV, "0"},
{FMH::MODEL_KEY::RATE, "0"},
{FMH::MODEL_KEY::COLOR, ""},
{FMH::MODEL_KEY::SOURCE, sourceUrl},
{FMH::MODEL_KEY::DATE, info.birthTime().toString()},
{FMH::MODEL_KEY::FORMAT, format}
};
return this->insertPic(picMap);
......@@ -159,8 +159,8 @@ bool DBActions::favPic(const QString &url, const bool &fav )
if(!this->addPic(url))
return false;
PIX::DB favedPic = {{PIX::KEY::FAV, fav ? "1" : "0"}};
return this->update(PIX::TABLEMAP[PIX::TABLE::IMAGES], favedPic, QVariantMap({{PIX::KEYMAP[PIX::KEY::URL], url}}) );
FMH::MODEL favedPic = {{FMH::MODEL_KEY::FAV, fav ? "1" : "0"}};
return this->update(PIX::TABLEMAP[PIX::TABLE::IMAGES], favedPic, QVariantMap({{FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url}}) );
}
bool DBActions::isFav(const QString &url)
......@@ -169,7 +169,7 @@ bool DBActions::isFav(const QString &url)
if (data.isEmpty()) return false;
return data.first()[PIX::KEY::FAV] == "1" ? true : false;
return data.first()[FMH::MODEL_KEY::FAV] == "1" ? true : false;
}
bool DBActions::addTag(const QString &tag)
......@@ -187,18 +187,18 @@ bool DBActions::albumTag(const QString &tag, const QString &album)
{
this->addTag(tag);
return this->tag->tagAbstract(tag, PIX::KEYMAP[PIX::KEY::ALBUM], album);
return this->tag->tagAbstract(tag, FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM], album);
}
bool DBActions::removePicTag(const QString &tag, const QString &url)
{
PIX::DB tagMap {{PIX::KEY::URL, url}, {PIX::KEY::TAG, tag}};
FMH::MODEL tagMap {{FMH::MODEL_KEY::URL, url}, {FMH::MODEL_KEY::TAG, tag}};
return this->remove(PIX::TABLEMAP[PIX::TABLE::IMAGES_TAGS], tagMap);
}
bool DBActions::removeAlbumTag(const QString &tag, const QString &album)
{
PIX::DB tagMap {{PIX::KEY::TAG, tag}, {PIX::KEY::ALBUM, album}};
FMH::MODEL tagMap {{FMH::MODEL_KEY::TAG, tag}, {FMH::MODEL_KEY::ALBUM, album}};
return this->remove(PIX::TABLEMAP[PIX::TABLE::ALBUMS_TAGS], tagMap);
}
......@@ -211,8 +211,8 @@ bool DBActions::addAlbum(const QString &album)
{
QVariantMap albumMap
{
{PIX::KEYMAP[PIX::KEY::ALBUM], album},
{PIX::KEYMAP[PIX::KEY::ADD_DATE], QDateTime::currentDateTime()}
{FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM], album},
{FMH::MODEL_NAME[FMH::MODEL_KEY::DATE], QDateTime::currentDateTime()}
};
if(this->insert(PIX::TABLEMAP[PIX::TABLE::ALBUMS], albumMap))
......@@ -230,9 +230,9 @@ bool DBActions::picAlbum(const QString &album, const QString &url)
this->addAlbum(album);
QVariantMap albumPic
{
{PIX::KEYMAP[PIX::KEY::URL], url},
{PIX::KEYMAP[PIX::KEY::ALBUM], album},
{PIX::KEYMAP[PIX::KEY::ADD_DATE], QDateTime::currentDateTime()}
{FMH::MODEL_NAME[FMH::MODEL_KEY::URL], url},
{FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM], album},
{FMH::MODEL_NAME[FMH::MODEL_KEY::DATE], QDateTime::currentDateTime()}
};
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES_ALBUMS], albumPic);
}
......@@ -253,14 +253,14 @@ FMH::MODEL_LIST DBActions::getFolders(const QString &query)
/*Data model keys for to be used on MauiKit Icondelegate component */
for(auto i : data)
res << FMH::getFileInfoModel(i[PIX::KEY::URL]);
res << FMH::getFileInfoModel(i[FMH::MODEL_KEY::URL]);
return res;
}
PIX::DB_LIST DBActions::getDBData(const QString &queryTxt)
FMH::MODEL_LIST DBActions::getDBData(const QString &queryTxt)
{
PIX::DB_LIST mapList;
FMH::MODEL_LIST mapList;
auto query = this->getQuery(queryTxt);
......@@ -268,18 +268,18 @@ PIX::DB_LIST DBActions::getDBData(const QString &queryTxt)
{
while(query.next())
{
PIX::DB data;
for(auto key : PIX::KEYMAP.keys())
if(query.record().indexOf(PIX::KEYMAP[key])>-1)
data.insert(key, query.value(PIX::KEYMAP[key]).toString());
FMH::MODEL data;
for(auto key : FMH::MODEL_NAME.keys())
if(query.record().indexOf(FMH::MODEL_NAME[key]) > -1)
data.insert(key, query.value(FMH::MODEL_NAME[key]).toString());
const auto url = data[PIX::KEY::URL];
const auto url = data[FMH::MODEL_KEY::URL];
if(!url.isEmpty())
{
if(FMH::fileExists(url))
mapList<< data;
else
this->removePic(data[PIX::KEY::URL]);
this->removePic(data[FMH::MODEL_KEY::URL]);
}else mapList<< data;
}
......
......@@ -42,7 +42,7 @@ public:
bool execQuery(const QString &queryTxt);
bool insertPic(const PIX::DB &img);
bool insertPic(const FMH::MODEL &img);
bool addPic(const QString &url);
bool removePic(const QString &url);
......@@ -58,7 +58,7 @@ public:
/* utils */
FMH::MODEL_LIST getFolders(const QString &query);
PIX::DB_LIST getDBData(const QString &queryTxt);
FMH::MODEL_LIST getDBData(const QString &queryTxt);
public slots:
QVariantList get(const QString &queryTxt);
......
......@@ -40,7 +40,6 @@ public:
FileLoader() : QObject()
{
this->dba = DBActions::getInstance();
qRegisterMetaType<PIX::DB>("PIX::DB");
qRegisterMetaType<PIX::TABLE>("PIX::TABLE");
qRegisterMetaType<QMap<PIX::TABLE, bool>>("QMap<PIX::TABLE,bool>");
this->moveToThread(&t);
......
......@@ -6,7 +6,7 @@ url TEXT PRIMARY KEY
CREATE TABLE IF NOT EXISTS ALBUMS (
album TEXT PRIMARY KEY,
addDate DATE
adddate DATE
);
CREATE TABLE IF NOT EXISTS TAGS (
......@@ -15,17 +15,17 @@ tag TEXT PRIMARY KEY
CREATE TABLE IF NOT EXISTS IMAGES (
url TEXT PRIMARY KEY,
sources_url TEXT NOT NULL,
sources TEXT NOT NULL,
title TEXT NOT NULL,
rate INTEGER NOT NULL,
fav INTEGER NOT NULL,
color TEXT,
addDate DATE,
picDate DATE,
adddate DATE,
date DATE,
place DATE,
format TEXT,
FOREIGN KEY(sources_url) REFERENCES SOURCES(url)
FOREIGN KEY(sources) REFERENCES SOURCES(url)
);
CREATE TABLE IF NOT EXISTS IMAGES_TAGS (
......@@ -39,7 +39,7 @@ FOREIGN KEY(url) REFERENCES IMAGES(url)
CREATE TABLE IF NOT EXISTS IMAGES_ALBUMS (
album TEXT NOT NULL,
url TEXT NOT NULL,
addDate DATE,
adddate DATE,
PRIMARY KEY (album, url),
FOREIGN KEY(album) REFERENCES ALBUMS(album),
FOREIGN KEY(url) REFERENCES IMAGES(url)
......
#include "albums.h"
#include "./src/db/dbactions.h"
#ifdef STATIC_MAUIKIT
#include "fmh.h"
#else
#include <MauiKit/fmh.h>
#endif
Albums::Albums(QObject *parent) : BaseList(parent)
{
qDebug()<< "CREATING GALLERY LIST";
......@@ -20,7 +14,7 @@ Albums::Albums(QObject *parent) : BaseList(parent)
connect(this, &Albums::sortByChanged, this, &Albums::setList);
}
void Albums::setSortBy(const uint &sort)
void Albums::setSortBy(const FMH::MODEL_KEY &sort)
{
if(this->sort == sort)
return;
......@@ -29,12 +23,12 @@ void Albums::setSortBy(const uint &sort)
emit this->sortByChanged();
}
uint Albums::getSortBy() const
FMH::MODEL_KEY Albums::getSortBy() const
{
return this->sort;
}
PIX::DB_LIST Albums::items() const
FMH::MODEL_LIST Albums::items() const
{
return this->list;
}
......@@ -57,15 +51,15 @@ QString Albums::getQuery() const
void Albums::sortList()
{
const auto key = static_cast<PIX::KEY>(this->sort);
qSort(this->list.begin(), this->list.end(), [key](const PIX::DB& e1, const PIX::DB& e2) -> bool
const auto key = static_cast<FMH::MODEL_KEY>(this->sort);
qSort(this->list.begin(), this->list.end(), [key](const FMH::MODEL &e1, const FMH::MODEL &e2) -> bool
{
auto role = key;
switch(role)
{
case PIX::KEY::ADD_DATE:
case FMH::MODEL_KEY::ADDDATE:
{
auto currentTime = QDateTime::currentDateTime();
......@@ -78,7 +72,7 @@ void Albums::sortList()
break;
}
case PIX::KEY::ALBUM:
case FMH::MODEL_KEY::ALBUM:
{
const auto str1 = QString(e1[role]).toLower();
const auto str2 = QString(e2[role]).toLower();
......@@ -102,7 +96,7 @@ void Albums::setList()
emit this->preListChanged();
this->list = this->dba->getDBData(this->query);
qDebug()<< "ALBUMS LIST READY"<< list;
// qDebug()<< "ALBUMS LIST READY"<< list;
this->sortList();
emit this->postListChanged();
......@@ -117,18 +111,18 @@ QVariantMap Albums::get(const int &index) const
const auto pic = this->list.at(index);
for(auto key : pic.keys())
res.insert(PIX::KEYMAP[key], pic[key]);
res.insert(FMH::MODEL_NAME[key], pic[key]);
return res;
}
bool Albums::insert(const QVariantMap &pic)
{
const auto album = pic[PIX::KEYMAP[PIX::KEY::ALBUM]].toString();
const auto album = pic[FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM]].toString();
if(this->dba->addAlbum(album))
{
emit this->preItemAppended();
this->list << PIX::DB {{PIX::KEY::ALBUM, album}};
this->list << FMH::MODEL {{FMH::MODEL_KEY::ALBUM, album}};
emit postItemAppended();
return true;
}
......@@ -146,7 +140,7 @@ bool Albums::update(const QVariantMap &data, const int &index)
return false;
}
bool Albums::update(const PIX::DB &pic)
bool Albums::update(const FMH::MODEL &pic)
{
return false;
}
......@@ -158,7 +152,7 @@ bool Albums::remove(const int &index)
void Albums::insertPic(const QString &album, const QString &url)
{
this->insert({{PIX::KEYMAP[PIX::KEY::ALBUM], album}});
this->insert({{FMH::MODEL_NAME[FMH::MODEL_KEY::ALBUM], album}});
this->dba->picAlbum(album, url);
}
......@@ -3,33 +3,32 @@
#include <QObject>
#include "./src/models/baselist.h"
#include "./src/utils/pic.h"
class DBActions;
class Albums : public BaseList
{
Q_OBJECT
Q_PROPERTY(QString query READ getQuery WRITE setQuery NOTIFY queryChanged())
Q_PROPERTY(uint sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
Q_PROPERTY(FMH::MODEL_KEY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
public:
explicit Albums(QObject *parent = nullptr);
PIX::DB_LIST items() const override;
FMH::MODEL_LIST items() const override;
void setQuery(const QString &query);
QString getQuery() const;
void setSortBy(const uint &sort);
uint getSortBy() const;
void setSortBy(const FMH::MODEL_KEY &sort);
FMH::MODEL_KEY getSortBy() const;
private:
DBActions *dba;
PIX::DB_LIST list;
FMH::MODEL_LIST list;
void sortList();
void setList();
QString query;
uint sort = PIX::KEY::ADD_DATE;
FMH::MODEL_KEY sort = FMH::MODEL_KEY::ADDDATE;
protected:
......@@ -38,12 +37,12 @@ signals:
void orderChanged();
void sortByChanged();
public slots:
public slots:
QVariantMap get(const int &index) const override;
bool insert(const QVariantMap &pic) override;
bool update(const int &index, const QVariant &value, const int &role) override; //deprecrated
bool update(const QVariantMap &data, const int &index) override;
bool update(const PIX::DB &pic) override;
bool update(const FMH::MODEL &pic) override;
bool remove(const int &index) override;
void insertPic(const QString &album, const QString &url);
};
......
......@@ -2,7 +2,11 @@
#define BASELIST_H
#include <QObject>
#include "src/utils/pic.h"
#ifdef Q_OS_ANDROID
#include "fmh.h"
#else
#include <MauiKit/fmh.h>
#endif
class BaseList : public QObject
{
......@@ -12,8 +16,7 @@ public:
explicit BaseList(QObject *parent = nullptr);
//* To be overrided *//
virtual PIX::DB_LIST items() const {return PIX::DB_LIST({{}});}
virtual FMH::MODEL_LIST items() const {return FMH::MODEL_LIST({{}});}
protected:
......@@ -48,7 +51,7 @@ public slots:
return false;
}
virtual bool update(const PIX::DB &data)
virtual bool update(const FMH::MODEL &data)
{
Q_UNUSED(data);
return false;
......
......@@ -20,7 +20,7 @@ QVariant BaseModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || !mList)
return QVariant();
return mList->items().at(index.row())[static_cast<PIX::KEY>(role)];
return mList->items().at(index.row())[static_cast<FMH::MODEL_KEY>(role)];
}
bool BaseModel::setData(const QModelIndex &index, const QVariant &value, int role)
......@@ -47,8 +47,8 @@ Qt::ItemFlags BaseModel::flags(const QModelIndex &index) const
QHash<int, QByteArray> BaseModel::roleNames() const
{
QHash<int, QByteArray> names;
for(auto key : PIX::KEYMAP.keys())
names[key] = QString(PIX::KEYMAP[key]).toUtf8();
for(auto key : FMH::MODEL_NAME.keys())
names[key] = QString(FMH::MODEL_NAME[key]).toUtf8();
return names;
}
......
......@@ -34,7 +34,7 @@ uint Gallery::getSortBy() const
return this->sort;
}
PIX::DB_LIST Gallery::items() const
FMH::MODEL_LIST Gallery::items() const
{
return this->list;
}
......@@ -57,23 +57,24 @@ QString Gallery::getQuery() const
void Gallery::sortList()
{
const auto key = static_cast<PIX::KEY>(this->sort);
const auto key = static_cast<FMH::MODEL_KEY>(this->sort);
qDebug()<< "SORTING LIST BY"<< this->sort;
qSort(this->list.begin(), this->list.end(), [key](const PIX::DB& e1, const PIX::DB& e2) -> bool
qSort(this->list.begin(), this->list.end(), [key](const FMH::MODEL &e1, const FMH::MODEL &e2) -> bool
{
auto role = key;
switch(role)
{
case PIX::KEY::SIZE:
case FMH::MODEL_KEY::SIZE:
{
if(e1[role].toDouble() > e2[role].toDouble())
return true;
break;
}
case PIX::KEY::ADD_DATE:
case PIX::KEY::PIC_DATE:
case FMH::MODEL_KEY::DATE:
case FMH::MODEL_KEY::ADDDATE:
case FMH::MODEL_KEY::MODIFIED:
{
auto currentTime = QDateTime::currentDateTime();
......@@ -86,9 +87,9 @@ void Gallery::sortList()
break;
}
case PIX::KEY::TITLE:
case PIX::KEY::PLACE:
case PIX::KEY::FORMAT:
case FMH::MODEL_KEY::TITLE:
case FMH::MODEL_KEY::PLACE:
case FMH::MODEL_KEY::FORMAT:
{
const auto str1 = QString(e1[role]).toLower();
const auto str2 = QString(e2[role]).toLower();
......@@ -126,7 +127,7 @@ QVariantMap Gallery::get(const int &index) const
const auto pic = this->list.at(index);
for(auto key : pic.keys())
res.insert(PIX::KEYMAP[key], pic[key]);
res.insert(FMH::MODEL_NAME[key], pic[key]);
return res;
}
......@@ -141,7 +142,7 @@ bool Gallery::update(const QVariantMap &data, const int &index)
return false;
}
bool Gallery::update(const PIX::DB &pic)
bool Gallery::update(const FMH::MODEL &pic)
{
return false;
}
......@@ -158,7 +159,7 @@ bool Gallery::deleteAt(const int &index)
emit this->preItemRemoved(index);
auto item = this->list.takeAt(index);
this->dba->deletePic(item[PIX::KEY::URL]);
this->dba->deletePic(item[FMH::MODEL_KEY::URL]);
emit this->postItemRemoved();
return true;
......@@ -169,9 +170,9 @@ bool Gallery::fav(const int &index, const bool &value)
if(index >= this->list.size() || index < 0)
return false;
if(this->dba->favPic(this->list[index][PIX::KEY::URL], value))
if(this->dba->favPic(this->list[index][FMH::MODEL_KEY::URL], value))
{
this->list[index].insert(PIX::KEY::FAV, value ? "1" : "0");
this->list[index].insert(FMH::MODEL_KEY::FAV, value ? "1" : "0");
return true;
}
......@@ -183,7 +184,7 @@ void Gallery::append(const QVariantMap &pic)
emit this->preItemAppended();
for(auto key : pic.keys())
this->list << PIX::DB {{PIX::MAPKEY[key], pic[key].toString()}};
this->list << FMH::MODEL {{FMH::MODEL_NAME_KEY[key], pic[key].toString()}};
emit this->postItemAppended();
}
......
......@@ -14,7 +14,7 @@ class Gallery : public BaseList
public:
explicit Gallery(QObject *parent = nullptr);
PIX::DB_LIST items() const override;
FMH::MODEL_LIST items() const override;
void setQuery(const QString &query);
QString getQuery() const;
......@@ -24,14 +24,14 @@ public: