1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-26 12:02:59 +02:00
joplin/QtClient/JoplinQtClient/application.cpp

67 lines
2.1 KiB
C++
Raw Normal View History

2016-12-11 16:09:39 +00:00
#include "application.h"
#include "models/folder.h"
#include "database.h"
#include "models/foldermodel.h"
#include "services/folderservice.h"
using namespace jop;
Application::Application(int &argc, char **argv) : QGuiApplication(argc, argv) {
2016-12-22 22:35:35 +01:00
db_ = Database("D:/Web/www/joplin/QtClient/data/notes.sqlite");
2016-12-11 16:09:39 +00:00
folderService_ = FolderService(db_);
folderModel_.setService(folderService_);
2016-12-12 22:33:33 +00:00
noteService_ = NoteService(db_);
noteModel_.setService(noteService_);
2016-12-11 16:09:39 +00:00
view_.setResizeMode(QQuickView::SizeRootObjectToView);
QQmlContext *ctxt = view_.rootContext();
ctxt->setContextProperty("folderListModel", &folderModel_);
2016-12-12 22:33:33 +00:00
ctxt->setContextProperty("noteListModel", &noteModel_);
2016-12-14 21:50:26 +00:00
ctxt->setContextProperty("noteModel", &selectedQmlNote_);
2016-12-11 16:09:39 +00:00
view_.setSource(QUrl("qrc:/main.qml"));
QObject* rootObject = (QObject*)view_.rootObject();
connect(rootObject, SIGNAL(currentFolderChanged()), this, SLOT(view_currentFolderChanged()));
2016-12-14 21:50:26 +00:00
connect(rootObject, SIGNAL(currentNoteChanged()), this, SLOT(view_currentNoteChanged()));
2016-12-11 16:09:39 +00:00
view_.show();
}
2016-12-12 22:33:33 +00:00
int Application::selectedFolderId() const {
2016-12-11 16:09:39 +00:00
QObject* rootObject = (QObject*)view_.rootObject();
int index = rootObject->property("currentFolderIndex").toInt();
QModelIndex modelIndex = folderModel_.index(index);
2016-12-12 22:33:33 +00:00
return folderModel_.data(modelIndex, FolderModel::IdRole).toInt();
2016-12-11 16:09:39 +00:00
}
2016-12-14 21:50:26 +00:00
int Application::selectedNoteId() const {
QObject* rootObject = (QObject*)view_.rootObject();
int index = rootObject->property("currentNoteIndex").toInt();
QModelIndex modelIndex = noteModel_.index(index);
return noteModel_.data(modelIndex, NoteModel::IdRole).toInt();
}
2016-12-11 16:09:39 +00:00
void Application::view_currentFolderChanged() {
2016-12-12 22:33:33 +00:00
int folderId = selectedFolderId();
2016-12-14 21:50:26 +00:00
noteCollection_ = NoteCollection(db_, folderId, "title ASC");
2016-12-12 22:33:33 +00:00
noteModel_.setCollection(noteCollection_);
2016-12-11 16:09:39 +00:00
}
2016-12-14 21:50:26 +00:00
void Application::view_currentNoteChanged() {
int noteId = selectedNoteId();
Note note = noteCollection_.byId(noteId);
selectedQmlNote_.setNote(note);
// TODO: get note by id
//Note note = noteCollection_.by
//selectedQmlNote_ = QmlNote(noteId);
//noteCollection_ = NoteCollection(db_, folderId, "title ASC");
//noteModel_.setCollection(noteCollection_);
}