Commit bfff896b authored by camilo higuita's avatar camilo higuita

make booklet model an attache dprop of book model

parent 7f239f41
......@@ -25,6 +25,7 @@
#include "./src/models/notes/notes.h"
#include "./src/models/books/books.h"
#include "./src/models/books/booklet.h"
#include "./src/models/links/links.h"
int main(int argc, char *argv[])
......@@ -61,6 +62,7 @@ int main(int argc, char *argv[])
Linker linker;
context->setContextProperty("linker", &linker);
qmlRegisterUncreatableType<Booklet>("Booklet", 1, 0 , "Booklet", "Booklet is instanciated by Books");
qmlRegisterType<Notes>("Notes", 1, 0, "Notes");
qmlRegisterType<Books>("Books", 1, 0, "Books");
qmlRegisterType<Links>("Links", 1, 0, "Links");
......
......@@ -32,6 +32,20 @@ Booklet::ORDER Booklet::getOrder() const
return this->order;
}
QString Booklet::getBook() const
{
return m_book;
}
void Booklet::setBook(const QString &book)
{
if (m_book == book)
return;
m_book = book;
emit bookChanged(m_book);
}
void Booklet::insert(const QVariantMap &data)
{
emit this->preItemAppended();
......
......@@ -17,10 +17,10 @@ class Booklet : public MauiList
Q_PROPERTY(SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
Q_PROPERTY(ORDER order READ getOrder WRITE setOrder NOTIFY orderChanged)
Q_PROPERTY(QString book READ getBook WRITE setBook NOTIFY bookChanged)
Q_PROPERTY(QString book READ getBook NOTIFY bookChanged)
public:
Booklet(Syncer *syncer = nullptr, QObject *parent = nullptr);
Booklet(Syncer *_syncer = nullptr, QObject *parent = nullptr);
enum ORDER : uint8_t
{
......@@ -47,21 +47,10 @@ public:
void setOrder(const ORDER &order);
ORDER getOrder() const;
QString getBook() const
{
return m_book;
}
QString getBook() const;
void setBook(const QString &book);
public slots:
void setBook(QString book)
{
if (m_book == book)
return;
m_book = book;
emit bookChanged(m_book);
}
void insert(const QVariantMap &data);
void update(const QVariantMap &data, const int &index);
void remove(const int &index);
......
#include "books.h"
#include "syncer.h"
#include "nextnote.h"
#include "booklet.h"
Books::Books(QObject *parent) : MauiList(parent),
syncer(new Syncer(this))
syncer(new Syncer(this)), m_booklet(new Booklet(syncer, this))
{
this->syncer->setProvider(new NextNote);
......@@ -82,5 +83,12 @@ return false;
bool Books::remove(const int &index)
{
return false;
return false;
}
void Books::openBook(const int &index)
{
if(index >= this->m_list.size() || index < 0)
return;
this->m_booklet->setBook(this->m_list.at(index)[FMH::MODEL_KEY::ID]);
}
......@@ -12,6 +12,7 @@
#include <MauiKit/mauilist.h>
#endif
class Booklet;
class Syncer;
class Books : public MauiList
{
......@@ -19,6 +20,7 @@ class Books : public MauiList
Q_PROPERTY(SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
Q_PROPERTY(ORDER order READ getOrder WRITE setOrder NOTIFY orderChanged)
Q_PROPERTY(Booklet *booklet READ getBooklet NOTIFY bookletChanged)
public:
enum ORDER : uint8_t
......@@ -48,8 +50,14 @@ public:
void setOrder(const ORDER &order);
ORDER getOrder() const;
Booklet * getBooklet() const
{
return m_booklet;
}
private:
Syncer *syncer;
Booklet * m_booklet;
FMH::MODEL_LIST m_list;
......@@ -62,6 +70,8 @@ signals:
void sortByChanged();
void orderChanged();
void bookletChanged(Booklet * booklet);
public slots:
QVariantMap get(const int &index) const;
......@@ -74,6 +84,8 @@ public slots:
bool insert(const QVariantMap &book);
bool update(const QVariantMap &data, const int &index);
bool remove(const int &index);
void openBook(const int &index);
};
#endif // BOOKS_H
......@@ -121,9 +121,9 @@ void Syncer::insertBook(FMH::MODEL &book)
emit this->bookInserted(book, {STATE::TYPE::LOCAL, STATE::STATUS::OK, "Book inserted locally sucessfully"});
}
void Syncer::insertBooklet(const FMH::MODEL &booklet)
void Syncer::insertBooklet(FMH::MODEL &booklet)
{
this->insertBookletLocal(booklet);
}
void Syncer::addId(FMH::MODEL &model)
......@@ -362,6 +362,7 @@ void Syncer::removeBookRemote(const QString &id)
bool Syncer::insertBookletLocal(FMH::MODEL &booklet)
{
qDebug()<< "trying to insert booklet" << booklet;
return false;
}
......
......@@ -174,7 +174,7 @@ public:
* @brief insertBooklet
* @param booklet
*/
void insertBooklet(const FMH::MODEL &booklet);
void insertBooklet(FMH::MODEL &booklet);
/**
* @brief removeBooklet
......
......@@ -10,6 +10,12 @@ Item
signal exit()
Maui.BaseModel
{
id: _bookletModel
list: _booksList.booklet
}
Maui.Page
{
id: _page
......@@ -55,6 +61,11 @@ Item
title: qsTr("New Chapter")
message: qsTr("Create a new chapter for your current book. Give it a title")
entryField: true
onAccepted:
{
_booksList.booklet.insert({title: textEntry.text})
}
}
Kirigami.OverlayDrawer
......@@ -66,6 +77,18 @@ Item
y: headBar.height
modal: !isWide
ListView
{
anchors.fill: parent
model: _bookletModel
delegate: Maui.LabelDelegate
{
label: model.title
}
}
Rectangle
{
z: 999
......
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