added save file option (keep filename)
This commit is contained in:
parent
95eebd4112
commit
3ad5d3bd57
@ -17,6 +17,7 @@ MainWindow::MainWindow(QWidget *parent)
|
|||||||
|
|
||||||
connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(newFile()));
|
connect(ui->actionNew, SIGNAL(triggered()), this, SLOT(newFile()));
|
||||||
connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
|
connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(openFile()));
|
||||||
|
connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(saveFile()));
|
||||||
connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveFileAs()));
|
connect(ui->actionSave_as, SIGNAL(triggered()), this, SLOT(saveFileAs()));
|
||||||
|
|
||||||
newFile();
|
newFile();
|
||||||
@ -33,6 +34,8 @@ void MainWindow::newFile()
|
|||||||
ui->metaDataWidget->setModel(&m_dataModel->m_metaData);
|
ui->metaDataWidget->setModel(&m_dataModel->m_metaData);
|
||||||
ui->verbEndWidget->setModel(&m_dataModel->m_verbEnd);
|
ui->verbEndWidget->setModel(&m_dataModel->m_verbEnd);
|
||||||
ui->genusWidget->setModel(&m_dataModel->m_genus);
|
ui->genusWidget->setModel(&m_dataModel->m_genus);
|
||||||
|
|
||||||
|
m_filename = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openFile()
|
void MainWindow::openFile()
|
||||||
@ -55,9 +58,23 @@ void MainWindow::openFile()
|
|||||||
|
|
||||||
m_dataModel->read(loadDoc.object());
|
m_dataModel->read(loadDoc.object());
|
||||||
|
|
||||||
|
m_filename = filename;
|
||||||
|
|
||||||
ui->metaDataWidget->toFirst();
|
ui->metaDataWidget->toFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::saveFile()
|
||||||
|
{
|
||||||
|
if (m_filename.isEmpty())
|
||||||
|
{
|
||||||
|
saveFileAs();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saveFile(m_filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::saveFileAs()
|
void MainWindow::saveFileAs()
|
||||||
{
|
{
|
||||||
QString filename = QFileDialog::getSaveFileName(this);
|
QString filename = QFileDialog::getSaveFileName(this);
|
||||||
@ -66,6 +83,11 @@ void MainWindow::saveFileAs()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveFile(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::saveFile(const QString &filename)
|
||||||
|
{
|
||||||
QJsonObject saveData;
|
QJsonObject saveData;
|
||||||
m_dataModel->write(saveData);
|
m_dataModel->write(saveData);
|
||||||
|
|
||||||
@ -75,4 +97,6 @@ void MainWindow::saveFileAs()
|
|||||||
saveFile.open(QFile::WriteOnly);
|
saveFile.open(QFile::WriteOnly);
|
||||||
saveFile.write(saveDoc.toJson());
|
saveFile.write(saveDoc.toJson());
|
||||||
saveFile.close();
|
saveFile.close();
|
||||||
|
|
||||||
|
m_filename = filename;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ class MainWindow : public QMainWindow
|
|||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
std::unique_ptr<DataModel> m_dataModel;
|
std::unique_ptr<DataModel> m_dataModel;
|
||||||
|
QString m_filename;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MainWindow(QWidget *parent = nullptr);
|
MainWindow(QWidget *parent = nullptr);
|
||||||
@ -26,5 +27,9 @@ public:
|
|||||||
public slots:
|
public slots:
|
||||||
void newFile();
|
void newFile();
|
||||||
void openFile();
|
void openFile();
|
||||||
|
void saveFile();
|
||||||
void saveFileAs();
|
void saveFileAs();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void saveFile(const QString &filename);
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="MetaDataTab">
|
<widget class="QWidget" name="MetaDataTab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
@ -60,7 +60,7 @@
|
|||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>905</width>
|
<width>905</width>
|
||||||
<height>19</height>
|
<height>17</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
@ -69,6 +69,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<addaction name="actionNew"/>
|
<addaction name="actionNew"/>
|
||||||
<addaction name="actionOpen"/>
|
<addaction name="actionOpen"/>
|
||||||
|
<addaction name="actionSave"/>
|
||||||
<addaction name="actionSave_as"/>
|
<addaction name="actionSave_as"/>
|
||||||
<addaction name="separator"/>
|
<addaction name="separator"/>
|
||||||
<addaction name="actionQuit"/>
|
<addaction name="actionQuit"/>
|
||||||
@ -87,7 +88,7 @@
|
|||||||
</attribute>
|
</attribute>
|
||||||
<addaction name="actionNew"/>
|
<addaction name="actionNew"/>
|
||||||
<addaction name="actionOpen"/>
|
<addaction name="actionOpen"/>
|
||||||
<addaction name="actionSave_as"/>
|
<addaction name="actionSave"/>
|
||||||
</widget>
|
</widget>
|
||||||
<action name="actionSave_as">
|
<action name="actionSave_as">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
@ -100,9 +101,6 @@
|
|||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Save as...</string>
|
<string>Save as...</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="shortcut">
|
|
||||||
<string>Ctrl+S</string>
|
|
||||||
</property>
|
|
||||||
</action>
|
</action>
|
||||||
<action name="actionOpen">
|
<action name="actionOpen">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
@ -136,6 +134,18 @@
|
|||||||
<string>Ctrl+Q</string>
|
<string>Ctrl+Q</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionSave">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="mainwindow.qrc">
|
||||||
|
<normaloff>:/images/document-save-as.png</normaloff>:/images/document-save-as.png</iconset>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Save</string>
|
||||||
|
</property>
|
||||||
|
<property name="shortcut">
|
||||||
|
<string>Ctrl+S</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
<customwidget>
|
<customwidget>
|
||||||
|
Reference in New Issue
Block a user