Commit 9c4ea2c4 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Remove NavigatorTreeModel from IconCheckboxItemDelegate

IconCheckboxItemDelegate does not require internals of the model anymore.

Change-Id: Ia4d2787cf34c56e8b2a3b82184b9d5f2378ce607
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 14d4ebd3
......@@ -43,12 +43,10 @@ namespace QmlDesigner {
IconCheckboxItemDelegate::IconCheckboxItemDelegate(QObject *parent,
const QPixmap &checkedPixmap,
const QPixmap &uncheckedPixmap,
NavigatorTreeModel *treeModel)
const QPixmap &uncheckedPixmap)
: QStyledItemDelegate(parent),
m_checkedPixmap(checkedPixmap),
m_uncheckedPixmap(uncheckedPixmap),
m_navigatorTreeModel(treeModel)
m_uncheckedPixmap(uncheckedPixmap)
{}
QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem & /*option*/,
......@@ -57,14 +55,19 @@ QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem & /*option*/
return QSize(15, 20);
}
static bool isChecked(const QAbstractItemModel *model, const QModelIndex &modelIndex)
static bool isChecked(const QModelIndex &modelIndex)
{
return model->data(modelIndex, Qt::CheckStateRole) == Qt::Checked;
return modelIndex.model()->data(modelIndex, Qt::CheckStateRole) == Qt::Checked;
}
static bool isVisible(const QAbstractItemModel *model, const QModelIndex &modelIndex)
static bool isVisible(const QModelIndex &modelIndex)
{
return model->data(modelIndex, ItemIsVisibleRole).toBool();
return modelIndex.model()->data(modelIndex, ItemIsVisibleRole).toBool();
}
static ModelNode getModelNode(const QModelIndex &modelIndex)
{
return modelIndex.model()->data(modelIndex, ModelNodeRole).value<ModelNode>();
}
static bool rowIsPropertyRole(const QAbstractItemModel *model, const QModelIndex &modelIndex)
......@@ -87,12 +90,12 @@ void IconCheckboxItemDelegate::paint(QPainter *painter,
if (styleOption.state & QStyle::State_Selected)
NavigatorTreeView::drawSelectionBackground(painter, styleOption);
if (!m_navigatorTreeModel->modelNodeForIndex(modelIndex).isRootNode()) {
if (!getModelNode(modelIndex).isRootNode()) {
if (!isVisible(modelIndex.model(), modelIndex))
if (!isVisible(modelIndex))
painter->setOpacity(0.5);
const bool checked = isChecked(modelIndex.model(), modelIndex);
const bool checked = isChecked(modelIndex);
painter->drawPixmap(styleOption.rect.x() + xOffset, styleOption.rect.y() + yOffset,
checked ? m_checkedPixmap : m_uncheckedPixmap);
}
......
......@@ -36,8 +36,7 @@ class IconCheckboxItemDelegate : public QStyledItemDelegate
public:
explicit IconCheckboxItemDelegate(QObject *parent,
const QPixmap &checkedPixmap,
const QPixmap &uncheckedPixmap,
NavigatorTreeModel *treeModel);
const QPixmap &uncheckedPixmap);
QSize sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index) const;
......@@ -49,6 +48,5 @@ public:
private:
const QPixmap m_checkedPixmap;
const QPixmap m_uncheckedPixmap;
NavigatorTreeModel *m_navigatorTreeModel;
};
} // namespace QmlDesigner
......@@ -93,14 +93,12 @@ NavigatorView::NavigatorView(QObject* parent) :
IconCheckboxItemDelegate *showDelegate =
new IconCheckboxItemDelegate(this,
Utils::Icons::EYE_OPEN_TOOLBAR.pixmap(),
Utils::Icons::EYE_CLOSED_TOOLBAR.pixmap(),
m_treeModel.data());
Utils::Icons::EYE_CLOSED_TOOLBAR.pixmap());
IconCheckboxItemDelegate *exportDelegate =
new IconCheckboxItemDelegate(this,
Icons::EXPORT_CHECKED.pixmap(),
Icons::EXPORT_UNCHECKED.pixmap(),
m_treeModel.data());
Icons::EXPORT_UNCHECKED.pixmap());
#ifdef _LOCK_ITEMS_
IconCheckboxItemDelegate *lockDelegate = new IconCheckboxItemDelegate(this,":/qmldesigner/images/lock.png",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment