ORE Studio 0.0.4
Loading...
Searching...
No Matches
CurrencyHistoryDialog.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_CURRENCY_HISTORY_DIALOG_HPP
21#define ORES_QT_CURRENCY_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/currency_version.hpp"
33#include "ores.refdata/domain/currency_version_history.hpp"
34#include "ores.logging/make_logger.hpp"
35#include "ui_CurrencyHistoryDialog.h"
36
37namespace Ui {
38class CurrencyHistoryDialog;
39}
40
41namespace ores::qt {
42
46class CurrencyHistoryDialog : public QWidget {
47 Q_OBJECT
48
49private:
50 inline static std::string_view logger_name =
51 "ores.qt.currency_history_dialog";
52
53 [[nodiscard]] static auto& lg() {
54 using namespace ores::logging;
55 static auto instance = make_logger(logger_name);
56 return instance;
57 }
58
59 const QIcon& getHistoryIcon() const;
60
61public:
62 explicit CurrencyHistoryDialog(QString iso_code,
63 ClientManager* clientManager,
64 QWidget* parent = nullptr);
65 ~CurrencyHistoryDialog() override;
66
67 void loadHistory();
68
72 void setImageCache(ImageCache* imageCache);
73
74 QSize sizeHint() const override; // Provide optimal size based on table content
75
82 void markAsStale();
83
87 [[nodiscard]] QString isoCode() const { return isoCode_; }
88
93 return history_;
94 }
95
96signals:
97 void statusChanged(const QString& message);
98 void errorOccurred(const QString& error_message);
99
105 void openVersionRequested(const refdata::domain::currency& currency, int versionNumber);
106
112
113private slots:
114 void onVersionSelected(int index);
115 void onHistoryLoaded();
116 void onHistoryLoadError(const QString& error);
117 void onOpenClicked();
118 void onRevertClicked();
119 void onReloadClicked();
120
121private:
122 void displayChangesTab(int version_index);
123 void displayFullDetailsTab(int version_index);
124
130 using DiffResult = QVector<QPair<QString, QPair<QString, QString>>>;
131 DiffResult calculateDiff(
133 const refdata::domain::currency_version& previous);
134
135 void setupToolbar();
136 void updateButtonStates();
137 int selectedVersionIndex() const;
138
139 std::unique_ptr<Ui::CurrencyHistoryDialog> ui_;
140 ClientManager* clientManager_;
141 ImageCache* imageCache_;
142 QString isoCode_;
144
145 QToolBar* toolBar_;
146 QAction* reloadAction_;
147 QAction* openAction_;
148 QAction* revertAction_;
149};
150
151}
152
153#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 currency version history.
Definition CurrencyHistoryDialog.hpp:46
const refdata::domain::currency_version_history & getHistory() const
Returns the loaded history for version navigation.
Definition CurrencyHistoryDialog.hpp:92
QString isoCode() const
Returns the ISO code of the currency.
Definition CurrencyHistoryDialog.hpp:87
void markAsStale()
Mark the history data as stale and reload.
Definition CurrencyHistoryDialog.cpp:540
void setImageCache(ImageCache *imageCache)
Set the image cache for displaying currency flags.
Definition CurrencyHistoryDialog.cpp:551
void openVersionRequested(const refdata::domain::currency &currency, int versionNumber)
Emitted when user requests to open a version in read-only mode.
void revertVersionRequested(const refdata::domain::currency &currency)
Emitted when user requests to revert to a selected version.
Cache for dynamically loaded images (flags, icons) from the server.
Definition ImageCache.hpp:52
Represents a currency with its metadata and formatting rules.
Definition currency.hpp:33
Represents a specific version of a currency with metadata.
Definition currency_version.hpp:32
Contains the full version history for a currency.
Definition currency_version_history.hpp:32