ORE Studio 0.0.4
Loading...
Searching...
No Matches
CountryHistoryDialog.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2025 Marco Craveiro <marco.craveiro@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc., 51
17 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 *
19 */
20#ifndef ORES_QT_COUNTRY_HISTORY_DIALOG_HPP
21#define ORES_QT_COUNTRY_HISTORY_DIALOG_HPP
22
23#include <memory>
24#include <QPair>
25#include <QWidget>
26#include <QString>
27#include <QVector>
28#include <QToolBar>
29#include <QAction>
30#include "ores.qt/ClientManager.hpp"
31#include "ores.qt/ImageCache.hpp"
32#include "ores.refdata/domain/country.hpp"
33#include "ores.logging/make_logger.hpp"
34#include "ui_CountryHistoryDialog.h"
35
36namespace Ui {
37class CountryHistoryDialog;
38}
39
40namespace ores::qt {
41
45class CountryHistoryDialog : public QWidget {
46 Q_OBJECT
47
48private:
49 inline static std::string_view logger_name =
50 "ores.qt.country_history_dialog";
51
52 [[nodiscard]] static auto& lg() {
53 using namespace ores::logging;
54 static auto instance = make_logger(logger_name);
55 return instance;
56 }
57
58 const QIcon& getHistoryIcon() const;
59
60public:
61 explicit CountryHistoryDialog(QString alpha2_code,
62 ClientManager* clientManager,
63 QWidget* parent = nullptr);
64 ~CountryHistoryDialog() override;
65
66 void loadHistory();
67
71 void setImageCache(ImageCache* imageCache);
72
73 QSize sizeHint() const override;
74
81 void markAsStale();
82
86 [[nodiscard]] QString alpha2Code() const { return alpha2Code_; }
87
91 [[nodiscard]] const std::vector<refdata::domain::country>& getHistory() const {
92 return history_;
93 }
94
95signals:
96 void statusChanged(const QString& message);
97 void errorOccurred(const QString& error_message);
98
104 void openVersionRequested(const refdata::domain::country& country, int versionNumber);
105
111
112private slots:
113 void onVersionSelected(int index);
114 void onHistoryLoaded();
115 void onHistoryLoadError(const QString& error);
116 void onOpenClicked();
117 void onRevertClicked();
118 void onReloadClicked();
119
120private:
121 void displayChangesTab(int version_index);
122 void displayFullDetailsTab(int version_index);
123
129 using DiffResult = QVector<QPair<QString, QPair<QString, QString>>>;
130 DiffResult calculateDiff(
131 const refdata::domain::country& current,
132 const refdata::domain::country& previous);
133
134 void setupToolbar();
135 void updateButtonStates();
136 int selectedVersionIndex() const;
137
138 std::unique_ptr<Ui::CountryHistoryDialog> ui_;
139 ClientManager* clientManager_;
140 ImageCache* imageCache_;
141 QString alpha2Code_;
142 std::vector<refdata::domain::country> history_;
143
144 QToolBar* toolBar_;
145 QAction* reloadAction_;
146 QAction* openAction_;
147 QAction* revertAction_;
148};
149
150}
151
152#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:90
Widget for displaying country version history.
Definition CountryHistoryDialog.hpp:45
void markAsStale()
Mark the history data as stale and reload.
Definition CountryHistoryDialog.cpp:513
const std::vector< refdata::domain::country > & getHistory() const
Returns the loaded history vector for version navigation.
Definition CountryHistoryDialog.hpp:91
void openVersionRequested(const refdata::domain::country &country, int versionNumber)
Emitted when user requests to open a version in read-only mode.
void revertVersionRequested(const refdata::domain::country &country)
Emitted when user requests to revert to a selected version.
QString alpha2Code() const
Returns the alpha-2 code of the country.
Definition CountryHistoryDialog.hpp:86
void setImageCache(ImageCache *imageCache)
Set the image cache for displaying country flags.
Definition CountryHistoryDialog.cpp:524
Cache for dynamically loaded images (flags, icons) from the server.
Definition ImageCache.hpp:52
Represents a country using ISO 3166-1 standard codes.
Definition country.hpp:33