ORE Studio 0.0.4
Loading...
Searching...
No Matches
CurrencyMdiWindow.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_MDI_WINDOW_HPP
21#define ORES_QT_CURRENCY_MDI_WINDOW_HPP
22
23#include <QWidget>
24#include <QTableView>
25#include <QVBoxLayout>
26#include <QToolBar>
27#include <QIcon>
28#include <QTimer>
29#include <QSortFilterProxyModel>
30#include <memory>
31#include "ores.qt/ClientManager.hpp"
32#include "ores.utility/log/make_logger.hpp"
33#include "ores.qt/ClientCurrencyModel.hpp"
34#include "ores.qt/PaginationWidget.hpp"
35
36namespace ores::qt {
37
41class CurrencyMdiWindow : public QWidget {
42 Q_OBJECT
43
44private:
45 inline static std::string_view logger_name =
46 "ores.qt.currency_mdi_window";
47
48 [[nodiscard]] static auto& lg() {
49 using namespace ores::utility::log;
50 static auto instance = make_logger(logger_name);
51 return instance;
52 }
53
54public:
55 explicit CurrencyMdiWindow(ClientManager* clientManager,
56 const QString& username,
57 QWidget* parent = nullptr);
58 ~CurrencyMdiWindow() override;
59
60 ClientCurrencyModel* currencyModel() const { return currencyModel_.get(); }
61
62 QSize sizeHint() const override;
63
64signals:
65 void statusChanged(const QString& message);
66 void errorOccurred(const QString& error_message);
67 void selectionChanged(int selection_count);
68 void addNewRequested();
69 void showCurrencyDetails(const risk::domain::currency& currency);
70 void currencyDeleted(const QString& iso_code);
71 void showCurrencyHistory(const QString& iso_code);
72
73public slots:
74 void reload();
75 void addNew();
76 void editSelected();
77 void deleteSelected();
78 void viewHistorySelected();
79 void importFromXML();
80 void exportToCSV();
81 void exportToXML();
82
90 void markAsStale();
91
98
99private slots:
100 void onDataLoaded();
101 void onLoadError(const QString& error_message);
102 void onRowDoubleClicked(const QModelIndex& index);
103 void onSelectionChanged();
104 void onConnectionStateChanged();
105
106private:
107 void updateActionStates();
108 void setupReloadAction();
109 void startPulseAnimation();
110 void stopPulseAnimation();
111
112private:
113 QVBoxLayout* verticalLayout_;
114 QTableView* currencyTableView_;
115 QToolBar* toolBar_;
116 PaginationWidget* pagination_widget_;
117
118 // Reload action with stale indicator
119 QAction* reloadAction_;
120 QIcon normalReloadIcon_;
121 QIcon staleReloadIcon_;
122 QTimer* pulseTimer_;
123 bool pulseState_{false};
124 int pulseCount_{0};
125
126 QAction* addAction_;
127 QAction* editAction_;
128 QAction* deleteAction_;
129 QAction* historyAction_;
130
131 std::unique_ptr<ClientCurrencyModel> currencyModel_;
132 QSortFilterProxyModel* proxyModel_;
133 ClientManager* clientManager_;
134 QString username_;
135 bool isStale_{false};
136};
137
138}
139
140#endif
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Implements logging for ORE Studio.
Definition lifecycle_manager.hpp:30
Model for displaying currencies fetched from the server via client.
Definition ClientCurrencyModel.hpp:41
Manages the lifecycle of the network client and IO context.
Definition ClientManager.hpp:56
MDI window for displaying currencies.
Definition CurrencyMdiWindow.hpp:41
void clearStaleIndicator()
Clear the stale indicator.
Definition CurrencyMdiWindow.cpp:813
void markAsStale()
Mark the data as stale (changed on server).
Definition CurrencyMdiWindow.cpp:804
Widget providing pagination controls for data tables.
Definition PaginationWidget.hpp:38
Represents a currency with its metadata and formatting rules.
Definition currency.hpp:30