fixed window title and file modification dialog

master
Marc Wäckerlin 7 years ago
parent 62fefb3183
commit e527c94918
  1. 19
      src/testgui.hxx
  2. 18
      src/testgui.ui
  3. 4
      src/webtester.cxx

@ -35,6 +35,7 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
QMainWindow(parent), QMainWindow(parent),
_typing(false), _typing(false),
_inEventFilter(false) { _inEventFilter(false) {
setWindowTitle("[*]");
setupUi(this); setupUi(this);
menuViews->addAction(_scriptDock->toggleViewAction()); menuViews->addAction(_scriptDock->toggleViewAction());
menuViews->addAction(_setupScriptDock->toggleViewAction()); menuViews->addAction(_setupScriptDock->toggleViewAction());
@ -118,6 +119,8 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
+char(out.status()+48)+")"); +char(out.status()+48)+")");
_actionSave->setEnabled(true); _actionSave->setEnabled(true);
_actionRevertToSaved->setEnabled(true); _actionRevertToSaved->setEnabled(true);
setWindowModified(false);
setWindowTitle(_filename+"[*]");
} catch(const std::exception& x) { } catch(const std::exception& x) {
QMessageBox::critical(this, tr("Save Failed"), QMessageBox::critical(this, tr("Save Failed"),
tr("Saving test script failed, %2. " tr("Saving test script failed, %2. "
@ -127,11 +130,18 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
_status->setCurrentIndex(STATUS_NONE); _status->setCurrentIndex(STATUS_NONE);
} }
void on__actionClear_triggered() { void on__actionClear_triggered() {
if (isWindowModified() &&
QMessageBox::question(this, tr("Changes Not Saved"),
tr("Clear script without saving changes?"))
!= QMessageBox::Yes)
return;
_testscript->clear(); _testscript->clear();
_log->clear(); _log->clear();
_filename.clear(); _filename.clear();
_actionSave->setEnabled(false); _actionSave->setEnabled(false);
_actionRevertToSaved->setEnabled(false); _actionRevertToSaved->setEnabled(false);
setWindowTitle("[*]");
setWindowModified(false);
_status->setCurrentIndex(STATUS_NONE); _status->setCurrentIndex(STATUS_NONE);
} }
void on__run_clicked() { void on__run_clicked() {
@ -332,6 +342,13 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
QSettings settings("mrw", "webtester"); QSettings settings("mrw", "webtester");
settings.setValue("geometry", saveGeometry()); settings.setValue("geometry", saveGeometry());
settings.setValue("windowstate", saveState()); settings.setValue("windowstate", saveState());
if (isWindowModified() &&
QMessageBox::question(this, tr("Changes Not Saved"),
tr("Leave without saving changes?"))
!= QMessageBox::Yes) {
event->ignore();
return;
}
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
bool eventFilter(QObject*, QEvent* event) { bool eventFilter(QObject*, QEvent* event) {
@ -442,6 +459,8 @@ class TestGUI: public QMainWindow, protected Ui::TestGUI {
_filename = name; _filename = name;
_actionSave->setEnabled(true); _actionSave->setEnabled(true);
_actionRevertToSaved->setEnabled(true); _actionRevertToSaved->setEnabled(true);
setWindowTitle(name+"[*]");
setWindowModified(false);
} catch(const std::exception& x) { } catch(const std::exception& x) {
QMessageBox::critical(this, tr("Open Failed"), QMessageBox::critical(this, tr("Open Failed"),
tr("Reading test script failed, %2. " tr("Reading test script failed, %2. "

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string/>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout_6"> <layout class="QVBoxLayout" name="verticalLayout_6">
@ -1089,5 +1089,21 @@ this.dispatchEvent(evObj);</string>
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>_testscript</sender>
<signal>modificationChanged(bool)</signal>
<receiver>TestGUI</receiver>
<slot>setWindowModified(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>126</x>
<y>144</y>
</hint>
<hint type="destinationlabel">
<x>443</x>
<y>589</y>
</hint>
</hints>
</connection>
</connections> </connections>
</ui> </ui>

@ -1,9 +1,13 @@
#include <testgui.hxx> #include <testgui.hxx>
#include <QApplication> #include <QApplication>
#include <QCommandLineParser> #include <QCommandLineParser>
#include <version.hxx>
int main(int argc, char *argv[]) try { int main(int argc, char *argv[]) try {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setApplicationDisplayName(a.tr("WebTester"));
a.setApplicationName(webtester::package_name().c_str());
a.setApplicationVersion(webtester::version().c_str());
QCommandLineParser parser; QCommandLineParser parser;
parser.addHelpOption(); parser.addHelpOption();
parser.addOption(QCommandLineOption parser.addOption(QCommandLineOption

Loading…
Cancel
Save