2017-04-27 18:26:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-04-27 15:27:27 +00:00
|
|
|
#ifndef MODELDELEGATES_H
|
|
|
|
#define MODELDELEGATES_H
|
|
|
|
|
2019-04-25 07:35:46 +00:00
|
|
|
#include "core/units.h"
|
|
|
|
|
2013-05-02 22:27:36 +00:00
|
|
|
#include <QStyledItemDelegate>
|
2014-11-17 14:03:37 +00:00
|
|
|
#include <QComboBox>
|
2024-03-30 12:40:00 +00:00
|
|
|
#include <functional>
|
2022-09-17 14:55:44 +00:00
|
|
|
|
2013-10-03 14:50:40 +00:00
|
|
|
class QPainter;
|
2024-03-30 12:40:00 +00:00
|
|
|
struct dive;
|
2022-09-17 14:55:44 +00:00
|
|
|
struct divecomputer;
|
2013-04-27 15:27:27 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
class DiveListDelegate : public QStyledItemDelegate {
|
2013-12-11 23:44:05 +00:00
|
|
|
public:
|
2023-02-12 12:03:28 +00:00
|
|
|
using QStyledItemDelegate::QStyledItemDelegate;
|
2014-02-28 04:09:57 +00:00
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
2013-12-11 23:44:05 +00:00
|
|
|
};
|
|
|
|
|
2013-05-02 22:27:36 +00:00
|
|
|
class StarWidgetsDelegate : public QStyledItemDelegate {
|
2013-04-27 15:27:27 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-28 04:09:57 +00:00
|
|
|
explicit StarWidgetsDelegate(QWidget *parent = 0);
|
2020-05-16 07:17:41 +00:00
|
|
|
const QSize &starSize() const;
|
2014-02-28 04:09:57 +00:00
|
|
|
|
2013-05-02 22:27:36 +00:00
|
|
|
private:
|
2020-05-16 07:28:50 +00:00
|
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
2013-05-02 22:27:36 +00:00
|
|
|
QWidget *parentWidget;
|
2014-10-15 13:30:49 +00:00
|
|
|
QSize minStarSize;
|
2013-04-27 15:27:27 +00:00
|
|
|
};
|
2013-05-22 17:11:49 +00:00
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
class ComboBoxDelegate : public QStyledItemDelegate {
|
2013-05-22 17:11:49 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2024-03-30 12:40:00 +00:00
|
|
|
// First parameter: function that creates a model and makes it a child of the passed-in widget.
|
|
|
|
explicit ComboBoxDelegate(std::function<QAbstractItemModel *(QWidget *)> create_model_func, QObject *parent = 0, bool allowEdit = true);
|
2020-05-16 07:46:30 +00:00
|
|
|
private
|
2014-02-28 04:09:57 +00:00
|
|
|
slots:
|
2020-05-16 07:46:30 +00:00
|
|
|
void testActivationString(const QString &currString);
|
|
|
|
void testActivationIndex(const QModelIndex &currIndex);
|
Make the Qt ComboBox behave in a Better Way
So, the ComboBox is a beast, and when used on a Delegate
it's very hard to get things right, wich is a pitty, because
I overly like qt. So:
1 - Combobox needs to show the popup when user press ↓ and ↑ keys
2 - Combobox needs to select when user press enter, not twice.
3 - Combobox neesds to select when user selects from the mouse, not
pressing enter after.
4 - Combobox needs to not mess with stuff when moving around.
Everything that I listed there works on a non-delegate combobox,
but for some reason, a delegate missed those, so I reimplemented
all. not nice, but now we have a code that will work, I hope.
*fingers crossed*
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
2013-09-25 19:37:24 +00:00
|
|
|
//HACK: try to get rid of this in the future.
|
|
|
|
void fakeActivation();
|
2020-05-16 07:46:30 +00:00
|
|
|
protected
|
|
|
|
slots:
|
2019-11-04 19:20:32 +00:00
|
|
|
virtual void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) = 0;
|
2017-03-26 21:47:21 +00:00
|
|
|
private:
|
2024-03-30 12:40:00 +00:00
|
|
|
std::function<QAbstractItemModel *(QWidget *)> create_model_func;
|
2017-03-26 21:47:21 +00:00
|
|
|
bool editable;
|
2020-05-16 07:28:50 +00:00
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
|
|
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
bool eventFilter(QObject *object, QEvent *event) override;
|
2013-06-16 13:15:19 +00:00
|
|
|
protected:
|
2020-03-27 21:33:17 +00:00
|
|
|
mutable struct CurrSelected {
|
|
|
|
QComboBox *comboEditor;
|
|
|
|
int currRow;
|
|
|
|
QString activeText;
|
|
|
|
QAbstractItemModel *model;
|
|
|
|
bool ignoreSelection;
|
|
|
|
} currCombo;
|
2013-06-16 13:15:19 +00:00
|
|
|
};
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
class TankInfoDelegate : public ComboBoxDelegate {
|
2013-06-16 13:15:19 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-28 04:09:57 +00:00
|
|
|
explicit TankInfoDelegate(QObject *parent = 0);
|
2018-09-29 20:13:44 +00:00
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
2020-05-16 07:28:50 +00:00
|
|
|
private:
|
|
|
|
void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) override;
|
2013-05-22 17:11:49 +00:00
|
|
|
};
|
|
|
|
|
2014-11-17 14:03:37 +00:00
|
|
|
class TankUseDelegate : public QStyledItemDelegate {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit TankUseDelegate(QObject *parent = 0);
|
2024-05-15 05:23:39 +00:00
|
|
|
void setDiveDc(const dive &d, int &dcNr);
|
2020-05-16 07:28:50 +00:00
|
|
|
private:
|
2018-09-29 20:13:44 +00:00
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
2020-05-16 07:17:41 +00:00
|
|
|
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
2024-05-15 05:23:39 +00:00
|
|
|
const dive *currentDive;
|
|
|
|
int *currentDcNr;
|
2022-09-02 20:51:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SensorDelegate : public QStyledItemDelegate {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit SensorDelegate(QObject *parent = 0);
|
2022-09-17 14:55:44 +00:00
|
|
|
void setCurrentDC(divecomputer *dc);
|
2022-09-02 20:51:19 +00:00
|
|
|
private:
|
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
2022-09-17 14:55:44 +00:00
|
|
|
divecomputer *currentdc;
|
2014-11-17 14:03:37 +00:00
|
|
|
};
|
|
|
|
|
2014-02-28 04:09:57 +00:00
|
|
|
class WSInfoDelegate : public ComboBoxDelegate {
|
2013-05-24 01:40:16 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-02-28 04:09:57 +00:00
|
|
|
explicit WSInfoDelegate(QObject *parent = 0);
|
2020-05-16 07:28:50 +00:00
|
|
|
private:
|
2018-09-29 20:13:44 +00:00
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
2020-05-16 07:28:50 +00:00
|
|
|
void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) override;
|
2013-05-24 01:40:16 +00:00
|
|
|
};
|
|
|
|
|
2024-05-15 05:23:39 +00:00
|
|
|
class GasTypesDelegate : public ComboBoxDelegate {
|
2013-08-30 10:14:30 +00:00
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2024-05-15 05:23:39 +00:00
|
|
|
explicit GasTypesDelegate(const dive &d, int &dcNr, QObject *parent = 0);
|
2020-05-16 07:28:50 +00:00
|
|
|
private:
|
2018-09-29 20:13:44 +00:00
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
2020-05-16 07:28:50 +00:00
|
|
|
void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) override;
|
2018-05-08 15:26:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DiveTypesDelegate : public ComboBoxDelegate {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2024-05-15 05:23:39 +00:00
|
|
|
explicit DiveTypesDelegate(const dive &d, int &dcNr, QObject *parent = 0);
|
2020-05-16 07:28:50 +00:00
|
|
|
private:
|
2018-09-29 20:13:44 +00:00
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
2020-05-16 07:28:50 +00:00
|
|
|
void editorClosed(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) override;
|
2013-08-30 10:14:30 +00:00
|
|
|
};
|
|
|
|
|
2014-07-11 20:42:43 +00:00
|
|
|
class SpinBoxDelegate : public QStyledItemDelegate {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-07-12 12:24:25 +00:00
|
|
|
SpinBoxDelegate(int min, int max, int step, QObject *parent = 0);
|
2014-07-11 20:42:43 +00:00
|
|
|
private:
|
2020-05-16 07:28:50 +00:00
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
2014-07-11 20:42:43 +00:00
|
|
|
int min;
|
|
|
|
int max;
|
2014-07-12 12:24:25 +00:00
|
|
|
int step;
|
2014-07-11 20:42:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DoubleSpinBoxDelegate : public QStyledItemDelegate {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2014-07-12 12:24:25 +00:00
|
|
|
DoubleSpinBoxDelegate(double min, double max, double step, QObject *parent = 0);
|
2014-07-11 20:42:43 +00:00
|
|
|
private:
|
2020-05-16 07:28:50 +00:00
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
2014-07-12 12:24:24 +00:00
|
|
|
double min;
|
|
|
|
double max;
|
2014-07-12 12:24:25 +00:00
|
|
|
double step;
|
2014-07-11 20:42:43 +00:00
|
|
|
};
|
|
|
|
|
2015-07-01 22:31:56 +00:00
|
|
|
class LocationFilterDelegate : public QStyledItemDelegate {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
LocationFilterDelegate(QObject *parent = 0);
|
2019-04-25 07:35:46 +00:00
|
|
|
void setCurrentLocation(location_t loc);
|
|
|
|
private:
|
2020-05-16 07:28:50 +00:00
|
|
|
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
|
|
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
2019-04-25 07:35:46 +00:00
|
|
|
location_t currentLocation;
|
2015-07-01 22:31:56 +00:00
|
|
|
};
|
|
|
|
|
2014-02-11 18:14:46 +00:00
|
|
|
#endif // MODELDELEGATES_H
|