mirror of
https://github.com/Lurkki14/tuxclocker.git
synced 2025-02-25 18:55:24 -06:00
qt: add a way to expand editor in AssignableEditorDelegate
This commit is contained in:
parent
5991b891b0
commit
db72b73795
@ -7,8 +7,10 @@
|
|||||||
#include <IntRangeEditor.h>
|
#include <IntRangeEditor.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QTreeView>
|
||||||
|
|
||||||
AssignableEditorDelegate::AssignableEditorDelegate(QObject *parent) : QStyledItemDelegate(parent) {
|
AssignableEditorDelegate::AssignableEditorDelegate(QTreeView *treeView, QObject *parent) : QStyledItemDelegate(parent) {
|
||||||
|
m_treeView = treeView;
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *AssignableEditorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
QWidget *AssignableEditorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||||
@ -43,9 +45,35 @@ QWidget *AssignableEditorDelegate::createEditor(QWidget *parent, const QStyleOpt
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AssignableEditorDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
void AssignableEditorDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const {
|
||||||
editor->setGeometry(option.rect);
|
if (index != m_spannedIndex) {
|
||||||
//editor->setGeometry(QRect(QPoint(option.rect.topLeft()), QPoint(500, 500)));
|
// Span editor across all columns
|
||||||
//editor->setGeometry(option.widget->rect());
|
const int maxCol = index.model()->columnCount(index.parent());
|
||||||
|
QRect tempRect = m_treeView->visualRect(index.model()->index(index.row(), 0, index.parent()));
|
||||||
|
int top = tempRect.top();
|
||||||
|
int left = tempRect.left();
|
||||||
|
int bottom = tempRect.bottom();
|
||||||
|
int right= tempRect.right();
|
||||||
|
|
||||||
|
for(int i = 1; i < maxCol ; i++){
|
||||||
|
tempRect = m_treeView->visualRect(index.model()->index(index.row(), i, index.parent()));
|
||||||
|
if (tempRect.top()<top) {
|
||||||
|
top = tempRect.top();
|
||||||
|
}
|
||||||
|
if (Q_UNLIKELY(tempRect.left() < left)) {
|
||||||
|
left= tempRect.left();
|
||||||
|
}
|
||||||
|
if (tempRect.bottom() > bottom) {
|
||||||
|
bottom = tempRect.bottom();
|
||||||
|
}
|
||||||
|
if (Q_LIKELY(tempRect.right() > right)) {
|
||||||
|
right= tempRect.right();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
editor->setGeometry(QRect(QPoint(left, top),QPoint(right, bottom)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
editor->setGeometry(option.rect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignableEditorDelegate::setEditorData(QWidget* editor, const QModelIndex &index) const {
|
void AssignableEditorDelegate::setEditorData(QWidget* editor, const QModelIndex &index) const {
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
#include <QStandardItem>
|
#include <QStandardItem>
|
||||||
|
#include <QTreeView>
|
||||||
|
|
||||||
class AssignableEditorDelegate : public QStyledItemDelegate {
|
class AssignableEditorDelegate : public QStyledItemDelegate {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
AssignableEditorDelegate(QObject *parent = nullptr);
|
AssignableEditorDelegate(QTreeView *treeView, QObject *parent = nullptr);
|
||||||
|
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
@ -14,7 +15,11 @@ public:
|
|||||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
|
||||||
|
|
||||||
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||||
|
|
||||||
|
void setSpannedIndex(const QModelIndex &index) {m_spannedIndex = index;}
|
||||||
private:
|
private:
|
||||||
|
QModelIndex m_spannedIndex; // Index of the editor that should span all columns
|
||||||
QSize m_customExpansionSize;
|
QSize m_customExpansionSize;
|
||||||
bool m_customExpansionSizeNeeded;
|
bool m_customExpansionSizeNeeded;
|
||||||
|
QTreeView *m_treeView; // Tree view that the delegate belongs to
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user