Add settings to enable/disable status bar logging

This commit is contained in:
GriffinR 2025-05-04 22:14:30 -04:00
parent 7511f445bd
commit eaceb45592
7 changed files with 79 additions and 2 deletions

View File

@ -80,6 +80,43 @@
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_Logging">
<property name="title">
<string>Logging</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_StatusMessages">
<property name="text">
<string>Status bar message types</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_StatusErrors">
<property name="text">
<string>Errors</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_StatusWarnings">
<property name="text">
<string>Warnings</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_StatusInformation">
<property name="text">
<string>Information</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">

View File

@ -12,6 +12,7 @@
#include <QUrl>
#include <QVersionNumber>
#include <QGraphicsPixmapItem>
#include <set>
#include "events.h"
#include "gridsettings.h"
@ -96,6 +97,7 @@ public:
this->eventSelectionShapeMode = QGraphicsPixmapItem::MaskShape;
this->shownInGameReloadMessage = false;
this->gridSettings = GridSettings();
this->statusBarLogTypes = { LogType::LOG_ERROR, LogType::LOG_WARN };
}
void addRecentProject(QString project);
void setRecentProjects(QStringList projects);
@ -161,6 +163,8 @@ public:
QByteArray newLayoutDialogGeometry;
bool shownInGameReloadMessage;
GridSettings gridSettings;
// Prefer over QSet to prevent shuffling elements when writing the config file.
std::set<LogType> statusBarLogTypes;
protected:
virtual QString getConfigFilepath() override;

View File

@ -398,6 +398,7 @@ private:
void updateWindowTitle();
void initWindow();
void initLogStatusBar();
void initCustomUI();
void initExtraSignals();
void initEditor();

View File

@ -476,6 +476,13 @@ void PorymapConfig::parseConfigKeyValue(QString key, QString value) {
this->gridSettings.style = GridSettings::getStyleFromName(value);
} else if (key == "grid_color") {
this->gridSettings.color = getConfigColor(key, value);
} else if (key == "status_bar_log_types") {
this->statusBarLogTypes.clear();
auto typeStrings = value.split(",", Qt::SkipEmptyParts);
for (const auto &typeString : typeStrings) {
LogType type = static_cast<LogType>(getConfigInteger(key, typeString, 0, 2));
this->statusBarLogTypes.insert(type);
}
} else {
logWarn(QString("Invalid config key found in config file %1: '%2'").arg(this->getConfigFilepath()).arg(key));
}
@ -559,6 +566,12 @@ QMap<QString, QString> PorymapConfig::getKeyValueMap() {
map.insert("grid_y", QString::number(this->gridSettings.offsetY));
map.insert("grid_style", GridSettings::getStyleName(this->gridSettings.style));
map.insert("grid_color", this->gridSettings.color.name().remove("#")); // Our text config treats '#' as the start of a comment.
QStringList logTypesStrings;
for (const auto &type : this->statusBarLogTypes) {
logTypesStrings.append(QString::number(type));
}
map.insert("status_bar_log_types", logTypesStrings.join(","));
return map;
}

View File

@ -110,6 +110,7 @@ void updateLogDisplays(const QString &message, LogType type) {
{LogType::LOG_ERROR, QPixmap(QStringLiteral(":/icons/error.ico"))},
};
bool startTimer = false;
auto it = QMutableListIterator(Log::displays);
while (it.hasNext()) {
auto display = it.next();
@ -123,11 +124,12 @@ void updateLogDisplays(const QString &message, LogType type) {
display.icon->setPixmap(icons.value(type));
display.statusBar->clearMessage();
display.message->setText(message);
startTimer = true;
}
}
// Auto-hide status bar messages after a set period of time
Log::displayClearTimer.start(5000);
if (startTimer) Log::displayClearTimer.start(5000);
}
void clearLogDisplays() {

View File

@ -75,7 +75,6 @@ MainWindow::MainWindow(QWidget *parent) :
ui->setupUi(this);
logInit();
addLogStatusBar(this->statusBar(), {LOG_ERROR, LOG_WARN});
logInfo(QString("Launching Porymap v%1").arg(QCoreApplication::applicationVersion()));
}
@ -144,6 +143,7 @@ void MainWindow::setWindowDisabled(bool disabled) {
void MainWindow::initWindow() {
porymapConfig.load();
this->initLogStatusBar();
this->initCustomUI();
this->initExtraSignals();
this->initEditor();
@ -239,6 +239,14 @@ void MainWindow::applyUserShortcuts() {
shortcut->setKeys(shortcutsConfig.userShortcuts(shortcut));
}
void MainWindow::initLogStatusBar() {
removeLogStatusBar(this->statusBar());
QSet logTypes = QSet(porymapConfig.statusBarLogTypes.begin(), porymapConfig.statusBarLogTypes.end());
if (!logTypes.isEmpty()) {
addLogStatusBar(this->statusBar(), logTypes);
}
}
void MainWindow::initCustomUI() {
static const QMap<int, QString> mainTabNames = {
{MainTab::Map, "Map"},
@ -2921,6 +2929,7 @@ void MainWindow::on_actionPreferences_triggered() {
connect(preferenceEditor, &PreferenceEditor::themeChanged, this, &MainWindow::setTheme);
connect(preferenceEditor, &PreferenceEditor::themeChanged, editor, &Editor::maskNonVisibleConnectionTiles);
connect(preferenceEditor, &PreferenceEditor::preferencesSaved, this, &MainWindow::togglePreferenceSpecificUi);
connect(preferenceEditor, &PreferenceEditor::preferencesSaved, this, &MainWindow::initLogStatusBar);
// Changes to porymapConfig.loadAllEventScripts or porymapConfig.eventSelectionShapeMode
// require us to repopulate the EventFrames and redraw event pixmaps, respectively.
connect(preferenceEditor, &PreferenceEditor::preferencesSaved, editor, &Editor::updateEvents);

View File

@ -57,6 +57,11 @@ void PreferenceEditor::updateFields() {
ui->checkBox_CheckForUpdates->setChecked(porymapConfig.checkForUpdates);
ui->checkBox_DisableEventWarning->setChecked(porymapConfig.eventDeleteWarningDisabled);
ui->checkBox_AutocompleteAllScripts->setChecked(porymapConfig.loadAllEventScripts);
auto logTypeEnd = porymapConfig.statusBarLogTypes.end();
ui->checkBox_StatusErrors->setChecked(porymapConfig.statusBarLogTypes.find(LogType::LOG_ERROR) != logTypeEnd);
ui->checkBox_StatusWarnings->setChecked(porymapConfig.statusBarLogTypes.find(LogType::LOG_WARN) != logTypeEnd);
ui->checkBox_StatusInformation->setChecked(porymapConfig.statusBarLogTypes.find(LogType::LOG_INFO) != logTypeEnd);
}
void PreferenceEditor::saveFields() {
@ -77,6 +82,12 @@ void PreferenceEditor::saveFields() {
porymapConfig.reopenOnLaunch = ui->checkBox_OpenRecentProject->isChecked();
porymapConfig.checkForUpdates = ui->checkBox_CheckForUpdates->isChecked();
porymapConfig.eventDeleteWarningDisabled = ui->checkBox_DisableEventWarning->isChecked();
porymapConfig.statusBarLogTypes.clear();
if (ui->checkBox_StatusErrors->isChecked()) porymapConfig.statusBarLogTypes.insert(LogType::LOG_ERROR);
if (ui->checkBox_StatusWarnings->isChecked()) porymapConfig.statusBarLogTypes.insert(LogType::LOG_WARN);
if (ui->checkBox_StatusInformation->isChecked()) porymapConfig.statusBarLogTypes.insert(LogType::LOG_INFO);
porymapConfig.save();
emit preferencesSaved();