/
waterstone
/
json_inspector
Обзор
Документация
Войти
/
waterstone
/
json_inspector
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
mainwindow.cpp
93 строки
2 KB
Peter Sakhno
Udjust data presentation
14 ноя 2025, 10:09
14 ноя 2025, 10:09
a35c7cd
Код
Авторство
О чём код?
#include "mainwindow.h" #include <QDir> #include <QFileInfo> #include <QFileDialog> #include <QMessageBox> #include <QApplication> namespace { static const QString kSettingsSavePathKey("save_path"); static const QString kSettingsOpenPathKey("open_path"); static QString GetSettingsPath() { const QString file_name = QStringLiteral(".") + QFileInfo(QApplication::applicationFilePath()).baseName(); const QDir home_dir = QDir::home(); return home_dir.filePath(file_name); } } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow), m_settings(GetSettingsPath(), QSettings::IniFormat) { m_ui->setupUi(this); m_ui->action_Save->setDisabled(true); } QString MainWindow::GetPath(bool save) const { QString out = QDir::homePath(); QString val = m_settings.value( save ? kSettingsSavePathKey : kSettingsOpenPathKey).toString(); if (!val.isEmpty()) { QFileInfo fi(val); if (fi.exists() && fi.isDir()) out = val; } return out; } void MainWindow::SetPath(bool save, const QString& val) { m_settings.setValue(save ? kSettingsSavePathKey : kSettingsOpenPathKey, QFileInfo(val).path()); } void MainWindow::OnFileOpen() { QString file_name = QFileDialog::getOpenFileName(this, tr("Open JSON File"), GetPath(false), tr("JSON files(*.json);;All files (*.*)")); if (file_name.isEmpty()) return; SetPath(false, file_name); m_ui->centralWidget->OpenJSON(file_name); } void MainWindow::OnFileSave() { if (!m_ui->centralWidget->CanSave()) return; QString file_name = QFileDialog::getSaveFileName(this, tr("Save JSON tags"), GetPath(true)); if (file_name.isEmpty()) return; SetPath(true, file_name); m_ui->action_Save->setEnabled(false); m_ui->centralWidget->SaveJSONTags(file_name); m_ui->action_Save->setEnabled(true); QMessageBox::information(this, tr("Save JSON tags"), tr("JSON tags saved")); } void MainWindow::OnAboutQt() { QApplication::aboutQt(); } void MainWindow::OnJsonLoadingStarted() { m_ui->action_Open->setEnabled(false); } void MainWindow::OnJsonLoadingFinished() { m_ui->action_Open->setEnabled(true); m_ui->action_Save->setEnabled(m_ui->centralWidget->CanSave()); } void MainWindow::closeEvent(QCloseEvent* event) { m_ui->centralWidget->OnCloseApp(); QMainWindow::closeEvent(event); }