ORE Studio 0.0.4
Loading...
Searching...
No Matches
PaginationWidget.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_PAGINATION_WIDGET_HPP
21#define ORES_QT_PAGINATION_WIDGET_HPP
22
23#include <QWidget>
24#include <QLabel>
25#include <QAction>
26#include <QToolBar>
27#include <QComboBox>
28#include <QHBoxLayout>
29#include "ores.logging/make_logger.hpp"
30#include "ores.qt/export.hpp"
31
32namespace ores::qt {
33
40class ORES_QT_API PaginationWidget : public QWidget {
41 Q_OBJECT
42
43private:
44 inline static std::string_view logger_name =
45 "ores.qt.pagination_widget";
46
47 [[nodiscard]] static auto& lg() {
48 using namespace ores::logging;
49 static auto instance = make_logger(logger_name);
50 return instance;
51 }
52
53public:
54 explicit PaginationWidget(QWidget* parent = nullptr);
55
62 void update_state(std::uint32_t loaded_count, std::uint32_t total_count);
63
69 std::uint32_t page_size() const;
70
76 void set_load_all_enabled(bool enabled);
77
81 [[nodiscard]] std::uint32_t current_page() const { return current_page_; }
82
86 [[nodiscard]] std::uint32_t total_pages() const;
87
91 [[nodiscard]] std::uint32_t current_offset() const;
92
93signals:
99 void page_size_changed(std::uint32_t page_size);
100
105
112 void page_requested(std::uint32_t offset, std::uint32_t limit);
113
114private slots:
115 void on_page_size_changed(int index);
116 void on_load_all_clicked();
117 void on_first_clicked();
118 void on_prev_clicked();
119 void on_next_clicked();
120 void on_last_clicked();
121
122private:
123 QLabel* info_label_;
124 QComboBox* page_size_combo_;
125 QAction* first_action_;
126 QAction* prev_action_;
127 QAction* next_action_;
128 QAction* last_action_;
129 QAction* load_all_action_;
130 QToolBar* nav_toolbar_;
131 QHBoxLayout* layout_;
132
133 std::uint32_t loaded_count_{0};
134 std::uint32_t total_count_{0};
135 std::uint32_t current_page_{0};
136
137 void update_button_states();
138};
139
140}
141
142#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AccountController.hpp:32
Widget providing pagination controls for data tables.
Definition PaginationWidget.hpp:40
void page_size_changed(std::uint32_t page_size)
Emitted when user changes the page size selection.
void load_all_requested()
Emitted when user requests to load all remaining data.
std::uint32_t current_page() const
Get the current page number (0-based).
Definition PaginationWidget.hpp:81
void page_requested(std::uint32_t offset, std::uint32_t limit)
Emitted when user requests to navigate to a specific page.