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
31namespace ores::qt {
32
39class PaginationWidget : public QWidget {
40 Q_OBJECT
41
42private:
43 inline static std::string_view logger_name =
44 "ores.qt.pagination_widget";
45
46 [[nodiscard]] static auto& lg() {
47 using namespace ores::logging;
48 static auto instance = make_logger(logger_name);
49 return instance;
50 }
51
52public:
53 explicit PaginationWidget(QWidget* parent = nullptr);
54
61 void update_state(std::uint32_t loaded_count, std::uint32_t total_count);
62
68 std::uint32_t page_size() const;
69
75 void set_load_all_enabled(bool enabled);
76
80 [[nodiscard]] std::uint32_t current_page() const { return current_page_; }
81
85 [[nodiscard]] std::uint32_t total_pages() const;
86
90 [[nodiscard]] std::uint32_t current_offset() const;
91
92signals:
98 void page_size_changed(std::uint32_t page_size);
99
104
111 void page_requested(std::uint32_t offset, std::uint32_t limit);
112
113private slots:
114 void on_page_size_changed(int index);
115 void on_load_all_clicked();
116 void on_first_clicked();
117 void on_prev_clicked();
118 void on_next_clicked();
119 void on_last_clicked();
120
121private:
122 QLabel* info_label_;
123 QComboBox* page_size_combo_;
124 QAction* first_action_;
125 QAction* prev_action_;
126 QAction* next_action_;
127 QAction* last_action_;
128 QAction* load_all_action_;
129 QToolBar* nav_toolbar_;
130 QHBoxLayout* layout_;
131
132 std::uint32_t loaded_count_{0};
133 std::uint32_t total_count_{0};
134 std::uint32_t current_page_{0};
135
136 void update_button_states();
137};
138
139}
140
141#endif
Implements logging infrastructure for ORE Studio.
Definition boost_severity.hpp:28
Qt-based graphical user interface for ORE Studio.
Definition AboutDialog.hpp:35
Widget providing pagination controls for data tables.
Definition PaginationWidget.hpp:39
void update_state(std::uint32_t loaded_count, std::uint32_t total_count)
Update the pagination display with current state.
Definition PaginationWidget.cpp:116
void page_size_changed(std::uint32_t page_size)
Emitted when user changes the page size selection.
std::uint32_t total_pages() const
Get the total number of pages.
Definition PaginationWidget.cpp:171
void set_load_all_enabled(bool enabled)
Enable or disable the Load All button.
Definition PaginationWidget.cpp:163
void load_all_requested()
Emitted when user requests to load all remaining data.
std::uint32_t current_offset() const
Calculate the offset for the current page.
Definition PaginationWidget.cpp:179
std::uint32_t current_page() const
Get the current page number (0-based).
Definition PaginationWidget.hpp:80
void page_requested(std::uint32_t offset, std::uint32_t limit)
Emitted when user requests to navigate to a specific page.
std::uint32_t page_size() const
Get the selected page size.
Definition PaginationWidget.cpp:145