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.api/domain/currency.hpp"
29#include "ores.refdata.api/messaging/currency_history_protocol.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 CurrencyDetailDialog final : public DetailDialogBase {
44 Q_OBJECT
45
46private:
47 inline static std::string_view logger_name =
48 "ores.qt.currency_detail_dialog";
49
50 [[nodiscard]] static auto& lg() {
51 using namespace ores::logging;
52 static auto instance = make_logger(logger_name);
53 return instance;
54 }
55
56public:
57 explicit CurrencyDetailDialog(QWidget* parent = nullptr);
58 ~CurrencyDetailDialog() override;
59
60 void setClientManager(ClientManager* clientManager);
61 void setUsername(const std::string& username);
62 void setImageCache(ImageCache* imageCache);
63
64 void setCurrency(const refdata::domain::currency& currency);
65 [[nodiscard]] refdata::domain::currency getCurrency() const;
66 void clearDialog();
67 void save();
68
82 void setReadOnly(bool readOnly, int versionNumber = 0);
83
94 void setHistory(const refdata::messaging::currency_version_history& history,
95 int versionNumber);
96
104 void markAsStale();
105
109 [[nodiscard]] QString isoCode() const;
110
111protected:
112 QTabWidget* tabWidget() const override;
113 QWidget* provenanceTab() const override;
114 ProvenanceWidget* provenanceWidget() const override;
115 bool hasUnsavedChanges() const override { return isDirty_; }
116
117signals:
118 void currencyUpdated(const QString& iso_code);
119 void currencyCreated(const QString& iso_code);
120 void currencyDeleted(const QString& iso_code);
121 void isDirtyChanged(bool isDirty);
122 void showRoundingTypesRequested();
123 void showMonetaryNaturesRequested();
124 void showMarketTiersRequested();
125
130 void revertRequested(const refdata::domain::currency& currency);
131
132private slots:
133 void onSaveClicked();
134 void onResetClicked();
135 void onDeleteClicked();
136 void onRevertClicked();
137 void onFieldChanged();
138 void onSelectFlagClicked();
139 void onCurrencyImageSet(const QString& iso_code, bool success, const QString& message);
140 void onGenerateClicked();
141
142 // Version navigation slots
143 void onFirstVersionClicked();
144 void onPrevVersionClicked();
145 void onNextVersionClicked();
146 void onLastVersionClicked();
147
148 void onSystemSettingNotification(const QString& eventType, const QDateTime& timestamp,
149 const QStringList& entityIds);
150 void onConnectionEstablished();
151
152private:
153 void updateSaveResetButtonState();
154 void setFieldsReadOnly(bool readOnly);
155 void updateFlagDisplay();
156 void displayCurrentVersion();
157 void updateVersionNavButtonStates();
158 void showVersionNavActions(bool visible);
159 void setupGenerateAction();
160 void updateGenerateActionVisibility();
161 void populateRoundingTypeCombo();
162 void populateMonetaryNatureCombo();
163 void populateMarketTierCombo();
164
165private:
166 std::unique_ptr<Ui::CurrencyDetailDialog> ui_;
167 bool isDirty_;
168 bool isAddMode_;
169 bool isReadOnly_;
170 bool isStale_;
171 bool flagChanged_;
172 int historicalVersion_;
173 std::string username_;
174 QToolBar* toolBar_;
175 QAction* revertAction_;
176 QAction* generateAction_;
177 QPushButton* flagButton_;
178
179 ClientManager* clientManager_;
180 ImageCache* imageCache_;
181 QAction* isoCodeFlagAction_{nullptr};
182 refdata::domain::currency currentCurrency_;
183 QString pendingImageId_;
184 static constexpr const char* max_timestamp = "9999-12-31 23:59:59";
185
186 // Version navigation members
187 refdata::messaging::currency_version_history history_;
188 int currentHistoryIndex_;
189 QAction* firstVersionAction_;
190 QAction* prevVersionAction_;
191 QAction* nextVersionAction_;
192 QAction* lastVersionAction_;
193};
194
195}
196
197#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
Represents a currency with its metadata and formatting rules.
Definition currency.hpp:34