ORE Studio 0.0.4
Loading...
Searching...
No Matches
CountryDetailDialog.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_DETAIL_DIALOG_HPP
21#define ORES_QT_COUNTRY_DETAIL_DIALOG_HPP
22
23#include <QToolBar>
24#include <QAction>
25#include <QPushButton>
26#include <memory>
27#include <vector>
28#include "ores.refdata/domain/country.hpp"
29#include "ores.qt/ClientManager.hpp"
30#include "ores.qt/DetailDialogBase.hpp"
31#include "ores.qt/ImageCache.hpp"
32#include "ores.logging/make_logger.hpp"
33
34namespace Ui {
35
36class CountryDetailDialog;
37
38}
39
40namespace ores::qt {
41
42class ChangeReasonCache;
43
44class CountryDetailDialog final : public DetailDialogBase {
45 Q_OBJECT
46
47private:
48 inline static std::string_view logger_name =
49 "ores.qt.country_detail_dialog";
50
51 [[nodiscard]] static auto& lg() {
52 using namespace ores::logging;
53 static auto instance = make_logger(logger_name);
54 return instance;
55 }
56
57public:
58 explicit CountryDetailDialog(QWidget* parent = nullptr);
59 ~CountryDetailDialog() override;
60
61 void setClientManager(ClientManager* clientManager);
62 void setUsername(const std::string& username);
63 void setImageCache(ImageCache* imageCache);
64 void setChangeReasonCache(ChangeReasonCache* changeReasonCache);
65
66 void setCountry(const refdata::domain::country& country);
67 [[nodiscard]] refdata::domain::country getCountry() const;
68 void clearDialog();
69 void save();
70
84 void setReadOnly(bool readOnly, int versionNumber = 0);
85
96 void setHistory(const std::vector<refdata::domain::country>& history,
97 int versionNumber);
98
106 void markAsStale();
107
111 [[nodiscard]] QString alpha2Code() const;
112
113signals:
114 void countryUpdated(const QString& alpha2_code);
115 void countryCreated(const QString& alpha2_code);
116 void countryDeleted(const QString& alpha2_code);
117 void isDirtyChanged(bool isDirty);
118
123 void revertRequested(const refdata::domain::country& country);
124
125private slots:
126 void onSaveClicked();
127 void onResetClicked();
128 void onDeleteClicked();
129 void onRevertClicked();
130 void onFieldChanged();
131 void onSelectFlagClicked();
132 void onCountryImageSet(const QString& alpha2_code, bool success, const QString& message);
133
134 // Version navigation slots
135 void onFirstVersionClicked();
136 void onPrevVersionClicked();
137 void onNextVersionClicked();
138 void onLastVersionClicked();
139
140private:
141 void updateSaveResetButtonState();
142 void setFieldsReadOnly(bool readOnly);
143 void updateFlagDisplay();
144 void displayCurrentVersion();
145 void updateVersionNavButtonStates();
146 void showVersionNavActions(bool visible);
147
148private:
149 std::unique_ptr<Ui::CountryDetailDialog> ui_;
150 bool isDirty_;
151 bool isAddMode_;
152 bool isReadOnly_;
153 bool isStale_;
154 bool flagChanged_;
155 int historicalVersion_;
156 std::string username_;
157 QToolBar* toolBar_;
158 QAction* saveAction_;
159 QAction* deleteAction_;
160 QAction* revertAction_;
161 QPushButton* flagButton_;
162
163 ClientManager* clientManager_;
164 ImageCache* imageCache_;
165 ChangeReasonCache* changeReasonCache_;
166 refdata::domain::country currentCountry_;
167 QString pendingImageId_;
168
169 // Version navigation members
170 std::vector<refdata::domain::country> history_;
171 int currentHistoryIndex_;
172 QAction* firstVersionAction_;
173 QAction* prevVersionAction_;
174 QAction* nextVersionAction_;
175 QAction* lastVersionAction_;
176};
177
178}
179
180#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 country using ISO 3166-1 standard codes.
Definition country.hpp:33