default/special lists and labels are loaded from db

This commit is contained in:
Luis Ángel San Martín 2014-11-10 23:33:11 +01:00
parent 0db866ddf1
commit a66b360456
10 changed files with 92 additions and 38 deletions

View File

@ -228,7 +228,7 @@ bool DataBaseManagement::createV8Tables(QSqlDatabase &database)
//8.0> tables
//LABEL
QSqlQuery queryLabel(database);
queryLabel.prepare("CREATE TABLE label (id INTEGER PRIMARY KEY, name TEXT NOT NULL, color TEXT NOT NULL)");
queryLabel.prepare("CREATE TABLE label (id INTEGER PRIMARY KEY, name TEXT NOT NULL, color TEXT NOT NULL, ordering INTEGER NOT NULL)"); //order depends on the color
success = success && queryLabel.exec();
//COMIC LABEL

View File

@ -26,10 +26,10 @@ SpecialListItem::SpecialListItem(const QList<QVariant> &data)
QIcon SpecialListItem::getIcon() const
{
if(itemData.count()>0)
if(itemData.count()>1)
{
QString name = itemData.at(0).toString();
return QIcon(QString(":/images/lists/%1.png").arg(name).toLower());
QString id = itemData.at(1).toString();
return QIcon(QString(":/images/lists/default_%1.png").arg(id));
}
}

View File

@ -2,6 +2,8 @@
#include "reading_list_item.h"
#include "data_base_management.h"
#include "QsLog.h"
ReadingListModel::ReadingListModel(QObject *parent) :
@ -158,6 +160,34 @@ void ReadingListModel::setupModelData(QString path)
{
beginResetModel();
cleanAll();
_databasePath = path;
QSqlDatabase db = DataBaseManagement::loadDatabase(path);
//setup special lists
specialLists = setupSpecialLists(db);
//separator--------------------------------------------
//setup labels
labels = setupLabels(db);
//separator--------------------------------------------
//setup reading list
setupReadingLists(db);
endResetModel();
}
void ReadingListModel::deleteItem(const QModelIndex &mi)
{
}
void ReadingListModel::cleanAll()
{
if(rootItem != 0)
{
delete rootItem;
@ -172,29 +202,59 @@ void ReadingListModel::setupModelData(QString path)
}
rootItem = 0;
}
//setup special lists
specialLists << new SpecialListItem(QList<QVariant>() /*<< 0*/ << "Favorites");
specialLists << new SpecialListItem(QList<QVariant>() /*<< 1*/ << "Reading");
void ReadingListModel::setupModelData(QSqlQuery &sqlquery, ReadingListItem *parent)
{
//separator
}
//setup labels
labels << new LabelItem(QList<QVariant>() /*<< 0*/ << "Oh Oh" << "red");
labels << new LabelItem(QList<QVariant>() /*<< 1*/ << "lalala" << "orange");
labels << new LabelItem(QList<QVariant>() /*<< 2*/ << "we are not sorry" << "yellow");
labels << new LabelItem(QList<QVariant>() /*<< 3*/ << "there we go" << "green");
labels << new LabelItem(QList<QVariant>() /*<< 4*/ << "oklabunga" << "cyan");
labels << new LabelItem(QList<QVariant>() /*<< 5*/ << "hailer mailer" << "blue");
labels << new LabelItem(QList<QVariant>() /*<< 6*/ << "lol" << "violet");
labels << new LabelItem(QList<QVariant>() /*<< 7*/ << "problems" << "purple");
labels << new LabelItem(QList<QVariant>() /*<< 8*/ << "me gussssta" << "pink");
labels << new LabelItem(QList<QVariant>() /*<< 9*/ << ":D" << "white");
labels << new LabelItem(QList<QVariant>() /*<< 10*/ << "ainsss" << "light");
labels << new LabelItem(QList<QVariant>() /*<< 11*/ << "put a smile on my face" << "dark");
QList<SpecialListItem *> ReadingListModel::setupSpecialLists(QSqlDatabase & db)
{
QList<SpecialListItem *> list;
//separator
QSqlQuery selectQuery("SELECT * FROM default_reading_list ORDER BY id",db);
while(selectQuery.next()) {
QSqlRecord record = selectQuery.record();
list << new SpecialListItem(QList<QVariant>() << record.value("name") << record.value("id"));
}
//Reading after Favorites, Why? Because I want :P
list.insert(1,new SpecialListItem(QList<QVariant>() << "Reading" << 0));
return list;
}
QList<LabelItem *> ReadingListModel::setupLabels(QSqlDatabase & db)
{
QList<LabelItem *> list;
QSqlQuery selectQuery("SELECT * FROM label ORDER BY ordering,name",db); //TODO add some kind of
while(selectQuery.next()) {
QSqlRecord record = selectQuery.record();
list << new LabelItem(QList<QVariant>() << record.value("name") << record.value("color") << record.value("id"));
}
//TEST
// INSERT INTO label (name, color, ordering) VALUES ("Oh Oh", "red", 1);
// INSERT INTO label (name, color, ordering) VALUES ("lalala", "orange", 2);
// INSERT INTO label (name, color, ordering) VALUES ("we are not sorry", "yellow", 3);
// INSERT INTO label (name, color, ordering) VALUES ("there we go", "green", 4);
// INSERT INTO label (name, color, ordering) VALUES ("oklabunga", "cyan", 5);
// INSERT INTO label (name, color, ordering) VALUES ("hailer mailer", "blue", 6);
// INSERT INTO label (name, color, ordering) VALUES ("lol", "violet", 7);
// INSERT INTO label (name, color, ordering) VALUES ("problems", "purple", 8);
// INSERT INTO label (name, color, ordering) VALUES ("me gussssta", "pink", 9);
// INSERT INTO label (name, color, ordering) VALUES (":D", "white", 10);
// INSERT INTO label (name, color, ordering) VALUES ("ainsss", "light", 11);
// INSERT INTO label (name, color, ordering) VALUES ("put a smile on my face", "dark", 12);
return list;
}
void ReadingListModel::setupReadingLists(QSqlDatabase & db)
{
//setup root item
rootItem = new ReadingListItem(QList<QVariant>() /*<< 0*/ << "ROOT" << "atr");
@ -204,18 +264,6 @@ void ReadingListModel::setupModelData(QString path)
rootItem->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "X timeline" << "atr"));
node1->appendChild(new ReadingListItem(QList<QVariant>() /*<< 0*/ << "sublist" << "atr",node1));
endResetModel();
}
void ReadingListModel::deleteItem(const QModelIndex &mi)
{
}
void ReadingListModel::setupModelData(QSqlQuery &sqlquery, ReadingListItem *parent)
{
}

View File

@ -38,7 +38,11 @@ public slots:
void deleteItem(const QModelIndex & mi);
private:
void cleanAll();
void setupModelData(QSqlQuery &sqlquery, ReadingListItem *parent);
QList<SpecialListItem *> setupSpecialLists(QSqlDatabase &db);
QList<LabelItem *> setupLabels(QSqlDatabase &db);
void setupReadingLists(QSqlDatabase &db);
//Special lists
QList<SpecialListItem *> specialLists;

View File

@ -30,7 +30,8 @@
<file>../images/clearSearch.png</file>
<!--reading lists-->
<file alias="images/lists/favorites.png">../images/lists/favorites_osx.png</file>
<file alias="images/lists/default_0.png">../images/lists/default_0_osx.png</file>
<file alias="images/lists/default_1.png">../images/lists/default_1_osx.png</file>
<file alias="images/lists/label_blue.png">../images/lists/label_blue_osx.png</file>
<file alias="images/lists/label_cyan.png">../images/lists/label_cyan_osx.png</file>
<file alias="images/lists/label_dark.png">../images/lists/label_dark_osx.png</file>
@ -44,7 +45,7 @@
<file alias="images/lists/label_white.png">../images/lists/label_white_osx.png</file>
<file alias="images/lists/label_yellow.png">../images/lists/label_yellow_osx.png</file>
<file alias="images/lists/list.png">../images/lists/list_osx.png</file>
<file alias="images/lists/reading.png">../images/lists/reading_osx.png</file>
</qresource>
</RCC>

View File

@ -26,7 +26,8 @@
<file alias="images/clearSearch.png">../images/clearSearchNew.png</file>
<file>../images/addLabelIcon.png</file>
<!--reading lists-->
<file>../images/lists/favorites.png</file>
<file>../images/lists/default_0.png</file>
<file>../images/lists/default_1.png</file>
<file>../images/lists/label_blue.png</file>
<file>../images/lists/label_cyan.png</file>
<file>../images/lists/label_dark.png</file>
@ -40,6 +41,6 @@
<file>../images/lists/label_white.png</file>
<file>../images/lists/label_yellow.png</file>
<file>../images/lists/list.png</file>
<file>../images/lists/reading.png</file>
</qresource>
</RCC>

View File

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

View File

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

View File

Before

Width:  |  Height:  |  Size: 383 B

After

Width:  |  Height:  |  Size: 383 B

View File

Before

Width:  |  Height:  |  Size: 383 B

After

Width:  |  Height:  |  Size: 383 B