Exemplo n.º 1
0
void NotebookMenuButton::reloadData() {
    for (int i=actions.size()-1; i>=0; i--) {
        delete actions[i];
    }
    for (int i=stackMenus.size()-1; i>=0; i--) {
        delete stackMenus[i];
    }
    stackMenus.clear();
    actions.clear();
    loadData();

    // Restore the proper notebook selection

    Note n;
    NoteTable noteTable;
    NotebookTable notebookTable;
    noteTable.get(n, currentNoteLid, false,false);
    QString notebookGuid = QString::fromStdString(n.notebookGuid);
    QList<qint32> bookList;
    notebookTable.getAll(bookList);
    QString bookName;

    for (int i=0; i<bookList.size(); i++) {
        Notebook book;
        notebookTable.get(book, bookList[i]);
        if (notebookGuid == QString::fromStdString(book.guid)) {
            bookName = QString::fromStdString(book.name);
            i=bookList.size();
        }
    }
    setCurrentNotebook(currentNoteLid, n);
    return;
}
Exemplo n.º 2
0
// Read in all of the data and build the menu.
void NotebookMenuButton::loadData() {
    rootMenu.clear();
    NotebookTable notebookTable;

    QList<qint32> lids;
    notebookTable.getAll(lids);

    if (notebookTable.findByName(currentNotebookName) <= 0)
        currentNotebookName = "";

    for (qint32 i=0; i<lids.size(); i++) {
        Notebook book;
        if (notebookTable.get(book, lids[i])) {

            QAction *action = new QAction(this);
            actions.append(action);
            action->setText(QString::fromStdString(book.name));
            action->setCheckable(true);
            connect(action, SIGNAL(triggered()), this, SLOT(notebookSelected()));
            QFont f = action->font();
            f.setPixelSize(10);
            action->setFont(f);
            QMenu *currentMenu = findStack(book);

            addNotebookMenuItem(currentMenu, action);

            if (currentNotebookName == "" && book.__isset.defaultNotebook &&
                    book.defaultNotebook) {
                currentNotebookName = QString::fromStdString(book.name);
                setText(currentNotebookName);
                currentAction = actions.size()-1;
            }
            if (QString::fromStdString(book.name) == currentNotebookName) {
                action->setChecked(true);
            }
        }
    }
}