Simplify mainwindow title logic: remove MainWindowTitleFormat enum

The MainWindow::setTitle() function was passed an enum, which depended
on whether existing_file is set or not. The check can be (and was!) done
directly in setTitle(). Therefore, remove the whole enum.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2017-12-11 17:43:53 +01:00 committed by Dirk Hohndel
parent 931bcc1966
commit 4ac5b9c965
3 changed files with 13 additions and 27 deletions

View file

@ -610,7 +610,7 @@ void MainWindow::on_actionCloudstorageopen_triggered()
QByteArray fileNamePtr = QFile::encodeName(filename);
if (!parse_file(fileNamePtr.data())) {
set_filename(fileNamePtr.data());
setTitle(MWTF_FILENAME);
setTitle();
}
getNotificationWidget()->hideNotification();
process_dives(false, false);
@ -641,7 +641,7 @@ void MainWindow::on_actionCloudstoragesave_triggered()
return;
set_filename(filename.toUtf8().data());
setTitle(MWTF_FILENAME);
setTitle();
mark_divelist_changed(false);
}
@ -692,7 +692,7 @@ void MainWindow::cleanUpEmpty()
dive_list()->reload(DiveTripModel::TREE);
MapWidget::instance()->reload();
if (!existing_filename)
setTitle(MWTF_DEFAULT);
setTitle();
disableShortcuts();
}
@ -1654,7 +1654,7 @@ int MainWindow::file_save_as(void)
return -1;
set_filename(filename.toUtf8().data());
setTitle(MWTF_FILENAME);
setTitle();
mark_divelist_changed(false);
addRecentFile(filename, true);
return 0;
@ -1725,21 +1725,15 @@ void MainWindow::setAutomaticTitle()
setTitle();
}
void MainWindow::setTitle(enum MainWindowTitleFormat format)
void MainWindow::setTitle()
{
switch (format) {
case MWTF_DEFAULT:
if (!existing_filename || !existing_filename[0]) {
setWindowTitle("Subsurface");
break;
case MWTF_FILENAME:
if (!existing_filename) {
setTitle(MWTF_DEFAULT);
return;
}
QString unsaved = (unsaved_changes() ? " *" : "");
setWindowTitle("Subsurface: " + displayedFilename(existing_filename) + unsaved);
break;
return;
}
QString unsaved = (unsaved_changes() ? " *" : "");
setWindowTitle("Subsurface: " + displayedFilename(existing_filename) + unsaved);
}
void MainWindow::importFiles(const QStringList fileNames)
@ -1801,7 +1795,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
if (!parse_file(fileNamePtr.data())) {
set_filename(fileNamePtr.data());
addRecentFile(fileNamePtr, false);
setTitle(MWTF_FILENAME);
setTitle();
}
}
hideProgressBar();

View file

@ -41,11 +41,6 @@ class LocationInformationWidget;
typedef std::pair<QByteArray, QVariant> WidgetProperty;
typedef QVector<WidgetProperty> PropertyList;
enum MainWindowTitleFormat {
MWTF_DEFAULT,
MWTF_FILENAME
};
class MainWindow : public QMainWindow {
Q_OBJECT
public:
@ -74,7 +69,7 @@ public:
DivePlannerWidget *divePlannerWidget();
PlannerSettingsWidget *divePlannerSettingsWidget();
LocationInformationWidget *locationInformationWidget();
void setTitle(enum MainWindowTitleFormat format = MWTF_FILENAME);
void setTitle();
void loadFiles(const QStringList files);
void importFiles(const QStringList importFiles);

View file

@ -33,10 +33,7 @@ void init_ui()
PluginManager::instance().loadPlugins();
window = new MainWindow();
if (existing_filename && existing_filename[0] != '\0')
window->setTitle(MWTF_FILENAME);
else
window->setTitle(MWTF_DEFAULT);
window->setTitle();
}
void run_ui()