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