Commit e510ede1 authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner: Handle visibility by role

Since there will be two models we have to decouple things
in the delegates.

Change-Id: If20b7ca1ab211bbf953968fb0994679b588e8b4a
Reviewed-by: Tim Jenssen's avatarTim Jenssen <tim.jenssen@qt.io>
parent 0732b9c0
......@@ -57,9 +57,14 @@ QSize IconCheckboxItemDelegate::sizeHint(const QStyleOptionViewItem & /*option*/
return QSize(15, 20);
}
static bool isChecked(NavigatorTreeModel *navigatorTreeModel, const QModelIndex &modelIndex)
static bool isChecked(const QAbstractItemModel *model, const QModelIndex &modelIndex)
{
return navigatorTreeModel->data(modelIndex, Qt::CheckStateRole) == Qt::Checked;
return model->data(modelIndex, Qt::CheckStateRole) == Qt::Checked;
}
static bool isVisible(const QAbstractItemModel *model, const QModelIndex &modelIndex)
{
return model->data(modelIndex, ItemIsVisibleRole).toBool();
}
void IconCheckboxItemDelegate::paint(QPainter *painter,
......@@ -76,10 +81,10 @@ void IconCheckboxItemDelegate::paint(QPainter *painter,
if (!m_navigatorTreeModel->modelNodeForIndex(modelIndex).isRootNode()) {
if (m_navigatorTreeModel->isNodeVisible(modelIndex))
if (!isVisible(modelIndex.model(), modelIndex))
painter->setOpacity(0.5);
const bool checked = isChecked(m_navigatorTreeModel, modelIndex);
const bool checked = isChecked(modelIndex.model(), modelIndex);
painter->drawPixmap(styleOption.rect.x() + xOffset, styleOption.rect.y() + yOffset,
checked ? m_checkedPixmap : m_uncheckedPixmap);
}
......
......@@ -143,6 +143,11 @@ static QRect drawText(QPainter *painter,
return textFrame;
}
static bool isVisible(const QAbstractItemModel *model, const QModelIndex &modelIndex)
{
return model->data(modelIndex, ItemIsVisibleRole).toBool();
}
static void drawRedWavyUnderLine(QPainter *painter,
const QStyleOptionViewItem &styleOption,
const QRect &textFrame)
......@@ -168,7 +173,7 @@ void NameItemDelegate::paint(QPainter *painter,
int iconOffset = drawIcon(painter, styleOption, modelIndex);
if (m_navigatorTreeModel->isNodeVisible(modelIndex))
if (!isVisible(modelIndex.model(), modelIndex))
painter->setOpacity(0.5);
QRect textFrame = drawText(painter, styleOption, modelIndex, iconOffset);
......
......@@ -251,6 +251,10 @@ QVariant NavigatorTreeModel::data(const QModelIndex &index, int role) const
if (!modelNode.isValid())
return QVariant();
if (role == ItemIsVisibleRole) //independent of column
return m_view->isNodeVisible(modelNode) ? Qt::Unchecked : Qt::Checked;
if (index.column() == 0) {
if (role == Qt::DisplayRole) {
return modelNode.displayName();
......
......@@ -40,6 +40,11 @@ namespace QmlDesigner {
class NavigatorWidget;
class NavigatorTreeModel;
enum NavigatorRoles {
ItemIsVisibleRole = Qt::UserRole,
RowIsPropertyRole = Qt::UserRole +1
};
class NavigatorView : public AbstractView
{
Q_OBJECT
......
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