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.api/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 CountryDetailDialog final : public DetailDialogBase {
43 Q_OBJECT
44
45private:
46 inline static std::string_view logger_name =
47 "ores.qt.country_detail_dialog";
48
49 [[nodiscard]] static auto& lg() {
50 using namespace ores::logging;
51 static auto instance = make_logger(logger_name);
52 return instance;
53 }
54
55public:
56 explicit CountryDetailDialog(QWidget* parent = nullptr);
57 ~CountryDetailDialog() override;
58
59 void setClientManager(ClientManager* clientManager);
60 void setUsername(const std::string& username);
61 void setImageCache(ImageCache* imageCache);
62
63 void setCountry(const refdata::domain::country& country);
64 [[nodiscard]] refdata::domain::country getCountry() const;
65 void clearDialog();
66 void save();
67
81 void setReadOnly(bool readOnly, int versionNumber = 0);
82
93 void setHistory(const std::vector<refdata::domain::country>& history,
94 int versionNumber);
95
103 void markAsStale();
104
108 [[nodiscard]] QString alpha2Code() const;
109
110protected:
111 QTabWidget* tabWidget() const override;
112 QWidget* provenanceTab() const override;
113 ProvenanceWidget* provenanceWidget() const override;
114 bool hasUnsavedChanges() const override { return isDirty_; }
115
116signals:
117 void countryUpdated(const QString& alpha2_code);
118 void countryCreated(const QString& alpha2_code);
119 void countryDeleted(const QString& alpha2_code);
120 void isDirtyChanged(bool isDirty);
121
126 void revertRequested(const refdata::domain::country& country);
127
128private slots:
129 void onSaveClicked();
130 void onResetClicked();
131 void onDeleteClicked();
132 void onRevertClicked();
133 void onFieldChanged();
134 void onSelectFlagClicked();
135 void onCountryImageSet(const QString& alpha2_code, bool success, const QString& message);
136
137 // Version navigation slots
138 void onFirstVersionClicked();
139 void onPrevVersionClicked();
140 void onNextVersionClicked();
141 void onLastVersionClicked();
142
143private:
144 void updateSaveResetButtonState();
145 void setFieldsReadOnly(bool readOnly);
146 void updateFlagDisplay();
147 void displayCurrentVersion();
148 void updateVersionNavButtonStates();
149 void showVersionNavActions(bool visible);
150
151private:
152 std::unique_ptr<Ui::CountryDetailDialog> ui_;
153 bool isDirty_;
154 bool isAddMode_;
155 bool isReadOnly_;
156 bool isStale_;
157 bool flagChanged_;
158 int historicalVersion_;
159 std::string username_;
160 QToolBar* toolBar_;
161 QAction* revertAction_;
162 QPushButton* flagButton_;
163
164 ClientManager* clientManager_;
165 ImageCache* imageCache_;
166 QAction* alpha2FlagAction_{nullptr};
167 refdata::domain::country currentCountry_;
168 QString pendingImageId_;
169
170 // Version navigation members
171 std::vector<refdata::domain::country> history_;
172 int currentHistoryIndex_;
173 QAction* firstVersionAction_;
174 QAction* prevVersionAction_;
175 QAction* nextVersionAction_;
176 QAction* lastVersionAction_;
177};
178
179}
180
181#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Represents a country using ISO 3166-1 standard codes.
Definition country.hpp:34