ORE Studio 0.0.4
Loading...
Searching...
No Matches
CurrencyDetailDialog.hpp
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * Copyright (C) 2024 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_DETAIL_DIALOG_HPP
21#define ORES_QT_CURRENCY_DETAIL_DIALOG_HPP
22
23#include <QToolBar>
24#include <QAction>
25#include <QPushButton>
26#include <memory>
27#include <vector>
28#include "ores.refdata/domain/currency.hpp"
29#include "ores.refdata/domain/currency_version_history.hpp"
30#include "ores.qt/ClientManager.hpp"
31#include "ores.qt/DetailDialogBase.hpp"
32#include "ores.qt/ImageCache.hpp"
33#include "ores.logging/make_logger.hpp"
34
35namespace Ui {
36
37class CurrencyDetailDialog;
38
39}
40
41namespace ores::qt {
42
43class ChangeReasonCache;
44
45class CurrencyDetailDialog final : public DetailDialogBase {
46 Q_OBJECT
47
48private:
49 inline static std::string_view logger_name =
50 "ores.qt.currency_detail_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
58public:
59 explicit CurrencyDetailDialog(QWidget* parent = nullptr);
60 ~CurrencyDetailDialog() override;
61
62 void setClientManager(ClientManager* clientManager);
63 void setUsername(const std::string& username);
64 void setImageCache(ImageCache* imageCache);
65 void setChangeReasonCache(ChangeReasonCache* changeReasonCache);
66
67 void setCurrency(const refdata::domain::currency& currency);
68 [[nodiscard]] refdata::domain::currency getCurrency() const;
69 void clearDialog();
70 void save();
71
85 void setReadOnly(bool readOnly, int versionNumber = 0);
86
97 void setHistory(const refdata::domain::currency_version_history& history,
98 int versionNumber);
99
107 void markAsStale();
108
112 [[nodiscard]] QString isoCode() const;
113
114signals:
115 void currencyUpdated(const QString& iso_code);
116 void currencyCreated(const QString& iso_code);
117 void currencyDeleted(const QString& iso_code);
118 void isDirtyChanged(bool isDirty);
119
124 void revertRequested(const refdata::domain::currency& currency);
125
126private slots:
127 void onSaveClicked();
128 void onResetClicked();
129 void onDeleteClicked();
130 void onRevertClicked();
131 void onFieldChanged();
132 void onSelectFlagClicked();
133 void onCurrencyImageSet(const QString& iso_code, bool success, const QString& message);
134 void onGenerateClicked();
135
136 // Version navigation slots
137 void onFirstVersionClicked();
138 void onPrevVersionClicked();
139 void onNextVersionClicked();
140 void onLastVersionClicked();
141
142 void onFeatureFlagNotification(const QString& eventType, const QDateTime& timestamp,
143 const QStringList& entityIds);
144 void onConnectionEstablished();
145
146private:
147 void updateSaveResetButtonState();
148 void setFieldsReadOnly(bool readOnly);
149 void updateFlagDisplay();
150 void displayCurrentVersion();
151 void updateVersionNavButtonStates();
152 void showVersionNavActions(bool visible);
153 void setupGenerateAction();
154 void updateGenerateActionVisibility();
155
156private:
157 std::unique_ptr<Ui::CurrencyDetailDialog> ui_;
158 bool isDirty_;
159 bool isAddMode_;
160 bool isReadOnly_;
161 bool isStale_;
162 bool flagChanged_;
163 int historicalVersion_;
164 std::string username_;
165 QToolBar* toolBar_;
166 QAction* saveAction_;
167 QAction* deleteAction_;
168 QAction* revertAction_;
169 QAction* generateAction_;
170 QPushButton* flagButton_;
171
172 ClientManager* clientManager_;
173 ImageCache* imageCache_;
174 ChangeReasonCache* changeReasonCache_;
175 refdata::domain::currency currentCurrency_;
176 QString pendingImageId_;
177 static constexpr const char* max_timestamp = "9999-12-31 23:59:59";
178
179 // Version navigation members
181 int currentHistoryIndex_;
182 QAction* firstVersionAction_;
183 QAction* prevVersionAction_;
184 QAction* nextVersionAction_;
185 QAction* lastVersionAction_;
186};
187
188}
189
190#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Represents a currency with its metadata and formatting rules.
Definition currency.hpp:33
Contains the full version history for a currency.
Definition currency_version_history.hpp:32