ORE Studio 0.0.4
Loading...
Searching...
No Matches
EntityListMdiWindow.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_ENTITY_LIST_MDI_WINDOW_HPP
21#define ORES_QT_ENTITY_LIST_MDI_WINDOW_HPP
22
23#include <string_view>
24#include <QWidget>
25#include <QAction>
26#include <QTimer>
27#include <QIcon>
28#include <QCloseEvent>
29#include <QProgressBar>
30#include <QSplitter>
31#include <QTableView>
32#include "ores.logging/make_logger.hpp"
33#include "ores.qt/AbstractClientModel.hpp"
34
35namespace ores::qt {
36
62class EntityListMdiWindow : public QWidget {
63 Q_OBJECT
64
65private:
66 inline static std::string_view logger_name = "ores.qt.entity_list_mdi_window";
67
68 [[nodiscard]] static auto& lg() {
69 using namespace ores::logging;
70 static auto instance = make_logger(logger_name);
71 return instance;
72 }
73
74public:
75 explicit EntityListMdiWindow(QWidget* parent = nullptr);
76 ~EntityListMdiWindow() override;
77
78 QSize sizeHint() const override;
79
80public slots:
87 void markAsStale();
88
96
103 void reload();
104
105protected:
113 virtual void doReload() = 0;
114
122 virtual void saveSettings();
123
124protected:
125 void closeEvent(QCloseEvent* event) override;
126
141 void initializeTableSettings(QTableView* tableView,
142 QAbstractItemModel* sourceModel,
143 std::string_view settingsGroup,
144 const QVector<int>& defaultHiddenColumns = {},
145 const QSize& defaultSize = {900, 400},
146 int settingsVersion = 1,
147 QSplitter* splitter = nullptr);
148
157 void initializeStaleIndicator(QAction* refreshAction, const QString& iconPath);
158
168 QProgressBar* loadingBar();
169
175 void beginLoading();
176
182 void endLoading();
183
191 void connectModel(AbstractClientModel* model);
192
198 virtual QString normalRefreshTooltip() const { return tr("Refresh"); }
199
205 virtual QString staleRefreshTooltip() const {
206 return tr("Data changed on server - click to reload");
207 }
208
209private slots:
210 void onPulseTimeout();
211
212private:
213 void startPulseAnimation();
214 void setupColumnVisibility();
215 void showHeaderContextMenu(const QPoint& pos);
216 void restoreTableSettings();
217
218 // Stale indicator members
219 QAction* refreshAction_{nullptr};
220 QTimer* pulseTimer_{nullptr};
221 QIcon normalReloadIcon_;
222 QIcon pulseReloadIcon_;
223 bool pulseState_{false};
224 int pulseCount_{0};
225
226 // Loading indicator
227 QProgressBar* loadingBar_{nullptr};
228
229 // Table settings members
230 QTableView* settingsTableView_{nullptr};
231 QAbstractItemModel* settingsModel_{nullptr};
232 QString settingsGroup_;
233 QVector<int> defaultHiddenColumns_;
234 QSize defaultSize_{900, 400};
235 int settingsVersion_{1};
236 QSplitter* settingsSplitter_{nullptr};
237
238protected:
246};
247
248}
249
250#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:29
QVector< int > defaultHiddenColumns(const std::array< ColumnMetadata, N > &columns)
Builds a QVector of hidden column indices from a metadata array.
Definition ColumnMetadata.hpp:98
Base class for entity list MDI windows providing stale indicator support.
Definition EntityListMdiWindow.hpp:62
QProgressBar * loadingBar()
Return the shared loading progress bar.
Definition EntityListMdiWindow.cpp:109
virtual QString staleRefreshTooltip() const
Get the stale tooltip text for the refresh action.
Definition EntityListMdiWindow.hpp:205
void clearStaleIndicator()
Clear the stale indicator.
Definition EntityListMdiWindow.cpp:69
void initializeTableSettings(QTableView *tableView, QAbstractItemModel *sourceModel, std::string_view settingsGroup, const QVector< int > &defaultHiddenColumns={}, const QSize &defaultSize={900, 400}, int settingsVersion=1, QSplitter *splitter=nullptr)
Configure table header, column visibility, and settings persistence.
Definition EntityListMdiWindow.cpp:130
virtual void doReload()=0
Subclass implementation of the reload operation.
void beginLoading()
Show the loading bar and disable the reload action.
Definition EntityListMdiWindow.cpp:120
void markAsStale()
Mark the list as stale (data changed on server).
Definition EntityListMdiWindow.cpp:58
virtual QString normalRefreshTooltip() const
Get the normal (non-stale) tooltip text for the refresh action.
Definition EntityListMdiWindow.hpp:198
QSize savedWindowSize_
Saved window size from QSettings.
Definition EntityListMdiWindow.hpp:245
virtual void saveSettings()
Save window settings (column visibility, window size, etc.).
Definition EntityListMdiWindow.cpp:165
void initializeStaleIndicator(QAction *refreshAction, const QString &iconPath)
Initialize the stale indicator support.
Definition EntityListMdiWindow.cpp:46
void reload()
Reload data from the server.
Definition EntityListMdiWindow.cpp:103
void connectModel(AbstractClientModel *model)
Wire endLoading() to the model's standard lifecycle signals.
Definition EntityListMdiWindow.cpp:227
void endLoading()
Hide the loading bar and re-enable the reload action.
Definition EntityListMdiWindow.cpp:125