Files
qt5-legatus-legacy/Lts/Common/LtsWidgets/lts_selection_popup.h
T
2026-08-13 18:33:10 +02:00

113 lines
3.5 KiB
C++
Executable File

/**
* @RDE_HEADER@
* ComboBox's popup, optimized for tablets (bigger dropdown/popup)
* $Id$
* $HeadURL$
* $Author$
*
* Created by Mike Wille, SLSE, 2016-03-09
*/
#pragma once
#include "lts_frameless_dialog.h"
#include "lts_widgets_export.h"
namespace Ui
{
class LtsSelectionPopup;
}
class QAbstractItemModel;
class QSortFilterProxyModel;
namespace LtsWidgets
{
/**
* @brief The LtsSelectionPopup is a popup window (LtsFramelessDialog) with a list of all QRadioButtons from a model with a search/filter edit.
* (former 'LtsComboBoxPopup' class WAS an internal Popup class for the LtsComboBox and is not meant for export)
* This is a custom Popup which is touch-friendly and screen-centered.
*/
class LTSWIDGETS_EXPORT LtsSelectionPopup : public LtsFramelessDialog
{
Q_OBJECT
public:
/**
* @brief LtsSelectionPopup creates a popup with all its items (from model) in it
* @param model the model which contains all items
* @param currentIndex which item is currently selected (to not select any item: a value smaller than 0)
* @param parent parent of this widget (not the LtsComboBox, the actual parent)
*/
LtsSelectionPopup(QAbstractItemModel *model,
int currentIndex,
QWidget *parent = nullptr);
~LtsSelectionPopup();
protected:
/**
* @brief showEvent selects the search/filter widget on show
* @param event
*/
void showEvent(QShowEvent *event) override;
private:
Ui::LtsSelectionPopup *m_ui;
int m_currentIndex;
int m_firstIndex;
QSortFilterProxyModel *m_filter;
bool m_valid; // selection is valid? (e.g. not hidden because it's filtered)
/**
* @brief refresh deletes all Radio Buttons and creates them new (e.g. filtering)
*/
void refresh();
/**
* @brief selectItem emits signals that tell the connected slot which item was selected
* @param row the row number of the model
* @param text the text of the radio button
* @param activate if the item was activated (see QRadioButton doc) - by default false as it not not used everytime
*/
void selectItem(int row, bool bCurrentIndexChanged, bool bActivated);
signals:
// void highlighted(int index); // not supported yet
// activated(row); // Qt::Doc: is only emitted when the change is caused by user interaction
// currentIndexChanged(row); // Qt::Doc: is always emitted regardless if the change was done programmatically or by user interaction
// My note: If the uses selects the already selected item, only activated is emitted.
/**
* @brief activated is emitted when the selection has changed or is confirmded by the user
* Qt::Doc: is only emitted when the change is caused by user interaction
* Addon: If the uses selects the already selected item, only activated is emitted.
*/
void activated(int index);
/**
* @brief currentIndexChanged is emitted when the current item changes (by user interaction or programmatically)
* Qt::Doc: is always emitted regardless if the change was done programmatically or by user interaction
* Addon: If the uses selects the already selected item, only activated is emitted.
*/
void currentIndexChanged(int index);
public slots:
/**
* @brief accept is called when the selection ends successfully (user double-clicked an item or clicked the 'Select' button) and emits signalSelectItem
*/
void accept() override;
/**
* @brief slotFilterChanged is called if the search / filter text changed and recreates all Radio Buttons after filtering
*/
void slotFilterChanged();
};
} // namespace LtsWidgets