db backend: mostly feature-complete
This commit is contained in:
parent
872bb95acf
commit
0afe9ca6bf
12 changed files with 497 additions and 160 deletions
|
|
@ -2,6 +2,8 @@
|
|||
#include "ui_numberator.h"
|
||||
#include "ui_TagListDock.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
Numberator::Numberator(QWidget *parent)
|
||||
: QMainWindow(parent)
|
||||
, ui(new Ui::Numberator)
|
||||
|
|
@ -14,6 +16,12 @@ Numberator::Numberator(QWidget *parent)
|
|||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
connect(&proj, &SQLiteSaveFile::fileIOError, [=](auto e, QString errorName, QString description) {
|
||||
Q_UNUSED(e);
|
||||
qDebug() << errorName << ": " << description;
|
||||
QMessageBox::critical(this, errorName, description);
|
||||
});
|
||||
|
||||
QDockWidget *dock = new QDockWidget(this);
|
||||
tagsDockUi->setupUi(dock);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, dock);
|
||||
|
|
@ -45,26 +53,29 @@ Numberator::Numberator(QWidget *parent)
|
|||
connect(&saveOpenDialog, &QFileDialog::accepted, [=]() {
|
||||
settings.setValue("MainWindow/SaveAsFileDialogState", this->saveOpenDialog.saveState());
|
||||
});
|
||||
connect(ui->actionSave_Project, &QAction::triggered, [=](bool checked){
|
||||
Q_UNUSED(checked);
|
||||
this->saveOpenDialog.setWindowTitle("Save Project as...");
|
||||
disconnect(&this->saveOpenDialog, &QFileDialog::fileSelected, nullptr, nullptr);
|
||||
connect(&this->saveOpenDialog, &QFileDialog::fileSelected,
|
||||
&this->proj, &SQLiteSaveFile::saveAs);
|
||||
this->saveOpenDialog.open();
|
||||
});
|
||||
connect(ui->actionOpen_Project, &QAction::triggered, [=](bool checked){
|
||||
Q_UNUSED(checked);
|
||||
this->saveOpenDialog.setWindowTitle("Open Project...");
|
||||
disconnect(&this->saveOpenDialog, &QFileDialog::fileSelected, nullptr, nullptr);
|
||||
connect(&this->saveOpenDialog, &QFileDialog::fileSelected,
|
||||
this, &Numberator::openFile);
|
||||
this->saveOpenDialog.open();
|
||||
connect(ui->actionSave_Project, &QAction::triggered, this, &Numberator::showSaveDialog);
|
||||
connect(ui->actionOpen_Project, &QAction::triggered, [=](){
|
||||
if (!showConfirmDiscardDialog())
|
||||
return;
|
||||
|
||||
saveOpenDialog.setWindowTitle("Open Project...");
|
||||
saveOpenDialog.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
if (saveOpenDialog.exec() == QDialog::Accepted)
|
||||
proj.open(saveOpenDialog.selectedFiles().value(0));
|
||||
});
|
||||
|
||||
connect(ui->actionNew_Project, &QAction::triggered,
|
||||
&proj, &SQLiteSaveFile::clearNew);
|
||||
connect(ui->actionQuit, &QAction::triggered, &QApplication::quit);
|
||||
connect(ui->actionNew_Project, &QAction::triggered, [=]() {
|
||||
if (!showConfirmDiscardDialog())
|
||||
return;
|
||||
|
||||
proj.clearNew();
|
||||
});
|
||||
connect(ui->actionQuit, &QAction::triggered, [=]() {
|
||||
if (!showConfirmDiscardDialog())
|
||||
return;
|
||||
|
||||
QApplication::quit();
|
||||
});
|
||||
connect(ui->actionAbout, &QAction::triggered, &aboutDialog, &AboutDialog::open);
|
||||
|
||||
connect(tagsDockUi->tagList->selectionModel(), &QItemSelectionModel::currentChanged,
|
||||
|
|
@ -79,8 +90,33 @@ Numberator::~Numberator()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void Numberator::openFile(const QString &path)
|
||||
bool Numberator::showConfirmDiscardDialog()
|
||||
{
|
||||
if (!proj.isMemory() || !proj.isDirty())
|
||||
return true;
|
||||
|
||||
auto btn = QMessageBox::warning(this, "Discard unsaved changes?", "This document contains unsaved changes. Do you want to save these changes?",
|
||||
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
|
||||
|
||||
if (btn == QMessageBox::Cancel)
|
||||
return false;
|
||||
|
||||
if (btn == QMessageBox::Save)
|
||||
return showSaveDialog();
|
||||
|
||||
/* else, the discard button was clicked */
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Numberator::showSaveDialog()
|
||||
{
|
||||
saveOpenDialog.setWindowTitle("Save Project as...");
|
||||
saveOpenDialog.setAcceptMode(QFileDialog::AcceptSave);
|
||||
if (saveOpenDialog.exec() == QDialog::Accepted) {
|
||||
QString fn = this->saveOpenDialog.selectedFiles().value(0);
|
||||
qDebug() << QString("Calling saveas(%1)").arg(fn);
|
||||
return proj.saveAs(fn);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue