Commit ec2cd9e7 authored by camilo higuita's avatar camilo higuita

more work on tags bar and tags dialog #19 close #16

parent 6bc561c7
......@@ -180,7 +180,32 @@ bool DB::update(const QString &table, const QString &column, const QVariant &new
return query.exec();
}
bool DB::remove()
bool DB::remove(const QString &tableName, const PIX::DB &removeData)
{
return false;
if (tableName.isEmpty())
{
qDebug()<<QStringLiteral("Fatal error on removing! The table name is empty!");
return false;
} else if (removeData.isEmpty())
{
qDebug()<<QStringLiteral("Fatal error on insert! The removeData is empty!");
return false;
}
QString strValues;
auto i = 0;
for (auto key : removeData.keys())
{
strValues.append(QString("%1 = \"%2\"").arg(PIX::KEYMAP[key], removeData[key]));
i++;
if(removeData.keys().size() > 1 && i<removeData.keys().size())
strValues.append(" AND ");
}
QString sqlQueryString = "DELETE FROM " + tableName + " WHERE " + strValues;
qDebug()<< sqlQueryString;
return this->getQuery(sqlQueryString).exec();
}
......@@ -34,7 +34,7 @@ class DB : public QObject
void prepareCollectionDB() const;
/* utils*/
bool checkExistance(const QString &tableName, const QString &searchId, const QString &search);
Q_INVOKABLE bool checkExistance(const QString &tableName, const QString &searchId, const QString &search);
protected:
......@@ -43,7 +43,7 @@ class DB : public QObject
bool insert(const QString &tableName, const QVariantMap &insertData);
bool update(const QString &tableName, const PIX::DB &updateData, const QVariantMap &where);
bool update(const QString &table, const QString &column, const QVariant &newValue, const QVariant &op, const QString &id);
bool remove();
bool remove(const QString &tableName, const PIX::DB &removeData);
signals:
......
......@@ -128,17 +128,20 @@ bool DBActions::picTag(const QString &tag, const QString &url)
{PIX::KEYMAP[PIX::KEY::TAG], tag}
};
if(this->insert(PIX::TABLEMAP[PIX::TABLE::TAGS], tagMap))
this->insert(PIX::TABLEMAP[PIX::TABLE::TAGS], tagMap);
QVariantMap taggedPic
{
QVariantMap taggedPic
{
{PIX::KEYMAP[PIX::KEY::URL], url},
{PIX::KEYMAP[PIX::KEY::TAG], tag}
};
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES_TAGS], taggedPic);
}
{PIX::KEYMAP[PIX::KEY::URL], url},
{PIX::KEYMAP[PIX::KEY::TAG], tag}
};
return this->insert(PIX::TABLEMAP[PIX::TABLE::IMAGES_TAGS], taggedPic);
}
return false;
bool DBActions::removePicTag(const QString &tag, const QString &url)
{
PIX::DB tagMap {{PIX::KEY::URL, url}, {PIX::KEY::TAG, tag}};
return this->remove(PIX::TABLEMAP[PIX::TABLE::IMAGES_TAGS], tagMap);
}
QVariantList DBActions::getFolders()
......
......@@ -22,6 +22,7 @@ class DBActions : public DB
Q_INVOKABLE bool isFav(const QString &url);
Q_INVOKABLE bool picTag(const QString &tag, const QString &url);
Q_INVOKABLE bool removePicTag(const QString &tag, const QString &url);
/* utils */
......
CREATE TABLE IF NOT EXISTS SOURCES (
url TEXT PRIMARY KEY
url TEXT PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS ALBUMS (
album TEXT PRIMARY KEY,
addDate DATE
album TEXT PRIMARY KEY,
addDate DATE
);
CREATE TABLE IF NOT EXISTS TAGS (
tag TEXT PRIMARY KEY
tag TEXT PRIMARY KEY
);
CREATE TABLE IF NOT EXISTS IMAGES (
url TEXT PRIMARY KEY,
sources_url TEXT NOT NULL,
title TEXT NOT NULL,
rate INTEGER NOT NULL,
fav INTEGER NOT NULL,
color TEXT,
note TEXT,
addDate DATE,
picDate DATE,
place DATE,
format TEXT,
FOREIGN KEY(sources_url) REFERENCES SOURCES(url)
url TEXT PRIMARY KEY,
sources_url TEXT NOT NULL,
title TEXT NOT NULL,
rate INTEGER NOT NULL,
fav INTEGER NOT NULL,
color TEXT,
note TEXT,
addDate DATE,
picDate DATE,
place DATE,
format TEXT,
FOREIGN KEY(sources_url) REFERENCES SOURCES(url)
);
CREATE TABLE IF NOT EXISTS IMAGES_TAGS (
tag TEXT NOT NULL,
url VARCHAR(150) NOT NULL,
FOREIGN KEY(tag) REFERENCES TAGS(tag),
FOREIGN KEY(url) REFERENCES IMAGES(url)
tag TEXT NOT NULL,
url VARCHAR(150) NOT NULL,
PRIMARY KEY (tag, url),
FOREIGN KEY(tag) REFERENCES TAGS(tag),
FOREIGN KEY(url) REFERENCES IMAGES(url)
);
CREATE TABLE IF NOT EXISTS IMAGES_ALBUMS (
album TEXT NOT NULL,
url TEXT NOT NULL,
addDate DATE,
album TEXT NOT NULL,
url TEXT NOT NULL,
addDate DATE,
FOREIGN KEY(album) REFERENCES ALBUMS(album),
FOREIGN KEY(url) REFERENCES IMAGES(url)
PRIMARY KEY (album, url),
FOREIGN KEY(album) REFERENCES ALBUMS(album),
FOREIGN KEY(url) REFERENCES IMAGES(url)
);
......@@ -40,7 +40,7 @@ ItemDelegate
text: labelTxt.text
elide: Text.ElideRight
color: labelColor
font.pointSize: fontSizes.medium
font.pointSize: fontSizes.default
font.bold: boldLabel
font.weight : boldLabel ? Font.Bold : Font.Normal
......
......@@ -2,19 +2,13 @@ import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import "../../dialogs/Tags"
import "../../../db/Query.js" as Q
ToolBar
Rectangle
{
position: ToolBar.Footer
color: "transparent"
clip : true
TagsDialog
{
id: tagsDialog
onPicTagged: tagsList.model.append({"tag": tag})
}
property alias tagsList : tagsList
RowLayout
{
......@@ -30,7 +24,6 @@ ToolBar
tagsDialog.picUrl = pixViewer.currentPic.url
tagsDialog.open()
}
}
TagList
......@@ -40,19 +33,9 @@ ToolBar
Layout.alignment: Qt.AlignCenter
Layout.fillHeight: true
Layout.fillWidth: true
}
}
function populate(url)
{
console.log("trying ot get tag for ", Q.Query.picTags_.arg(url))
tagsList.model.clear()
var tags = pix.get(Q.Query.picTags_.arg(url))
if(tags.length > 0)
for(var i in tags)
tagsList.model.append(tags[i])
onTagRemoved: if(pix.removePicTag(tagsList.model.get(index).tag, pixViewer.currentPic.url))
tagsList.model.remove(index)
}
}
}
......@@ -10,6 +10,8 @@ ItemDelegate
property int tagWidth: 100
property int tagHeight: 24
signal removeTag(int index)
height: tagHeight
width: tagWidth
......@@ -45,6 +47,7 @@ ItemDelegate
iconName: "window-close"
iconSize: 16
Layout.fillHeight: true
onClicked: removeTag(index)
}
}
......
import QtQuick 2.0
import "../../../db/Query.js" as Q
ListView
{
orientation: ListView.Horizontal
clip: true
signal tagRemoved(int index)
model: ListModel{ ListElement{tag: "test"}}
delegate: TagDelegate
{
id: delegate
Connections
{
target: delegate
onRemoveTag: tagRemoved(index)
}
}
function populate(url)
{
console.log("trying ot get tag for ", Q.Query.picTags_.arg(url))
model.clear()
var tags = pix.get(Q.Query.picTags_.arg(url))
if(tags.length > 0)
for(var i in tags)
model.append(tags[i])
}
}
......@@ -2,6 +2,7 @@ import QtQuick 2.0
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../../../view_models"
import "../../custom/TagBar"
import "../../../db/Query.js" as Q
PixPopup
......@@ -26,30 +27,74 @@ PixPopup
Layout.fillWidth: true
width: parent.width
height: parent.height
onTagClicked:
{
tagListComposer.model.insert(0, {tag: tagsList.model.get(index).tag})
}
}
TextField
{
id: tagText
placeholderText: "New tag..."
Layout.fillWidth: true
placeholderText: "Tags..."
onAccepted:
{
var tags = tagText.text.split(",")
for(var i in tags)
{
var tag = tags[i].trim()
if(!pix.checkExistance("tags", "tag", tag))
{
tagsList.model.insert(0, {tag: tag})
tagListComposer.model.insert(0, {tag: tag})
}
}
clear()
}
}
TagList
{
id: tagListComposer
Layout.fillWidth: true
height: 64
width: parent.width
onTagRemoved:
{
pix.removePicTag(model.get(index).tag, pixViewer.currentPic.url)
tagListComposer.model.remove(index)
}
}
Button
{
text: qsTr("Add")
Layout.alignment: Qt.AlignRight
onClicked: addTag(tagText.text, picUrl)
onClicked: addTags(picUrl)
}
}
function addTag(tag, url)
function addTags(url)
{
if(pix.picTag(tag, url))
picTagged(tag)
close()
var tags = []
for(var i = 0; i < tagListComposer.model.count; i++)
tags.push(tagListComposer.model.get(i))
if(tags.length > 0)
for(i in tags)
{
if(pix.picTag(tags[i].tag, url))
picTagged(tags[i].tag)
}
close()
}
function populate()
......@@ -61,5 +106,6 @@ PixPopup
for(var i in tags)
tagsList.model.append(tags[i])
tagListComposer.populate(picUrl)
}
}
......@@ -5,6 +5,9 @@ import "../../../view_models"
ListView
{
id: tagListRoot
signal tagClicked(int index)
highlight: Rectangle
{
width: tagListRoot.width
......@@ -28,6 +31,7 @@ ListView
onClicked:
{
tagListRoot.currentIndex = index
tagClicked(index)
}
}
}
......
......@@ -5,6 +5,7 @@ import "../../../view_models"
import "../../../widgets/views/Viewer/Viewer.js" as VIEWER
import "../../../widgets/custom/TagBar"
import "../../dialogs/share"
import "../../dialogs/Tags"
PixPage
{
......@@ -37,20 +38,28 @@ PixPage
headerBarLeft: [
PixButton
{
iconName: "document-save-as"
},
PixButton
{
iconName: "draw-text"
}
]
footer: TagBar
footer: ToolBar
{
id: tagBar
position: ToolBar.Footer
TagBar
{
id: tagBar
anchors.fill: parent
}
}
TagsDialog
{
id: tagsDialog
onPicTagged: tagBar.tagsList.model.append({"tag": tag})
}
PixHolder
......@@ -61,16 +70,16 @@ PixPage
visible: Object.keys(currentPic).length === 0
}
// Rectangle
// {
// id: shadow
// width: parent.width
// height: parent.height - headerBar.height
// y: headerBar.height
// color: textColor
// opacity: 0.6
// visible: shareDialog.opened
// }
// Rectangle
// {
// id: shadow
// width: parent.width
// height: parent.height - headerBar.height
// y: headerBar.height
// color: textColor
// opacity: 0.6
// visible: shareDialog.opened
// }
content: Viewer
{
......
......@@ -14,7 +14,8 @@ function view(index)
{
pixViewer.currentPic = pixViewer.picContext[index]
pixViewer.currentPicFav = pix.isFav(pixViewer.currentPic.url)
pixViewer.tagBar.populate(pixViewer.currentPic.url)
pixViewer.tagBar.tagsList.populate(pixViewer.currentPic.url)
root.title = pixViewer.currentPic.title
}
function fullscreen(state)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment