refactor: VNote and VNotebook

regression: notebook renaming logics does not work for now

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-11-25 10:09:32 +08:00
parent 013b6cecc2
commit 8e8d69c85f
16 changed files with 127 additions and 214 deletions

View File

@ -65,9 +65,6 @@ void VConfigManager::initialize()
m_mainWindowGeometry = getConfigFromSettings("session", "main_window_geometry").toByteArray();
m_mainWindowState = getConfigFromSettings("session", "main_window_state").toByteArray();
// Update notebooks
readNotebookFromSettings();
updateMarkdownEditStyle();
}
@ -87,25 +84,23 @@ void VConfigManager::readPredefinedColorsFromSettings()
<< "pre-defined colors from [predefined_colors] section";
}
void VConfigManager::readNotebookFromSettings()
void VConfigManager::readNotebookFromSettings(QVector<VNotebook *> &p_notebooks, QObject *parent)
{
notebooks.clear();
Q_ASSERT(p_notebooks.isEmpty());
int size = userSettings->beginReadArray("notebooks");
for (int i = 0; i < size; ++i) {
userSettings->setArrayIndex(i);
VNotebook notebook;
QString name = userSettings->value("name").toString();
QString path = userSettings->value("path").toString();
notebook.setName(name);
notebook.setPath(path);
notebooks.append(notebook);
VNotebook *notebook = new VNotebook(name, path, parent);
p_notebooks.append(notebook);
}
userSettings->endArray();
qDebug() << "read" << notebooks.size()
qDebug() << "read" << p_notebooks.size()
<< "notebook items from [notebooks] section";
}
void VConfigManager::writeNotebookToSettings()
void VConfigManager::writeNotebookToSettings(const QVector<VNotebook *> &p_notebooks)
{
// Clear it first
userSettings->beginGroup("notebooks");
@ -113,13 +108,14 @@ void VConfigManager::writeNotebookToSettings()
userSettings->endGroup();
userSettings->beginWriteArray("notebooks");
for (int i = 0; i < notebooks.size(); ++i) {
for (int i = 0; i < p_notebooks.size(); ++i) {
userSettings->setArrayIndex(i);
userSettings->setValue("name", notebooks[i].getName());
userSettings->setValue("path", notebooks[i].getPath());
const VNotebook &notebook = *p_notebooks[i];
userSettings->setValue("name", notebook.getName());
userSettings->setValue("path", notebook.getPath());
}
userSettings->endArray();
qDebug() << "write" << notebooks.size()
qDebug() << "write" << p_notebooks.size()
<< "notebook items in [notebooks] section";
}

View File

@ -60,8 +60,8 @@ public:
inline int getCurNotebookIndex() const;
inline void setCurNotebookIndex(int index);
inline const QVector<VNotebook>& getNotebooks() const;
inline void setNotebooks(const QVector<VNotebook> &notebooks);
inline void getNotebooks(QVector<VNotebook *> &p_notebooks, QObject *parent);
inline void setNotebooks(const QVector<VNotebook *> &p_notebooks);
inline hoedown_extensions getMarkdownExtensions() const;
inline MarkdownConverterType getMdConverterType() const;
@ -96,8 +96,8 @@ private:
void updateMarkdownEditStyle();
QVariant getConfigFromSettings(const QString &section, const QString &key);
void setConfigToSettings(const QString &section, const QString &key, const QVariant &value);
void readNotebookFromSettings();
void writeNotebookToSettings();
void readNotebookFromSettings(QVector<VNotebook *> &p_notebooks, QObject *parent);
void writeNotebookToSettings(const QVector<VNotebook *> &p_notebooks);
void readPredefinedColorsFromSettings();
// Update baseEditPalette according to curBackgroundColor
void updatePaletteColor();
@ -113,7 +113,6 @@ private:
QString postTemplatePath;
QString templateCssUrl;
int curNotebookIndex;
QVector<VNotebook> notebooks;
// Markdown Converter
hoedown_extensions markdownExtensions;
@ -199,15 +198,14 @@ inline void VConfigManager::setCurNotebookIndex(int index)
setConfigToSettings("global", "current_notebook", index);
}
inline const QVector<VNotebook>& VConfigManager::getNotebooks() const
inline void VConfigManager::getNotebooks(QVector<VNotebook *> &p_notebooks, QObject *parent)
{
return notebooks;
readNotebookFromSettings(p_notebooks, parent);
}
inline void VConfigManager::setNotebooks(const QVector<VNotebook> &notebooks)
inline void VConfigManager::setNotebooks(const QVector<VNotebook *> &p_notebooks)
{
this->notebooks = notebooks;
writeNotebookToSettings();
writeNotebookToSettings(p_notebooks);
}
inline hoedown_extensions VConfigManager::getMarkdownExtensions() const

View File

@ -64,10 +64,10 @@ void VDirectoryTree::setNotebook(const QString& notebookName)
clear();
return;
}
const QVector<VNotebook> &notebooks = vnote->getNotebooks();
const QVector<VNotebook *> &notebooks = vnote->getNotebooks();
for (int i = 0; i < notebooks.size(); ++i) {
if (notebooks[i].getName() == notebook) {
treePath = notebooks[i].getPath();
if (notebooks[i]->getName() == notebook) {
treePath = notebooks[i]->getPath();
break;
}
}
@ -585,12 +585,3 @@ void VDirectoryTree::renameDirectory(QTreeWidgetItem *item, const QString &newNa
qDebug() << "directory renamed" << oldPath << "to" << newPath;
emit directoryRenamed(notebook, oldPath, newPath);
}
void VDirectoryTree::handleNotebookRenamed(const QVector<VNotebook> &notebooks,
const QString &oldName, const QString &newName)
{
if (oldName == notebook) {
notebook = newName;
qDebug() << "directoryTree update notebook" << oldName << "to" << newName;
}
}

View File

@ -23,8 +23,6 @@ public slots:
void newRootDirectory();
void deleteDirectory();
void editDirectoryInfo();
void handleNotebookRenamed(const QVector<VNotebook> &notebooks, const QString &oldName,
const QString &newName);
private slots:
// Read config file and pdate the subtree of @item in the directory tree.

View File

@ -233,17 +233,6 @@ void VEditArea::saveAndReadFile()
win->saveAndReadFile();
}
void VEditArea::handleNotebookRenamed(const QVector<VNotebook> &notebooks,
const QString &oldName, const QString &newName)
{
int nrWin = splitter->count();
for (int i = 0; i < nrWin; ++i) {
VEditWindow *win = getWindow(i);
win->handleNotebookRenamed(notebooks, oldName, newName);
}
updateWindowStatus();
}
void VEditArea::handleDirectoryRenamed(const QString &notebook, const QString &oldRelativePath,
const QString &newRelativePath)
{

View File

@ -40,8 +40,6 @@ public slots:
void saveFile();
void readFile();
void saveAndReadFile();
void handleNotebookRenamed(const QVector<VNotebook> &notebooks, const QString &oldName,
const QString &newName);
void handleOutlineItemActivated(const VAnchor &anchor);
void handleDirectoryRenamed(const QString &notebook,
const QString &oldRelativePath, const QString &newRelativePath);

View File

@ -260,22 +260,6 @@ void VEditWindow::saveFile()
editor->saveFile();
}
void VEditWindow::handleNotebookRenamed(const QVector<VNotebook> &notebooks,
const QString &oldName, const QString &newName)
{
QTabBar *tabs = tabBar();
int nrTabs = tabs->count();
for (int i = 0; i < nrTabs; ++i) {
QJsonObject tabJson = tabs->tabData(i).toJsonObject();
if (tabJson["notebook"] == oldName) {
tabJson["notebook"] = newName;
tabs->setTabData(i, tabJson);
tabs->setTabToolTip(i, generateTooltip(tabJson));
}
}
updateTabListMenu();
}
void VEditWindow::handleDirectoryRenamed(const QString &notebook, const QString &oldRelativePath,
const QString &newRelativePath)
{

View File

@ -27,8 +27,6 @@ public:
void saveFile();
void readFile();
void saveAndReadFile();
void handleNotebookRenamed(const QVector<VNotebook> &notebooks, const QString &oldName,
const QString &newName);
bool closeAllFiles(bool p_forced);
void setRemoveSplitEnable(bool enabled);
void requestUpdateTabStatus();

View File

@ -83,10 +83,10 @@ void VFileList::setDirectory(QJsonObject dirJson)
notebook = dirJson["notebook"].toString();
relativePath = dirJson["relative_path"].toString();
rootPath = "";
const QVector<VNotebook> &notebooks = vnote->getNotebooks();
const QVector<VNotebook *> &notebooks = vnote->getNotebooks();
for (int i = 0; i < notebooks.size(); ++i) {
if (notebooks[i].getName() == notebook) {
rootPath = notebooks[i].getPath();
if (notebooks[i]->getName() == notebook) {
rootPath = notebooks[i]->getPath();
break;
}
}
@ -430,14 +430,6 @@ bool VFileList::importFile(const QString &name)
return insertFileListItem(fileJson, true);
}
void VFileList::handleNotebookRenamed(const QVector<VNotebook> &notebooks,
const QString &oldName, const QString &newName)
{
if (oldName == notebook) {
notebook = newName;
}
}
void VFileList::handleDirectoryRenamed(const QString &notebook,
const QString &oldRelativePath, const QString &newRelativePath)
{

View File

@ -44,8 +44,6 @@ private slots:
public slots:
void setDirectory(QJsonObject dirJson);
void handleNotebookRenamed(const QVector<VNotebook> &notebooks, const QString &oldName,
const QString &newName);
void handleDirectoryRenamed(const QString &notebook, const QString &oldRelativePath,
const QString &newRelativePath);
void newFile();

View File

@ -18,7 +18,7 @@ VMainWindow::VMainWindow(QWidget *parent)
{
setWindowIcon(QIcon(":/resources/icons/vnote.ico"));
// Must be called before those who uses VConfigManager
vnote = new VNote();
vnote = new VNote(this);
vnote->initPalette(palette());
initPredefinedColorPixmaps();
setupUI();
@ -31,11 +31,6 @@ VMainWindow::VMainWindow(QWidget *parent)
updateNotebookComboBox(vnote->getNotebooks());
}
VMainWindow::~VMainWindow()
{
delete vnote;
}
void VMainWindow::setupUI()
{
QWidget *directoryPanel = setupDirectoryPanel();
@ -60,8 +55,6 @@ void VMainWindow::setupUI()
connect(notebookComboBox, SIGNAL(currentIndexChanged(int)), this,
SLOT(setCurNotebookIndex(int)));
connect(vnote, &VNote::notebooksRenamed,
fileList, &VFileList::handleNotebookRenamed);
connect(directoryTree, &VDirectoryTree::currentDirectoryChanged,
fileList, &VFileList::setDirectory);
connect(directoryTree, &VDirectoryTree::directoryRenamed,
@ -75,8 +68,6 @@ void VMainWindow::setupUI()
editArea, &VEditArea::closeFile);
connect(fileList, &VFileList::fileCreated,
editArea, &VEditArea::openFile);
connect(vnote, &VNote::notebooksRenamed,
editArea, &VEditArea::handleNotebookRenamed);
connect(editArea, &VEditArea::curTabStatusChanged,
this, &VMainWindow::handleCurTabStatusChanged);
connect(directoryTree, &VDirectoryTree::directoryRenamed,
@ -91,19 +82,15 @@ void VMainWindow::setupUI()
connect(notebookInfoBtn, &QPushButton::clicked,
this, &VMainWindow::onNotebookInfoBtnClicked);
connect(vnote, &VNote::notebooksChanged,
this, &VMainWindow::updateNotebookComboBox);
connect(vnote, &VNote::notebooksDeleted,
connect(vnote, &VNote::notebookDeleted,
this, &VMainWindow::notebookComboBoxDeleted);
connect(vnote, &VNote::notebooksRenamed,
connect(vnote, &VNote::notebookRenamed,
this, &VMainWindow::notebookComboBoxRenamed);
connect(vnote, &VNote::notebooksAdded,
connect(vnote, &VNote::notebookAdded,
this, &VMainWindow::notebookComboBoxAdded);
connect(this, &VMainWindow::curNotebookChanged,
directoryTree, &VDirectoryTree::setNotebook);
connect(vnote, &VNote::notebooksRenamed,
directoryTree, &VDirectoryTree::handleNotebookRenamed);
setCentralWidget(mainSplitter);
// Create and show the status bar
@ -383,18 +370,18 @@ void VMainWindow::initDockWindows()
viewMenu->addAction(toolDock->toggleViewAction());
}
void VMainWindow::updateNotebookComboBox(const QVector<VNotebook> &notebooks)
void VMainWindow::updateNotebookComboBox(const QVector<VNotebook *> &p_notebooks)
{
notebookComboMuted = true;
notebookComboBox->clear();
for (int i = 0; i < notebooks.size(); ++i) {
for (int i = 0; i < p_notebooks.size(); ++i) {
notebookComboBox->addItem(QIcon(":/resources/icons/notebook_item.svg"),
notebooks[i].getName());
p_notebooks[i]->getName());
}
notebookComboMuted = false;
int index = vconfig.getCurNotebookIndex();
if (notebooks.isEmpty()) {
if (p_notebooks.isEmpty()) {
index = -1;
}
if (notebookComboBox->currentIndex() == index) {
@ -404,11 +391,11 @@ void VMainWindow::updateNotebookComboBox(const QVector<VNotebook> &notebooks)
}
}
void VMainWindow::notebookComboBoxAdded(const QVector<VNotebook> &notebooks, int idx)
void VMainWindow::notebookComboBoxAdded(const VNotebook *p_notebook, int p_idx)
{
notebookComboMuted = true;
notebookComboBox->insertItem(idx, QIcon(":/resources/icons/notebook_item.svg"),
notebooks[idx].getName());
notebookComboBox->insertItem(p_idx, QIcon(":/resources/icons/notebook_item.svg"),
p_notebook->getName());
notebookComboMuted = false;
if (notebookComboBox->currentIndex() == vconfig.getCurNotebookIndex()) {
setCurNotebookIndex(vconfig.getCurNotebookIndex());
@ -417,16 +404,11 @@ void VMainWindow::notebookComboBoxAdded(const QVector<VNotebook> &notebooks, int
}
}
void VMainWindow::notebookComboBoxDeleted(const QVector<VNotebook> &notebooks, const QString &deletedName)
void VMainWindow::notebookComboBoxDeleted(int p_oriIdx)
{
Q_ASSERT(p_oriIdx >= 0 && p_oriIdx < notebookComboBox->count());
notebookComboMuted = true;
int nrItem = notebookComboBox->count();
for (int i = 0; i < nrItem; ++i) {
if (notebookComboBox->itemText(i) == deletedName) {
notebookComboBox->removeItem(i);
break;
}
}
notebookComboBox->removeItem(p_oriIdx);
notebookComboMuted = false;
if (notebookComboBox->currentIndex() == vconfig.getCurNotebookIndex()) {
@ -434,19 +416,12 @@ void VMainWindow::notebookComboBoxDeleted(const QVector<VNotebook> &notebooks, c
} else {
notebookComboBox->setCurrentIndex(vconfig.getCurNotebookIndex());
}
Q_ASSERT(notebooks.size() == notebookComboBox->count());
}
void VMainWindow::notebookComboBoxRenamed(const QVector<VNotebook> &notebooks,
const QString &oldName, const QString &newName)
void VMainWindow::notebookComboBoxRenamed(const VNotebook *p_notebook, int p_idx)
{
int nrItem = notebookComboBox->count();
for (int i = 0; i < nrItem; ++i) {
if (notebookComboBox->itemText(i) == oldName) {
notebookComboBox->setItemText(i, newName);
break;
}
}
Q_ASSERT(p_idx >= 0 && p_idx < notebookComboBox->count());
notebookComboBox->setItemText(p_idx, p_notebook->getName());
// Renaming a notebook won't change current index
}
@ -461,7 +436,7 @@ void VMainWindow::setCurNotebookIndex(int index)
QString notebook;
if (index > -1) {
vconfig.setCurNotebookIndex(index);
notebook = vnote->getNotebooks()[index].getName();
notebook = vnote->getNotebooks()[index]->getName();
newRootDirAct->setEnabled(true);
} else {
newRootDirAct->setEnabled(false);
@ -494,9 +469,9 @@ void VMainWindow::onNewNotebookBtnClicked()
bool VMainWindow::isConflictWithExistingNotebooks(const QString &name)
{
const QVector<VNotebook> &notebooks = vnote->getNotebooks();
const QVector<VNotebook *> &notebooks = vnote->getNotebooks();
for (int i = 0; i < notebooks.size(); ++i) {
if (notebooks[i].getName() == name) {
if (notebooks[i]->getName() == name) {
return true;
}
}
@ -506,15 +481,15 @@ bool VMainWindow::isConflictWithExistingNotebooks(const QString &name)
void VMainWindow::onDeleteNotebookBtnClicked()
{
int curIndex = notebookComboBox->currentIndex();
QString curName = vnote->getNotebooks()[curIndex].getName();
QString curPath = vnote->getNotebooks()[curIndex].getPath();
QString curName = vnote->getNotebooks()[curIndex]->getName();
QString curPath = vnote->getNotebooks()[curIndex]->getPath();
QMessageBox msgBox(QMessageBox::Warning, tr("Warning"), QString("Are you sure you want to delete notebook \"%1\"?")
.arg(curName), QMessageBox::Ok | QMessageBox::Cancel, this);
msgBox.setInformativeText(QString("This will delete any files in this notebook (\"%1\").").arg(curPath));
msgBox.setDefaultButton(QMessageBox::Cancel);
if (msgBox.exec() == QMessageBox::Ok) {
vnote->removeNotebook(curName);
vnote->removeNotebook(curIndex);
}
}
@ -525,8 +500,8 @@ void VMainWindow::onNotebookInfoBtnClicked()
return;
}
QString info;
QString curName = vnote->getNotebooks()[curIndex].getName();
QString defaultPath = vnote->getNotebooks()[curIndex].getPath();
QString curName = vnote->getNotebooks()[curIndex]->getName();
QString defaultPath = vnote->getNotebooks()[curIndex]->getPath();
QString defaultName(curName);
do {
VNotebookInfoDialog dialog(tr("Notebook information"), info, defaultName,
@ -541,7 +516,7 @@ void VMainWindow::onNotebookInfoBtnClicked()
defaultName = name;
continue;
}
vnote->renameNotebook(curName, name);
vnote->renameNotebook(curIndex, name);
}
break;
} while (true);

View File

@ -29,7 +29,6 @@ class VMainWindow : public QMainWindow
public:
VMainWindow(QWidget *parent = 0);
~VMainWindow();
const QVector<QPair<QString, QString> > &getPalette() const;
private slots:
@ -38,11 +37,10 @@ private slots:
void onNewNotebookBtnClicked();
void onDeleteNotebookBtnClicked();
void onNotebookInfoBtnClicked();
void updateNotebookComboBox(const QVector<VNotebook> &notebooks);
void notebookComboBoxAdded(const QVector<VNotebook> &notebooks, int idx);
void notebookComboBoxDeleted(const QVector<VNotebook> &notebooks, const QString &deletedName);
void notebookComboBoxRenamed(const QVector<VNotebook> &notebooks,
const QString &oldName, const QString &newName);
void updateNotebookComboBox(const QVector<VNotebook *> &p_notebooks);
void notebookComboBoxAdded(const VNotebook *p_notebook, int p_idx);
void notebookComboBoxDeleted(int p_oriIdx);
void notebookComboBoxRenamed(const VNotebook *p_notebook, int p_idx);
void importNoteFromFile();
void changeMarkdownConverter(QAction *action);
void aboutMessage();

View File

@ -13,12 +13,12 @@ QString VNote::templateHtml;
QString VNote::preTemplateHtml;
QString VNote::postTemplateHtml;
VNote::VNote() : QObject()
VNote::VNote(QObject *parent)
: QObject(parent)
{
vconfig.initialize();
initTemplate();
notebooks = vconfig.getNotebooks();
emit notebooksChanged(notebooks);
vconfig.getNotebooks(m_notebooks, this);
}
void VNote::initPalette(QPalette palette)
@ -75,9 +75,9 @@ void VNote::updateTemplate()
postTemplateHtml = VUtils::readFileFromDisk(vconfig.getPostTemplatePath());
}
const QVector<VNotebook>& VNote::getNotebooks()
const QVector<VNotebook *> &VNote::getNotebooks()
{
return notebooks;
return m_notebooks;
}
void VNote::createNotebook(const QString &name, const QString &path)
@ -92,78 +92,66 @@ void VNote::createNotebook(const QString &name, const QString &path)
}
// Update notebooks settings
notebooks.prepend(VNotebook(name, path));
vconfig.setNotebooks(notebooks);
VNotebook *nb = new VNotebook(name, path, this);
m_notebooks.prepend(nb);
vconfig.setNotebooks(m_notebooks);
// Set current index to the new notebook
vconfig.setCurNotebookIndex(0);
emit notebooksAdded(notebooks, 0);
emit notebookAdded(nb, 0);
}
void VNote::removeNotebook(const QString &name)
void VNote::removeNotebook(int idx)
{
// Update notebooks settings
QString path;
Q_ASSERT(idx >= 0 && idx < m_notebooks.size());
VNotebook *nb = m_notebooks[idx];
QString name = nb->getName();
QString path = nb->getPath();
// Update notebook settings
int curIndex = vconfig.getCurNotebookIndex();
int index;
for (index = 0; index < notebooks.size(); ++index) {
if (notebooks[index].getName() == name) {
path = notebooks[index].getPath();
break;
}
}
if (index == notebooks.size()) {
return;
}
notebooks.remove(index);
vconfig.setNotebooks(notebooks);
if (notebooks.isEmpty()) {
m_notebooks.remove(idx);
vconfig.setNotebooks(m_notebooks);
if (m_notebooks.isEmpty()) {
vconfig.setCurNotebookIndex(-1);
} else if (index == curIndex) {
} else if (idx == curIndex) {
vconfig.setCurNotebookIndex(0);
}
// Close all the directory and files
notebookPathHash.remove(name);
nb->close(true);
delete nb;
qDebug() << "notebook" << name << "deleted";
// Delete the directory
QDir dir(path);
if (!dir.removeRecursively()) {
qWarning() << "error: fail to delete" << path << "recursively";
} else {
qDebug() << "delete" << path << "recursively";
qWarning() << "failed to delete" << path << "recursively";
}
emit notebookDeleted(idx);
}
notebookPathHash.remove(name);
emit notebooksDeleted(notebooks, name);
}
void VNote::renameNotebook(const QString &name, const QString &newName)
void VNote::renameNotebook(int idx, const QString &newName)
{
QString path;
int index;
for (index = 0; index < notebooks.size(); ++index) {
if (notebooks[index].getName() == name) {
path = notebooks[index].getPath();
break;
}
}
if (index == notebooks.size()) {
return;
}
notebooks[index].setName(newName);
vconfig.setNotebooks(notebooks);
Q_ASSERT(idx >= 0 && idx < m_notebooks.size());
VNotebook *nb = m_notebooks[idx];
QString name = nb->getName();
notebookPathHash.remove(name);
emit notebooksRenamed(notebooks, name, newName);
nb->setName(newName);
vconfig.setNotebooks(m_notebooks);
emit notebookRenamed(nb, idx);
}
QString VNote::getNotebookPath(const QString &name)
{
QString path = notebookPathHash.value(name);
if (path.isEmpty()) {
for (int i = 0; i < notebooks.size(); ++i) {
if (notebooks[i].getName() == name) {
path = notebooks[i].getPath();
for (int i = 0; i < m_notebooks.size(); ++i) {
if (m_notebooks[i]->getName() == name) {
path = m_notebooks[i]->getPath();
break;
}
}

View File

@ -17,9 +17,9 @@ class VNote : public QObject
{
Q_OBJECT
public:
VNote();
VNote(QObject *parent = 0);
const QVector<VNotebook>& getNotebooks();
const QVector<VNotebook *>& getNotebooks();
void initTemplate();
@ -31,8 +31,8 @@ public:
static QString postTemplateHtml;
void createNotebook(const QString &name, const QString &path);
void removeNotebook(const QString &name);
void renameNotebook(const QString &name, const QString &newName);
void removeNotebook(int idx);
void renameNotebook(int idx, const QString &newName);
QString getNotebookPath(const QString &name);
@ -43,15 +43,13 @@ public slots:
void updateTemplate();
signals:
// Force to do a fully update
void notebooksChanged(const QVector<VNotebook> &notebooks);
void notebooksAdded(const QVector<VNotebook> &notebooks, int idx);
void notebooksDeleted(const QVector<VNotebook> &notebooks, const QString &deletedName);
void notebooksRenamed(const QVector<VNotebook> &notebooks,
const QString &oldName, const QString &newName);
void notebookAdded(const VNotebook *p_notebook, int p_idx);
void notebookDeleted(int p_oriIdx);
void notebookRenamed(const VNotebook *p_notebook, int p_idx);
private:
QVector<VNotebook> notebooks;
// Maintain all the notebooks. Other holder should use QPointer.
QVector<VNotebook *> m_notebooks;
QHash<QString, QString> notebookPathHash;
QVector<QPair<QString, QString> > m_palette;
};

View File

@ -1,31 +1,37 @@
#include "vnotebook.h"
VNotebook::VNotebook()
VNotebook::VNotebook(QObject *parent)
: QObject(parent)
{
}
VNotebook::VNotebook(const QString &name, const QString &path)
: name(name), path(path)
VNotebook::VNotebook(const QString &name, const QString &path, QObject *parent)
: QObject(parent), m_name(name), m_path(path)
{
}
QString VNotebook::getName() const
{
return this->name;
return m_name;
}
QString VNotebook::getPath() const
{
return this->path;
return m_path;
}
void VNotebook::setName(const QString &name)
{
this->name = name;
m_name = name;
}
void VNotebook::setPath(const QString &path)
{
this->path = path;
m_path = path;
}
void VNotebook::close(bool p_forced)
{
//TODO
}

View File

@ -1,13 +1,19 @@
#ifndef VNOTEBOOK_H
#define VNOTEBOOK_H
#include <QObject>
#include <QString>
class VNotebook
class VNotebook : public QObject
{
Q_OBJECT
public:
VNotebook();
VNotebook(const QString &name, const QString &path);
VNotebook(QObject *parent = 0);
VNotebook(const QString &name, const QString &path, QObject *parent = 0);
// Close all the directory and files of this notebook.
// If @p_forced, unsaved files will also be closed without a confirm.
void close(bool p_forced);
QString getName() const;
QString getPath() const;
@ -15,8 +21,8 @@ public:
void setPath(const QString &path);
private:
QString name;
QString path;
QString m_name;
QString m_path;
};
#endif // VNOTEBOOK_H