Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 9ff44b00 authored by Camilo higuita's avatar Camilo higuita

move to new models and lists and start testing mauikit syncing

parent f9f27c1d
......@@ -41,15 +41,14 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \
main.cpp \
src/db/db.cpp \
src/db/dbactions.cpp \
src/buho.cpp \
src/documenthandler.cpp \
src/linker.cpp \
src/utils/htmlparser.cpp \
src/models/notes/notesmodel.cpp \
src/models/notes/notes.cpp \
src/models/links/linksmodel.cpp \
src/models/links/links.cpp
src/models/links/links.cpp \
src/models/basemodel.cpp \
src/models/baselist.cpp
RESOURCES += \
qml.qrc \
......@@ -72,16 +71,15 @@ DISTFILES += \
HEADERS += \
src/db/db.h \
src/db/dbactions.h \
src/buho.h \
src/utils/owl.h \
src/documenthandler.h \
src/linker.h \
src/utils/htmlparser.h \
src/models/notes/notesmodel.h \
src/models/notes/notes.h \
src/models/links/linksmodel.h \
src/models/links/links.h
src/models/links/links.h \
src/models/basemodel.h \
src/models/baselist.h
INCLUDEPATH += \
src/utils/ \
......
......@@ -24,8 +24,11 @@
#include "src/documenthandler.h"
#include "src/linker.h"
#include "models/notes/notesmodel.h"
#include "models/links/linksmodel.h"
#include "models/basemodel.h"
#include "models/baselist.h"
#include "models/notes/notes.h"
#include "models/links/links.h"
int main(int argc, char *argv[])
{
......@@ -56,20 +59,20 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine;
auto context = engine.rootContext();
context->setContextProperty("owl", &owl);
Linker linker;
auto tag = owl.getTagging();
context->setContextProperty("linker", &linker);
context->setContextProperty("tag", tag);
qmlRegisterUncreatableMetaObject(OWL::staticMetaObject, "Owl", 1, 0, "KEY", "Error");
qmlRegisterType<DocumentHandler>("org.buho.editor", 1, 0, "DocumentHandler");
qmlRegisterUncreatableType<BaseList>("BaseList", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));
qmlRegisterUncreatableMetaObject(OWL::staticMetaObject, "Owl", 1, 0, "KEY", "Error");
qmlRegisterType<BaseModel>("BuhoModel", 1, 0, "BuhoModel");
qmlRegisterType<Notes>("Notes", 1, 0, "Notes");
qmlRegisterType<Links>("Links", 1, 0, "Links");
qmlRegisterType<NotesModel>("Notes", 1, 0, "NotesModel");
qmlRegisterType<LinksModel>("Links", 1, 0, "LinksModel");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
......
......@@ -26,11 +26,12 @@ Maui.ApplicationWindow
headBarBGColor: accentColor
headBarFGColor: altColorText
accentColor : "#ff9494"
property color headBarTint : Qt.lighter(headBarBGColor, 1.25)
altColorText : "white"/*Qt.darker(accentColor, 2.5)*/
about.appDescription: qsTr("Buho allows you to take quick notes, collect links and take long notes organized by chapters.")
about.appIcon: "qrc:/buho.svg"
property int currentView : views.notes
property var views : ({
notes: 0,
......@@ -39,9 +40,9 @@ Maui.ApplicationWindow
tags: 3,
search: 4
})
property color headBarTint : Qt.lighter(headBarBGColor, 1.25)
headBar.middleContent: [
Maui.ToolButton
{
onClicked: currentView = views.notes
......@@ -91,7 +92,7 @@ Maui.ApplicationWindow
iconName: "list-add"
iconColor: altColorText
barHeight: footBar.height
alignment: Qt.AlignLeft
content: [
Maui.ToolButton
{
......@@ -112,31 +113,38 @@ Maui.ApplicationWindow
]
// /***** COMPONENTS *****/
Connections
Maui.SyncDialog
{
target: owl
onLinkInserted: linksView.append(link)
id: syncDialog
}
mainMenu: [
Maui.MenuItem
{
text: qsTr("Syncing")
onTriggered: syncDialog.open()
}
]
// /***** COMPONENTS *****/
NewNoteDialog
{
id: newNoteDialog
onNoteSaved: notesView.model.insert(note)
onNoteSaved: notesView.list.insert(note)
}
NewNoteDialog
{
id: editNote
onNoteSaved: notesView.cardsView.currentItem.update(note)
onNoteSaved: notesView.list.update(note, notesView.currentIndex)
}
NewLinkDialog
{
id: newLinkDialog
onLinkSaved: linksView.model.insert(link)
onLinkSaved: linksView.list.insert(link)
}
// /***** VIEWS *****/
......@@ -193,7 +201,7 @@ Maui.ApplicationWindow
function setNote(note)
{
var tags = notesView.model.getTags(notesView.currentIndex)
var tags = notesView.list.getTags(notesView.currentIndex)
note.tags = tags
notesView.currentNote = note
editNote.fill(note)
......@@ -201,7 +209,7 @@ Maui.ApplicationWindow
function previewLink(link)
{
var tags = linksView.model.getTags(linksView.currentIndex)
var tags = linksView.list.getTags(linksView.currentIndex)
link.tags = tags
linksView.previewer.show(link)
......
#include "buho.h"
#include "owl.h"
Buho::Buho(QObject *parent) : DBActions(parent)
Buho::Buho(QObject *parent) : QObject(parent)
{
this->setFolders();
}
Tagging *Buho::getTagging()
{
return this->tag;
}
void Buho::setFolders()
{
QDir notes_path(OWL::NotesPath);
......
......@@ -2,20 +2,18 @@
#define BUHO_H
#include <QObject>
#include "db/dbactions.h"
#ifdef STATIC_MAUIKIT
#include "tagging.h"
#else
#include <MauiKit/tagging.h>
#endif
class Buho : public DBActions
class Buho : public QObject
{
Q_OBJECT
public:
explicit Buho(QObject *parent = nullptr);
Tagging* getTagging();
private:
void setFolders();
......
/***
Buho Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#include "dbactions.h"
#include <QJsonDocument>
#include <QVariantMap>
#include <QUuid>
#include <QDateTime>
#include "linker.h"
#include "db.h"
#ifdef STATIC_MAUIKIT
#include "tagging.h"
#else
#include <MauiKit/tagging.h>
#endif
DBActions::DBActions(QObject *parent) : QObject(parent)
{
qDebug() << "Getting collectionDB info from: " << OWL::CollectionDBPath;
qDebug()<< "Starting DBActions";
this->db = DB::getInstance();
}
DBActions::~DBActions() {}
QVariantList DBActions::get(const QString &queryTxt)
{
QVariantList mapList;
auto query = this->db->getQuery(queryTxt);
if(query.exec())
{
while(query.next())
{
QVariantMap data;
for(auto key : OWL::KEYMAP.keys())
if(query.record().indexOf(OWL::KEYMAP[key])>-1)
data[OWL::KEYMAP[key]] = query.value(OWL::KEYMAP[key]).toString();
mapList<< data;
}
}else qDebug()<< query.lastError()<< query.lastQuery();
return mapList;
}
bool DBActions::execQuery(const QString &queryTxt)
{
auto query = this->db->getQuery(queryTxt);
return query.exec();
}
void DBActions::removeAbtractTags(const QString &key, const QString &lot)
{
}
/***
Buho Copyright (C) 2018 Camilo Higuita
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
***/
#ifndef DBACTIONS_H
#define DBACTIONS_H
#include <QObject>
#include "owl.h"
class DB;
class Tagging;
class DBActions : public QObject
{
Q_OBJECT
public:
explicit DBActions(QObject *parent = nullptr);
~DBActions();
Q_INVOKABLE QVariantList get(const QString &queryTxt);
/*main actions*/
protected:
OWL::DB_LIST getDBData(const QString &queryTxt);
bool execQuery(const QString &queryTxt);
Tagging *tag;
DB *db;
void removeAbtractTags(const QString &key, const QString &lot);
signals:
void linkInserted(QVariantMap link);
};
#endif // DBACTIONS_H
......@@ -194,6 +194,22 @@ void DocumentHandler::setBold(bool bold)
emit boldChanged();
}
bool DocumentHandler::uppercase() const
{
QTextCursor cursor = textCursor();
if (cursor.isNull())
return false;
return textCursor().charFormat().fontCapitalization() == QFont::AllUppercase;
}
void DocumentHandler::setUppercase(bool uppercase)
{
QTextCharFormat format;
format.setFontCapitalization(uppercase ? QFont::AllUppercase : QFont::AllLowercase);
mergeFormatOnWordOrSelection(format);
emit uppercaseChanged();
}
bool DocumentHandler::italic() const
{
QTextCursor cursor = textCursor();
......
......@@ -75,6 +75,7 @@ class DocumentHandler : public QObject
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged)
Q_PROPERTY(bool uppercase READ uppercase WRITE setUppercase NOTIFY uppercaseChanged)
Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged)
Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged)
......@@ -111,6 +112,9 @@ public:
bool bold() const;
void setBold(bool bold);
bool uppercase() const;
void setUppercase(bool uppercase);
bool italic() const;
void setItalic(bool italic);
......@@ -139,6 +143,7 @@ Q_SIGNALS:
void alignmentChanged();
void boldChanged();
void uppercaseChanged();
void italicChanged();
void underlineChanged();
......
#include "baselist.h"
BaseList::BaseList(QObject *parent) : QObject(parent)
{
}
#ifndef BASELIST_H
#define BASELIST_H
#include <QObject>
#include "owl.h"
class BaseList : public QObject
{
Q_OBJECT
public:
explicit BaseList(QObject *parent = nullptr);
//* To be overrided *//
virtual OWL::DB_LIST items() const {return OWL::DB_LIST({{}});}
protected:
signals:
void preItemAppended();
void postItemAppended();
void preItemRemoved(int index);
void postItemRemoved();
void updateModel(int index, QVector<int> roles);
void preListChanged();
void postListChanged();
public slots:
virtual QVariantMap get(const int &index) const
{
Q_UNUSED(index);
return QVariantMap();
}
virtual bool update(const int &index, const QVariant &value, const int &role)
{
Q_UNUSED(index);
Q_UNUSED(value);
Q_UNUSED(role);
return false;
}
virtual bool update(const QVariantMap &data, const int &index)
{
Q_UNUSED(index);
Q_UNUSED(data);
return false;
}
virtual bool update(const OWL::DB &data)
{
Q_UNUSED(data);
return false;
}
virtual bool insert(const QVariantMap &map)
{
Q_UNUSED(map);
return false;
}
virtual bool remove(const int &index)
{
Q_UNUSED(index);
return false;
}
virtual void sortBy(const int &role, const QString &order)
{
Q_UNUSED(role);
Q_UNUSED(order);
}
};
#endif // BASELIST_H
#include "linksmodel.h"
#include "links.h"
#include "basemodel.h"
#include "baselist.h"
#include "notes/notes.h"
LinksModel::LinksModel(QObject *parent)
: QAbstractListModel(parent)
{
this->mLinks = new Links(this);
}
BaseModel::BaseModel(QObject *parent)
: QAbstractListModel(parent),
mList(nullptr)
{}
int LinksModel::rowCount(const QModelIndex &parent) const
int BaseModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() || !mLinks)
if (parent.isValid() || !mList)
return 0;
return mLinks->items().size();
return mList->items().size();
}
QVariant LinksModel::data(const QModelIndex &index, int role) const
QVariant BaseModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || !mLinks)
if (!index.isValid() || !mList)
return QVariant();
return mLinks->items().at(index.row())[static_cast<OWL::KEY>(role)];
}
QVariantMap LinksModel::get(const int &index)
{
QVariantMap res;
const auto note = mLinks->items().at(index);
for(auto key : note.keys())
res.insert(OWL::KEYMAP[key], note[key]);
return res;
return mList->items().at(index.row())[static_cast<OWL::KEY>(role)];
}
void LinksModel::sortBy(const int &index, const QString &order)
bool BaseModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
beginResetModel();
mLinks->sortBy(static_cast<OWL::KEY>(index), order);
endResetModel();
}
bool LinksModel::insert(const QVariantMap &link)
{
const int index = mLinks->items().size();
if( this->mLinks->insertLink(link))
{
beginInsertRows(QModelIndex(), index, index);
endInsertRows();
return true;
}
return false;
}
bool LinksModel::remove(const int &index)
{
if(this->mLinks->removeLink(index))
{
beginResetModel();
endResetModel();
return true;
}
return false;
}
QVariantList LinksModel::getTags(const int &index)
{
return this->mLinks->getLinkTags(this->mLinks->items().at(index)[OWL::KEY::LINK]);
}
bool LinksModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!mLinks)
if (!mList)
return false;
if (mLinks->updateLink(index.row(), value, role))
if (mList->update(index.row(), value, role))
{
emit dataChanged(index, index, QVector<int>() << role);
return true;
......@@ -82,7 +37,7 @@ bool LinksModel::setData(const QModelIndex &index, const QVariant &value, int ro
return false;
}
Qt::ItemFlags LinksModel::flags(const QModelIndex &index) const
Qt::ItemFlags BaseModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
......@@ -90,7 +45,7 @@ Qt::ItemFlags LinksModel::flags(const QModelIndex &index) const
return Qt::ItemIsEditable; // FIXME: Implement me!
}
QHash<int, QByteArray> LinksModel::roleNames() const
QHash<int, QByteArray> BaseModel::roleNames() const
{
QHash<int, QByteArray> names;
names[OWL::KEY::TITLE] = QString(OWL::KEYMAP[OWL::KEY::TITLE]).toUtf8();
......@@ -111,42 +66,58 @@ QHash<int, QByteArray> LinksModel::roleNames() const
return names;
}
//Notes *NotesModel::notes() const
//{
// return mLinks;
//}
//void NotesModel::setNotes(Notes *value)
//{
// beginResetModel();
// if(mLinks)
// mLinks->disconnect(this);
// mLinks = value;
//// if(mLinks)
//// {
//// connect(mLinks, &Notes::preItemAppended, this, [=]()
//// {
//// const int index = mLinks->items().size();
//// beginInsertRows(QModelIndex(), index, index);
//// });
//// connect(mLinks, &Notes::postItemAppended, this, [=]()
//// {
//// endInsertRows();
//// });
//// connect(mLinks, &Notes::preItemRemoved, this, [=](int index)
//// {
//// beginInsertRows(QModelIndex(), index, index);
//// });
//// connect(mLinks, &Notes::preItemRemoved, this, [=]()
//// {
//// endRemoveRows();
//// });
//// }
// endResetModel();
//}
BaseList *BaseModel::getList() const
{
return this->mList;
}
void BaseModel::setList(BaseList *value)
{
beginResetModel();
if(mList)
mList->disconnect(this);
mList = value;
if(mList)
{
connect(this->mList, &BaseList::preItemAppended, this, [=]()
{
const int index = mList->items().size();
beginInsertRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::postItemAppended, this, [=]()
{
endInsertRows();
});
connect(this->mList, &BaseList::preItemRemoved, this, [=](int index)
{
beginRemoveRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::postItemRemoved, this, [=]()
{
endRemoveRows();
});
connect(this->mList, &BaseList::updateModel, this, [=](int index, QVector<int> roles)
{
emit this->dataChanged(this->index(index), this->index(index), roles);
});
connect(this->mList, &BaseList::preListChanged, this, [=]()
{
beginResetModel();
});
connect(this->mList, &BaseList::postListChanged, this, [=]()
{
endResetModel();
});
}