Commit ff5b43e9 authored by Camilo higuita's avatar Camilo higuita
Browse files

more work on tagging modeling and controls

parent 7f291d48
......@@ -111,7 +111,7 @@ Maui.Popup
clip: true
headBarExit: false
colorScheme.backgroundColor : control.colorScheme.backgroundColor
footBar.visible: footBar.count > 1
footBar.visible: defaultButtons || footBar.count > 1
footBar.colorScheme.backgroundColor: colorScheme.backgroundColor
footBar.margins: space.big
footBar.rightContent: Row
......
......@@ -23,16 +23,19 @@ import QtQuick.Layouts 1.3
import org.kde.mauikit 1.0 as Maui
import "private"
Item
{
id: control
clip : true
width: parent.width
height: rowHeight
property alias tagsList : tagsList
property alias listView : tagsList
property alias count : tagsList.count
property color bgColor: "transparent"
property bool editMode : false
property bool allowEditMode : false
property alias list : tagsList.list
signal addClicked()
signal tagRemovedClicked(int index)
......@@ -44,8 +47,8 @@ Item
anchors.fill: parent
color: bgColor
z: -1
}
}
RowLayout
{
anchors.fill: parent
......@@ -80,7 +83,7 @@ Item
showDeleteIcon: allowEditMode
onTagRemoved: tagRemovedClicked(index)
onTagClicked: control.tagClicked(tagsList.model.get(index).tag)
MouseArea
{
anchors.fill: parent
......@@ -138,14 +141,14 @@ Item
function clear()
{
tagsList.model.clear()
// tagsList.model.clear()
}
function goEditMode()
{
var currentTags = []
for(var i = 0 ; i < tagsList.count; i++)
currentTags.push(tagsList.model.get(i).tag)
currentTags.push(list.get(i).tag)
editTagsEntry.text = currentTags.join(", ")
editMode = true
......@@ -157,20 +160,7 @@ Item
tagsEdited(getTags())
editMode = false
}
function populate(tags)
{
clear()
for(var i in tags)
append(tags[i])
}
function append(tag)
{
tagsList.model.append(tag)
}
function getTags()
{
var tags = []
......
......@@ -2,6 +2,9 @@ import QtQuick 2.0
import QtQuick.Controls 2.2
import "."
import TagsList 1.0
import TagsModel 1.0
ListView
{
id: control
......@@ -12,9 +15,23 @@ ListView
signal tagClicked(int index)
boundsBehavior: isMobile ? Flickable.DragOverBounds : Flickable.StopAtBounds
property alias list : _tagsList
property bool showPlaceHolder: true
property bool showDeleteIcon: true
TagsModel
{
id: _tagsModel
list: _tagsList
}
TagsList
{
id: _tagsList
}
model: _tagsModel
Label
{
height: parent.height
......@@ -27,8 +44,6 @@ ListView
font.pointSize: fontSizes.default
}
model: ListModel{}
delegate: TagDelegate
{
id: delegate
......
......@@ -233,19 +233,29 @@ QVariantList Tagging::getAbstractTags(const QString &key, const QString &lot, co
return res;
}
bool Tagging::removeAbstractTag(const QString& key, const QString& lot, const QString &tag)
{
TAG::DB data {{TAG::KEYS::KEY, key}, {TAG::KEYS::LOT, lot}, {TAG::KEYS::TAG, tag}};
return this->remove(TAG::TABLEMAP[TAG::TABLE::TAGS_ABSTRACT], data);
}
bool Tagging::removeUrlTags(const QString &url)
{
for(auto map : this->getUrlTags(url))
{
auto tag = map.toMap().value(TAG::KEYMAP[TAG::KEYS::TAG]).toString();
TAG::DB data {{TAG::KEYS::URL, url}, {TAG::KEYS::TAG, tag}};
this->remove(TAG::TABLEMAP[TAG::TABLE::TAGS_URLS], data);
this->removeUrlTag(url, tag);
}
return true;
}
bool Tagging::removeUrlTag(const QString& url, const QString& tag)
{
TAG::DB data {{TAG::KEYS::URL, url}, {TAG::KEYS::TAG, tag}};
return this->remove(TAG::TABLEMAP[TAG::TABLE::TAGS_URLS], data);
}
QString Tagging::mac()
{
QNetworkInterface mac;
......
......@@ -62,8 +62,11 @@ public:
Q_INVOKABLE QVariantList getAbstractTags(const QString &key, const QString &lot, const bool &strict = true);
/* DELETES */
Q_INVOKABLE bool removeUrlTags(const QString &url);
Q_INVOKABLE bool removeAbstractTag(const QString &key, const QString &lot, const QString &tag);
Q_INVOKABLE bool removeUrlTags(const QString &url);
Q_INVOKABLE bool removeUrlTag(const QString &url, const QString &tag);
/*STATIC METHODS*/
static QString mac();
......
......@@ -30,10 +30,21 @@ void TagsList::setList()
if(this->abstract)
{
this->list = this->toModel(this->tag->getAbstractsTags(this->strict));
if(this->lot.isEmpty() || this->key.isEmpty())
this->list = this->toModel(this->tag->getAbstractsTags(this->strict));
else
this->list = this->toModel(this->tag->getAbstractTags(this->key, this->lot, this->strict));
}else
{
this->list = this->toModel(this->tag->getAllTags(this->strict));
if(this->urls.isEmpty())
this->list = this->toModel(this->tag->getAllTags(this->strict));
else
{
this->list.clear();
for(auto url : this->urls)
this->list << this->toModel(this->tag->getUrlTags(url, this->strict));
}
}
qDebug()<< "TAGGING LIST"<< list;
......@@ -60,26 +71,62 @@ void TagsList::refresh()
this->setList();
}
void TagsList::insert(const QString &tag)
bool TagsList::insert(const QString &tag)
{
qDebug() << "trying to insert tag "<< tag;
if(this->tag->tag(tag))
auto _tag = tag.trimmed();
if(this->tag->tag(_tag))
{
emit this->preItemAppended();
qDebug()<< "tag inserted";
this->list << TAG::DB {{TAG::KEYS::TAG, tag}};
this->list << TAG::DB {{TAG::KEYS::TAG, _tag}};
emit this->postItemAppended();
return true;
}
return false;
}
void TagsList::remove(const int& index)
bool TagsList::remove(const int& index)
{
if(index >= this->list.size() || index < 0)
return false;
emit this->preItemRemoved(index);
this->list.removeAt(index);
emit this->postItemRemoved();
return true;
}
void TagsList::removeFrom(const int& index, const QString& key, const QString& lot)
{
if(index >= this->list.size() || index < 0)
return;
//todo
emit this->preItemRemoved(index);
auto item = this->list.takeAt(index);
this->tag->removeAbstractTag(key, lot, item[TAG::KEYS::TAG]);
emit this->postItemRemoved();
}
void TagsList::removeFrom(const int& index, const QString& url)
{
if(index >= this->list.size() || index < 0)
return;
emit this->preItemRemoved(index);
auto item = this->list.takeAt(index);
this->tag->removeUrlTag(url, item[TAG::KEYS::TAG]);
emit this->postItemRemoved();
}
void TagsList::erase(const int& index)
{
}
TAG::DB_LIST TagsList::items() const
......@@ -161,3 +208,18 @@ void TagsList::setUrls(const QStringList& value)
this->setList();
emit this->urlsChanged();
}
void TagsList::append(const QString &tag)
{
qDebug() << "trying to append tag "<< tag;
if(!this->insert(tag))
{
emit this->preItemAppended();
this->list << TAG::DB {{TAG::KEYS::TAG, tag}};
emit this->postItemAppended();
qDebug() << "done appending tag "<< tag;
}
}
......@@ -67,8 +67,12 @@ signals:
public slots:
QVariantMap get(const int &index) const;
void insert(const QString &tag);
void remove(const int &index);
void append(const QString &tag);
bool insert(const QString &tag);
bool remove(const int &index);
void removeFrom(const int &index, const QString &url);
void removeFrom(const int &index, const QString &key, const QString &lot);
void erase(const int &index);
void refresh();
};
......
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