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 ...@@ -41,15 +41,14 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += \ SOURCES += \
main.cpp \ main.cpp \
src/db/db.cpp \ src/db/db.cpp \
src/db/dbactions.cpp \
src/buho.cpp \ src/buho.cpp \
src/documenthandler.cpp \ src/documenthandler.cpp \
src/linker.cpp \ src/linker.cpp \
src/utils/htmlparser.cpp \ src/utils/htmlparser.cpp \
src/models/notes/notesmodel.cpp \
src/models/notes/notes.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 += \ RESOURCES += \
qml.qrc \ qml.qrc \
...@@ -72,16 +71,15 @@ DISTFILES += \ ...@@ -72,16 +71,15 @@ DISTFILES += \
HEADERS += \ HEADERS += \
src/db/db.h \ src/db/db.h \
src/db/dbactions.h \
src/buho.h \ src/buho.h \
src/utils/owl.h \ src/utils/owl.h \
src/documenthandler.h \ src/documenthandler.h \
src/linker.h \ src/linker.h \
src/utils/htmlparser.h \ src/utils/htmlparser.h \
src/models/notes/notesmodel.h \
src/models/notes/notes.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 += \ INCLUDEPATH += \
src/utils/ \ src/utils/ \
......
...@@ -24,8 +24,11 @@ ...@@ -24,8 +24,11 @@
#include "src/documenthandler.h" #include "src/documenthandler.h"
#include "src/linker.h" #include "src/linker.h"
#include "models/notes/notesmodel.h" #include "models/basemodel.h"
#include "models/links/linksmodel.h" #include "models/baselist.h"
#include "models/notes/notes.h"
#include "models/links/links.h"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -56,20 +59,20 @@ int main(int argc, char *argv[]) ...@@ -56,20 +59,20 @@ int main(int argc, char *argv[])
QQmlApplicationEngine engine; QQmlApplicationEngine engine;
auto context = engine.rootContext(); auto context = engine.rootContext();
context->setContextProperty("owl", &owl); context->setContextProperty("owl", &owl);
Linker linker; Linker linker;
auto tag = owl.getTagging();
context->setContextProperty("linker", &linker); context->setContextProperty("linker", &linker);
context->setContextProperty("tag", tag);
qmlRegisterUncreatableMetaObject(OWL::staticMetaObject, "Owl", 1, 0, "KEY", "Error");
qmlRegisterType<DocumentHandler>("org.buho.editor", 1, 0, "DocumentHandler"); 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"))); engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty()) if (engine.rootObjects().isEmpty())
......
...@@ -26,11 +26,12 @@ Maui.ApplicationWindow ...@@ -26,11 +26,12 @@ Maui.ApplicationWindow
headBarBGColor: accentColor headBarBGColor: accentColor
headBarFGColor: altColorText headBarFGColor: altColorText
accentColor : "#ff9494" accentColor : "#ff9494"
property color headBarTint : Qt.lighter(headBarBGColor, 1.25)
altColorText : "white"/*Qt.darker(accentColor, 2.5)*/ 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.appDescription: qsTr("Buho allows you to take quick notes, collect links and take long notes organized by chapters.")
about.appIcon: "qrc:/buho.svg" about.appIcon: "qrc:/buho.svg"
property int currentView : views.notes property int currentView : views.notes
property var views : ({ property var views : ({
notes: 0, notes: 0,
...@@ -39,9 +40,9 @@ Maui.ApplicationWindow ...@@ -39,9 +40,9 @@ Maui.ApplicationWindow
tags: 3, tags: 3,
search: 4 search: 4
}) })
property color headBarTint : Qt.lighter(headBarBGColor, 1.25)
headBar.middleContent: [ headBar.middleContent: [
Maui.ToolButton Maui.ToolButton
{ {
onClicked: currentView = views.notes onClicked: currentView = views.notes
...@@ -91,7 +92,7 @@ Maui.ApplicationWindow ...@@ -91,7 +92,7 @@ Maui.ApplicationWindow
iconName: "list-add" iconName: "list-add"
iconColor: altColorText iconColor: altColorText
barHeight: footBar.height barHeight: footBar.height
alignment: Qt.AlignLeft
content: [ content: [
Maui.ToolButton Maui.ToolButton
{ {
...@@ -112,31 +113,38 @@ Maui.ApplicationWindow ...@@ -112,31 +113,38 @@ Maui.ApplicationWindow
] ]
// /***** COMPONENTS *****/ Maui.SyncDialog
Connections
{ {
target: owl id: syncDialog
onLinkInserted: linksView.append(link)
} }
mainMenu: [
Maui.MenuItem
{
text: qsTr("Syncing")
onTriggered: syncDialog.open()
}
]
// /***** COMPONENTS *****/
NewNoteDialog NewNoteDialog
{ {
id: newNoteDialog id: newNoteDialog
onNoteSaved: notesView.model.insert(note) onNoteSaved: notesView.list.insert(note)
} }
NewNoteDialog NewNoteDialog
{ {
id: editNote id: editNote
onNoteSaved: notesView.cardsView.currentItem.update(note) onNoteSaved: notesView.list.update(note, notesView.currentIndex)
} }
NewLinkDialog NewLinkDialog
{ {
id: newLinkDialog id: newLinkDialog
onLinkSaved: linksView.model.insert(link) onLinkSaved: linksView.list.insert(link)
} }
// /***** VIEWS *****/ // /***** VIEWS *****/
...@@ -193,7 +201,7 @@ Maui.ApplicationWindow ...@@ -193,7 +201,7 @@ Maui.ApplicationWindow
function setNote(note) function setNote(note)
{ {
var tags = notesView.model.getTags(notesView.currentIndex) var tags = notesView.list.getTags(notesView.currentIndex)
note.tags = tags note.tags = tags
notesView.currentNote = note notesView.currentNote = note
editNote.fill(note) editNote.fill(note)
...@@ -201,7 +209,7 @@ Maui.ApplicationWindow ...@@ -201,7 +209,7 @@ Maui.ApplicationWindow
function previewLink(link) function previewLink(link)
{ {
var tags = linksView.model.getTags(linksView.currentIndex) var tags = linksView.list.getTags(linksView.currentIndex)
link.tags = tags link.tags = tags
linksView.previewer.show(link) linksView.previewer.show(link)
......
#include "buho.h" #include "buho.h"
#include "owl.h"
Buho::Buho(QObject *parent) : DBActions(parent) Buho::Buho(QObject *parent) : QObject(parent)
{ {
this->setFolders(); this->setFolders();
} }
Tagging *Buho::getTagging()
{
return this->tag;
}
void Buho::setFolders() void Buho::setFolders()
{ {
QDir notes_path(OWL::NotesPath); QDir notes_path(OWL::NotesPath);
......
...@@ -2,20 +2,18 @@ ...@@ -2,20 +2,18 @@
#define BUHO_H #define BUHO_H
#include <QObject> #include <QObject>
#include "db/dbactions.h"
#ifdef STATIC_MAUIKIT #ifdef STATIC_MAUIKIT
#include "tagging.h" #include "tagging.h"
#else #else
#include <MauiKit/tagging.h> #include <MauiKit/tagging.h>
#endif #endif
class Buho : public DBActions
class Buho : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit Buho(QObject *parent = nullptr); explicit Buho(QObject *parent = nullptr);
Tagging* getTagging();
private: private:
void setFolders(); 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) ...@@ -194,6 +194,22 @@ void DocumentHandler::setBold(bool bold)
emit boldChanged(); 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 bool DocumentHandler::italic() const
{ {
QTextCursor cursor = textCursor(); QTextCursor cursor = textCursor();
......
...@@ -75,6 +75,7 @@ class DocumentHandler : public QObject ...@@ -75,6 +75,7 @@ class DocumentHandler : public QObject
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged) 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 italic READ italic WRITE setItalic NOTIFY italicChanged)
Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged) Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged)
...@@ -111,6 +112,9 @@ public: ...@@ -111,6 +112,9 @@ public:
bool bold() const; bool bold() const;
void setBold(bool bold); void setBold(bool bold);
bool uppercase() const;
void setUppercase(bool uppercase);
bool italic() const; bool italic() const;
void setItalic(bool italic); void setItalic(bool italic);
...@@ -139,6 +143,7 @@ Q_SIGNALS: ...@@ -139,6 +143,7 @@ Q_SIGNALS:
void alignmentChanged(); void alignmentChanged();
void boldChanged(); void boldChanged();
void uppercaseChanged();
void italicChanged(); void italicChanged();
void underlineChanged(); 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 "basemodel.h"
#include "links.h" #include "baselist.h"
#include "notes/notes.h"
LinksModel::LinksModel(QObject *parent) BaseModel::BaseModel(QObject *parent)
: QAbstractListModel(parent) : QAbstractListModel(parent),
{ mList(nullptr)
this->mLinks = new Links(this); {}
}
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 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 QVariant();
return mLinks->items().at(index.row())[static_cast<OWL::KEY>(role)];
}
QVariantMap LinksModel::get(const int &index) return mList->items().at(index.row())[static_cast<OWL::KEY>(role)];
{
QVariantMap res;
const auto note = mLinks->items().at(index);
for(auto key : note.keys())
res.insert(OWL::KEYMAP[key], note[key]);
return res;
} }
void LinksModel::sortBy(const int &index, const QString &order) bool BaseModel::setData(const QModelIndex &index, const QVariant &value, int role)
{ {
beginResetModel(); if (!mList)
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)
return false; return false;
if (mLinks->updateLink(index.row(), value, role)) if (mList->update(index.row(), value, role))
{ {
emit dataChanged(index, index, QVector<int>() << role); emit dataChanged(index, index, QVector<int>() << role);
return true; return true;
...@@ -82,7 +37,7 @@ bool LinksModel::setData(const QModelIndex &index, const QVariant &value, int ro ...@@ -82,7 +37,7 @@ bool LinksModel::setData(const QModelIndex &index, const QVariant &value, int ro
return false; return false;
} }
Qt::ItemFlags LinksModel::flags(const QModelIndex &index) const Qt::ItemFlags BaseModel::flags(const QModelIndex &index) const
{ {
if (!index.isValid()) if (!index.isValid())
return Qt::NoItemFlags; return Qt::NoItemFlags;
...@@ -90,7 +45,7 @@ Qt::ItemFlags LinksModel::flags(const QModelIndex &index) const ...@@ -90,7 +45,7 @@ Qt::ItemFlags LinksModel::flags(const QModelIndex &index) const
return Qt::ItemIsEditable; // FIXME: Implement me! return Qt::ItemIsEditable; // FIXME: Implement me!
} }
QHash<int, QByteArray> LinksModel::roleNames() const QHash<int, QByteArray> BaseModel::roleNames() const
{ {
QHash<int, QByteArray> names; QHash<int, QByteArray> names;
names[OWL::KEY::TITLE] = QString(OWL::KEYMAP[OWL::KEY::TITLE]).toUtf8(); names[OWL::KEY::TITLE] = QString(OWL::KEYMAP[OWL::KEY::TITLE]).toUtf8();
...@@ -111,42 +66,58 @@ QHash<int, QByteArray> LinksModel::roleNames() const ...@@ -111,42 +66,58 @@ QHash<int, QByteArray> LinksModel::roleNames() const
return names; return names;
} }
//Notes *NotesModel::notes() const BaseList *BaseModel::getList() const
//{ {
// return mLinks; return this->mList;
//} }
//void NotesModel::setNotes(Notes *value) void BaseModel::setList(BaseList *value)