Changed: #1306 added basic editing possibillities for normal and parent values (no default values and no saving of changed values yet); added possibillity to expand/collapse whole tree by header click

This commit is contained in:
aquiles 2011-08-25 23:25:33 +02:00
parent 9f614249b5
commit 1304bfe56a
11 changed files with 595 additions and 48 deletions

View file

@ -12,7 +12,8 @@ SET(OVQT_PLUG_GEORGES_EDITOR_HDR georges_editor_plugin.h
georges_editor_form.h georges_editor_form.h
georges_dirtree_dialog.h georges_dirtree_dialog.h
georges_filesystem_model.h georges_filesystem_model.h
georges_treeview_dialog.h) georges_treeview_dialog.h
expandable_headerview.h)
SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui SET(OVQT_PLUG_GEORGES_EDITOR_UIS georges_editor_form.ui
georges_dirtree_form.ui georges_dirtree_form.ui

View file

@ -0,0 +1,143 @@
// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Project includes
#include "expandable_headerview.h"
// Qt includes
#include <QApplication>
#include <QMouseEvent>
#include <QPainter>
namespace Plugin
{
ExpandableHeaderView::ExpandableHeaderView(Qt::Orientation orientation, QWidget * parent)
: QHeaderView(orientation, parent),
m_expanded(true),
m_inDecoration(false)
{
}
void ExpandableHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
painter->save();
QHeaderView::paintSection(painter, rect, logicalIndex);
painter->restore();
if (logicalIndex == 0)
{
QRect sectionRect = this->orientation() == Qt::Horizontal ?
QRect(this->sectionPosition(logicalIndex), 0,
this->sectionSize(logicalIndex), this->height()):
QRect(0, this->sectionPosition(logicalIndex),
this->width(), this->sectionSize(logicalIndex));
QStyleOptionHeader opt;
initStyleOption(&opt);
opt.iconAlignment = Qt::AlignVCenter;
QVariant variant = this->model()->headerData(logicalIndex, this->orientation(),
Qt::DecorationRole);
opt.icon = qvariant_cast<QIcon>(variant);
if (opt.icon.isNull())
{
opt.icon = qvariant_cast<QPixmap>(variant);
}
QRect headerLabelRect = this->style()->subElementRect(QStyle::SE_HeaderLabel, &opt, this);
QPixmap pixmap
= opt.icon.pixmap(this->style()->pixelMetric(QStyle::PM_SmallIconSize),
(opt.state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled);
QRect aligned = this->style()->alignedRect(opt.direction, QFlag(opt.iconAlignment),
pixmap.size(), headerLabelRect);
QRect inter = aligned.intersected(headerLabelRect);
QStyleOption option;
option.rect = QRect(inter.x()-2,inter.y(),inter.width(),inter.height());
if (m_expanded)
option.state = QStyle::State_Children | QStyle::State_Open;
else
option.state = QStyle::State_Children;
if (m_inDecoration)
option.state |= QStyle::State_MouseOver;
QApplication::style()->drawPrimitive(QStyle::PE_IndicatorBranch, &option, painter);
}
}
void ExpandableHeaderView::mousePressEvent(QMouseEvent *e)
{
int section = logicalIndexAt(e->x());
if (section == 0 && m_inDecoration) {
if (m_expanded)
m_expanded = false;
else
m_expanded = true;
this->QHeaderView::mousePressEvent(e);
Q_EMIT headerClicked(section);
}
}
void ExpandableHeaderView::mouseMoveEvent(QMouseEvent *e)
{
int section = this->logicalIndexAt(e->x());
if (section != 0)
return;
bool tmp = m_inDecoration;
if (isPointInDecoration(section, e->pos()))
m_inDecoration = true;
else
m_inDecoration = false;
if (m_inDecoration != tmp)
updateSection(0);
}
bool ExpandableHeaderView::isPointInDecoration(int section, QPoint pos)const
{
QRect sectionRect = this->orientation() == Qt::Horizontal ?
QRect(this->sectionPosition(section), 0,
this->sectionSize(section), this->height()):
QRect(0, this->sectionPosition(section),
this->width(), this->sectionSize(section));
QStyleOptionHeader opt;
this->initStyleOption(&opt);
opt.iconAlignment = Qt::AlignVCenter;
QVariant variant = this->model()->headerData(section, this->orientation(),
Qt::DecorationRole);
opt.icon = qvariant_cast<QIcon>(variant);
if (opt.icon.isNull())
{
opt.icon = qvariant_cast<QPixmap>(variant);
}
QRect headerLabelRect = this->style()->subElementRect(QStyle::SE_HeaderLabel, &opt, this);
// from qcommonstyle.cpp
if (opt.icon.isNull())
{
return false;
}
QPixmap pixmap
= opt.icon.pixmap(this->style()->pixelMetric(QStyle::PM_SmallIconSize),
(opt.state & QStyle::State_Enabled) ? QIcon::Normal : QIcon::Disabled);
QRect aligned = this->style()->alignedRect(opt.direction, QFlag(opt.iconAlignment),
pixmap.size(), headerLabelRect);
QRect inter = aligned.intersected(headerLabelRect);
return inter.contains(pos);
}
}

View file

@ -0,0 +1,49 @@
// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef EXPANDABLE_HEADERVIEW_H
#define EXPANDABLE_HEADERVIEW_H
// Qt includes
#include <QHeaderView>
namespace Plugin
{
class ExpandableHeaderView : public QHeaderView
{
Q_OBJECT
public:
ExpandableHeaderView(Qt::Orientation orientation, QWidget * parent = 0);
bool* expanded() { return &m_expanded; }
protected:
void paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const;
bool isPointInDecoration(int section, QPoint pos)const;
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
private:
bool m_expanded;
bool m_inDecoration;
Q_SIGNALS:
void headerClicked(int);
};
} /* namespace NLQT */
#endif // EXPANDABLE_HEADERVIEW_H

View file

@ -0,0 +1,278 @@
// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "formdelegate.h"
// NeL includes
#include <nel/misc/debug.h>
#include <nel/georges/u_type.h>
#include <nel/georges/u_form_elm.h>
// Qt includes
#include <QSpinBox>
#include <QLineEdit>
#include <QDoubleSpinBox>
#include <QColorDialog>
#include <QComboBox>
#include <QApplication>
#include <QTextDocument>
#include <QAbstractTextDocumentLayout>
#include <QPainter>
// Project includes
#include "georgesform_model.h"
#include "georgesform_proxy_model.h"
#include "formitem.h"
namespace Plugin
{
FormDelegate::FormDelegate(QObject *parent)
: QStyledItemDelegate(parent)
{
}
QWidget *FormDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem & option ,
const QModelIndex &index) const
{
const CGeorgesFormProxyModel * mp = dynamic_cast<const CGeorgesFormProxyModel *>(index.model());
const CGeorgesFormModel * m = dynamic_cast<const CGeorgesFormModel *>(mp->sourceModel());
CFormItem *item = static_cast<CFormItem*>(mp->mapToSource(index).internalPointer());
QString value = item->data(1).toString();
if (value.isEmpty() || !mp || !m)
return 0;
CFormItem* curItem = m->getItem(mp->mapToSource(index));
NLGEORGES::UFormElm *curElm = curItem->getFormElm();
if (!curElm) {
// TODO: create new Element
return 0;
}
const NLGEORGES::UType *type = curElm->getType();
if(type)
{
int numDefinitions = type->getNumDefinition();
if (numDefinitions)
{
std::string l, v;
QString label,value;
QComboBox *editor = new QComboBox(parent);
for (int i = 0; i < numDefinitions; i++)
{
type->getDefinition(i,l,v);
label = l.c_str();
value = v.c_str();
editor->addItem(label);
}
return editor;
}
else
{
switch (type->getType())
{
case NLGEORGES::UType::UnsignedInt:
case NLGEORGES::UType::SignedInt:
{
QSpinBox *editor = new QSpinBox(parent);
//QString min = QString(type->getMin().c_str());
//QString max = QString(type->getMax().c_str());
//QString inc = QString(type->getIncrement().c_str());
//nldebug(QString("min %1 max %2 inc %3").arg(min).arg(max).arg(inc).toStdString().c_str());
// TODO: use saved min/max values
editor->setMinimum(-99999);
editor->setMaximum(99999);
editor->setSingleStep(1);
return editor;
}
case NLGEORGES::UType::Double:
{
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
//QString min = QString(type->getMin().c_str());
//QString max = QString(type->getMax().c_str());
//QString inc = QString(type->getIncrement().c_str());
//nldebug(QString("min %1 max %2 inc %3").arg(min).arg(max).arg(inc).toStdString().c_str());
// TODO: use saved min/max values
editor->setMinimum(-99999);
editor->setMaximum(99999);
editor->setSingleStep(0.1);
editor->setDecimals(1);
return editor;
}
case NLGEORGES::UType::Color:
{
return new QColorDialog();
}
default: // UType::String
{
QLineEdit *editor = new QLineEdit(parent);
return editor;
}
}
}
}
return 0;
}
void FormDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const
{
const CGeorgesFormProxyModel * mp = dynamic_cast<const CGeorgesFormProxyModel *>(index.model());
const CGeorgesFormModel * m = dynamic_cast<const CGeorgesFormModel *>(mp->sourceModel());
const NLGEORGES::UType *type = m->getItem(mp->mapToSource(index))->getFormElm()->getType();
int numDefinitions = type->getNumDefinition();
QString value = index.model()->data(index, Qt::DisplayRole).toString();
if (numDefinitions)
{
QComboBox *cb = static_cast<QComboBox*>(editor);
cb->setCurrentIndex(cb->findText(value));
}
else
{
switch (type->getType())
{
case NLGEORGES::UType::UnsignedInt:
case NLGEORGES::UType::SignedInt:
{
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
spinBox->setValue((int)value.toDouble());
break;
}
case NLGEORGES::UType::Double:
{
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
spinBox->setValue(value.toDouble());
break;
}
case NLGEORGES::UType::Color:
{
break;
}
default:
{
QLineEdit *textEdit = static_cast<QLineEdit*>(editor);
textEdit->setText(value);
break;
}
}
}
}
void FormDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
const CGeorgesFormProxyModel * mp = dynamic_cast<const CGeorgesFormProxyModel *>(index.model());
const CGeorgesFormModel * m = dynamic_cast<const CGeorgesFormModel *>(mp->sourceModel());
const NLGEORGES::UType *type = m->getItem(mp->mapToSource(index))->getFormElm()->getType();
int numDefinitions = type->getNumDefinition();
if (numDefinitions)
{
QComboBox *comboBox = static_cast<QComboBox*>(editor);
QString value = comboBox->currentText();
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
if (value == oldValue)
{
// nothing's changed
}
else
{
nldebug(QString("setModelData from %1 to %2")
.arg(oldValue).arg(value).toStdString().c_str());
model->setData(index, value, Qt::EditRole);
}
}
else
{
switch (type->getType())
{
case NLGEORGES::UType::UnsignedInt:
case NLGEORGES::UType::SignedInt:
{
QSpinBox *spinBox = static_cast<QSpinBox*>(editor);
int value = spinBox->value();
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
if (QString("%1").arg(value) == oldValue)
{
// nothing's changed
}
else
{
nldebug(QString("setModelData from %1 to %2")
.arg(oldValue).arg(value).toStdString().c_str());
model->setData(index, value, Qt::EditRole);
}
break;
}
case NLGEORGES::UType::Double:
{
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
double value = spinBox->value();
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
if (QString("%1").arg(value) == oldValue)
{
// nothing's changed
}
else
{
nldebug(QString("setModelData from %1 to %2")
.arg(oldValue).arg(value).toStdString().c_str());
model->setData(index, value, Qt::EditRole);
}
break;
}
case NLGEORGES::UType::Color:
{
break; // TODO
}
default: // UType::String
{
QLineEdit *textEdit = static_cast<QLineEdit*>(editor);
QString value = textEdit->text();
QString oldValue = index.model()->data(index, Qt::DisplayRole).toString();
if (value == oldValue)
{
// nothing's changed
}
else
{
nldebug(QString("setModelData from %1 to %2")
.arg(oldValue).arg(value).toStdString().c_str());
model->setData(index, value, Qt::EditRole);
}
break;
}
}
}
}
void FormDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QRect r = option.rect;
editor->setGeometry(r);
}
} /* namespace Plugin */

View file

@ -0,0 +1,41 @@
// Object Viewer Qt - Georges Editor Plugin - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2011 Adrian Jaekel <aj at elane2k dot com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef FORMDELEGATE_H
#define FORMDELEGATE_H
#include <QStyledItemDelegate>
namespace Plugin
{
class FormDelegate : public QStyledItemDelegate
{
public:
FormDelegate(QObject *parent = 0);
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &index) const;
};
}
#endif // FORMDELEGATE_H

View file

@ -74,7 +74,7 @@ QString GeorgesEditorPlugin::name() const
QString GeorgesEditorPlugin::version() const QString GeorgesEditorPlugin::version() const
{ {
return "0.3"; return "0.4";
} }
QString GeorgesEditorPlugin::vendor() const QString GeorgesEditorPlugin::vendor() const

View file

@ -32,7 +32,8 @@
#include "georgesform_model.h" #include "georgesform_model.h"
#include "georgesform_proxy_model.h" #include "georgesform_proxy_model.h"
#include "formitem.h" #include "formitem.h"
//#include "formdelegate.h" #include "formdelegate.h"
#include "expandable_headerview.h"
using namespace NLMISC; using namespace NLMISC;
using namespace NLGEORGES; using namespace NLGEORGES;
@ -41,7 +42,8 @@ namespace Plugin
{ {
CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/) CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/)
: QDockWidget(parent) : QDockWidget(parent),
m_header(0)
{ {
m_georges = new CGeorges; m_georges = new CGeorges;
@ -49,16 +51,18 @@ namespace Plugin
m_modified = false; m_modified = false;
m_ui.setupUi(this); m_ui.setupUi(this);
m_header = new ExpandableHeaderView(Qt::Horizontal, m_ui.treeView);
m_ui.treeView->setHeader(m_header);
m_ui.treeView->header()->setResizeMode(QHeaderView::ResizeToContents); m_ui.treeView->header()->setResizeMode(QHeaderView::ResizeToContents);
m_ui.treeView->header()->setStretchLastSection(true);
m_ui.treeViewTabWidget->setTabEnabled (2,false); m_ui.treeViewTabWidget->setTabEnabled (2,false);
m_ui.checkBoxParent->setStyleSheet("background-color: rgba(0,255,0,30)"); m_ui.checkBoxParent->setStyleSheet("background-color: rgba(0,255,0,30)");
m_ui.checkBoxDefaults->setStyleSheet("background-color: rgba(255,0,0,30)"); m_ui.checkBoxDefaults->setStyleSheet("background-color: rgba(255,0,0,30)");
m_form = 0; m_form = 0;
//FormDelegate *formdelegate = new FormDelegate(this); FormDelegate *formdelegate = new FormDelegate(this);
//_ui.treeView->setItemDelegateForColumn(1, formdelegate); m_ui.treeView->setItemDelegateForColumn(1, formdelegate);
connect(m_ui.treeView, SIGNAL(doubleClicked (QModelIndex)), connect(m_ui.treeView, SIGNAL(doubleClicked (QModelIndex)),
this, SLOT(doubleClicked (QModelIndex))); this, SLOT(doubleClicked (QModelIndex)));
@ -66,14 +70,22 @@ namespace Plugin
this, SLOT(filterRows())); this, SLOT(filterRows()));
connect(m_ui.checkBoxDefaults, SIGNAL(toggled(bool)), connect(m_ui.checkBoxDefaults, SIGNAL(toggled(bool)),
this, SLOT(filterRows())); this, SLOT(filterRows()));
connect(m_header, SIGNAL(headerClicked(int)),
this, SLOT(headerClicked(int)));
} }
CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog() CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog()
{ {
//delete _ui.treeView->itemDelegateForColumn(1);
delete m_form; delete m_form;
//QSettings settings("RyzomCore", "GeorgesQt"); }
//settings.setValue("dirViewGeometry", saveGeometry());
void CGeorgesTreeViewDialog::headerClicked(int section)
{
if (section == 0)
if (*(m_header->expanded()))
m_ui.treeView->expandAll();
else
m_ui.treeView->collapseAll();
} }
void CGeorgesTreeViewDialog::setForm(const CForm *form) void CGeorgesTreeViewDialog::setForm(const CForm *form)
@ -170,7 +182,7 @@ namespace Plugin
{ {
loadedForm = m_form->getFilename().c_str(); loadedForm = m_form->getFilename().c_str();
CGeorgesFormModel *model = new CGeorgesFormModel(root,deps,comments,parents); CGeorgesFormModel *model = new CGeorgesFormModel(root,deps,comments,parents,m_header->expanded());
CGeorgesFormProxyModel *proxyModel = new CGeorgesFormProxyModel(); CGeorgesFormProxyModel *proxyModel = new CGeorgesFormProxyModel();
proxyModel->setSourceModel(model); proxyModel->setSourceModel(model);
m_ui.treeView->setModel(proxyModel); m_ui.treeView->setModel(proxyModel);

View file

@ -18,6 +18,7 @@
#define GEORGES_TREEVIEWER_DIALOG_H #define GEORGES_TREEVIEWER_DIALOG_H
#include "ui_georges_treeview_form.h" #include "ui_georges_treeview_form.h"
#include "expandable_headerview.h"
// Qt includes // Qt includes
#include <QtGui/QDockWidget> #include <QtGui/QDockWidget>
@ -77,9 +78,11 @@ namespace Plugin
private Q_SLOTS: private Q_SLOTS:
void doubleClicked ( const QModelIndex & index ); void doubleClicked ( const QModelIndex & index );
void filterRows(); void filterRows();
void headerClicked(int);
private: private:
Ui::CGeorgesTreeViewDialog m_ui; Ui::CGeorgesTreeViewDialog m_ui;
ExpandableHeaderView *m_header;
UForm *m_form; UForm *m_form;
CGeorges *m_georges; CGeorges *m_georges;

View file

@ -30,10 +30,13 @@
#include <QApplication> #include <QApplication>
#include <QStyle> #include <QStyle>
#include <QDebug> #include <QDebug>
#include <QStylePainter>
#include <QStyleOption>
#include <QLabel>
#include <QPixmap>
// project includes // project includes
#include "formitem.h" #include "formitem.h"
//#include "modules.h"
using namespace NLGEORGES; using namespace NLGEORGES;
@ -41,7 +44,7 @@ namespace Plugin
{ {
CGeorgesFormModel::CGeorgesFormModel(UFormElm *rootElm, QMap< QString, QStringList> deps, CGeorgesFormModel::CGeorgesFormModel(UFormElm *rootElm, QMap< QString, QStringList> deps,
QString comment, QStringList parents, QObject *parent) : QAbstractItemModel(parent) QString comment, QStringList parents, bool *expanded, QObject *parent) : QAbstractItemModel(parent)
{ {
QList<QVariant> rootData; QList<QVariant> rootData;
rootData << "Value" << "Data" << "Extra";// << "Type"; rootData << "Value" << "Data" << "Extra";// << "Type";
@ -51,6 +54,7 @@ namespace Plugin
m_comments = comment; m_comments = comment;
m_parents = parents; m_parents = parents;
m_parentRows = new QList<const QModelIndex*>; m_parentRows = new QList<const QModelIndex*>;
m_expanded = expanded;
setupModelData(); setupModelData();
} }
@ -231,23 +235,23 @@ namespace Plugin
/******************************************************************************/ /******************************************************************************/
//bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value, bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value,
// int role) int role)
//{ {
// if (role != Qt::EditRole) if (role != Qt::EditRole)
// return false; return false;
// CFormItem *item = getItem(index); CFormItem *item = getItem(index);
// bool result = item->setData(index.column(), value); bool result = item->setData(index.column(), value);
// // TODO: ugly hack for updating icon too // // TODO: ugly hack for updating icon too
// if (result) // if (result)
// Q_EMIT dataChanged(index, this->index(index.row(),index.column()+1,index.parent())); // Q_EMIT dataChanged(index, this->index(index.row(),index.column()+1,index.parent()));
// setupModelData(); //setupModelData();
// return result; return result;
//} }
/******************************************************************************/ /******************************************************************************/
@ -258,11 +262,8 @@ namespace Plugin
Qt::ItemFlags returnValue = Qt::ItemIsSelectable | Qt::ItemIsEnabled; Qt::ItemFlags returnValue = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
//if(index.column() == 1) if(index.column() == 1)
// returnValue |= Qt::ItemIsEditable; returnValue |= Qt::ItemIsEditable;
// TODO?
// col 2 should go here too but i dont want to do another delegate
// so for now i just connected the dblClick in the dialog
return returnValue; return returnValue;
@ -273,11 +274,42 @@ namespace Plugin
QVariant CGeorgesFormModel::headerData(int section, QVariant CGeorgesFormModel::headerData(int section,
Qt::Orientation orientation, int role) const Qt::Orientation orientation, int role) const
{ {
if (orientation == Qt::Horizontal && role == Qt::DisplayRole) if (orientation == Qt::Horizontal)
{
if (role == Qt::DisplayRole)
return m_rootItem->data(section); return m_rootItem->data(section);
if (role == Qt::TextAlignmentRole)
return Qt::AlignLeft;
if (section == 0 && role == Qt::DecorationRole)
{
// transparent pixmap as we paint it ourself with tree brach
// if we extend the HeaderView::paintSection for the CE_HeaderLabel
// we could drop this
QPixmap pixmap = QPixmap(
QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize),
QApplication::style()->pixelMetric(QStyle::PM_SmallIconSize));
// Create new picture for transparent
QPixmap transparent(pixmap.size());
// Do transparency
transparent.fill(Qt::transparent);
QPainter p(&transparent);
p.setCompositionMode(QPainter::CompositionMode_Source);
p.drawPixmap(0, 0, pixmap);
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
// Set transparency level to 150 (possible values are 0-255)
// The alpha channel of a color specifies the transparency effect,
// 0 represents a fully transparent color, while 255 represents
// a fully opaque color.
p.fillRect(transparent.rect(), QColor(0, 0, 0, 0));
p.end();
// Set original picture's reference to new transparent one
pixmap = transparent;
return pixmap;
}
}
return QVariant(); return QVariant();
} }
/******************************************************************************/ /******************************************************************************/

View file

@ -39,11 +39,11 @@ namespace Plugin
public: public:
CGeorgesFormModel(NLGEORGES::UFormElm *root, QMap< QString, QStringList> deps, CGeorgesFormModel(NLGEORGES::UFormElm *root, QMap< QString, QStringList> deps,
QString comment, QStringList parents, QObject *parent = 0); QString comment, QStringList parents, bool* expanded, QObject *parent = 0);
~CGeorgesFormModel(); ~CGeorgesFormModel();
QVariant data(const QModelIndex &index, int role) const; QVariant data(const QModelIndex &index, int role) const;
//bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const;
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
@ -71,6 +71,7 @@ namespace Plugin
bool m_showParents; bool m_showParents;
bool m_showDefaults; bool m_showDefaults;
bool *m_expanded;
};/* class CGeorgesFormModel */ };/* class CGeorgesFormModel */

View file

@ -14,17 +14,14 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "georgesform_proxy_model.h"
#include "georgesform_model.h"
// NeL includes // NeL includes
#include <nel/misc/debug.h> #include <nel/misc/debug.h>
#include <nel/georges/u_form_elm.h> #include <nel/georges/u_form_elm.h>
// project includes // project includes
#include "formitem.h" #include "formitem.h"
#include "georgesform_proxy_model.h"
#include <QDebug> #include "georgesform_model.h"
namespace Plugin namespace Plugin
{ {
@ -32,20 +29,11 @@ namespace Plugin
bool CGeorgesFormProxyModel::filterAcceptsRow(int sourceRow, bool CGeorgesFormProxyModel::filterAcceptsRow(int sourceRow,
const QModelIndex &sourceParent) const const QModelIndex &sourceParent) const
{ {
//nlinfo("CGeorgesFormProxyModel::filterAcceptsRow");
// column doesnt matter for item // column doesnt matter for item
CGeorgesFormModel *smodel = dynamic_cast<CGeorgesFormModel *>(sourceModel()); CGeorgesFormModel *smodel = dynamic_cast<CGeorgesFormModel *>(sourceModel());
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
CFormItem *item = smodel->getItem(index); CFormItem *item = smodel->getItem(index);
//qDebug() << smodel->showParents() << (item->valueFrom() == NLGEORGES::UFormElm::NodeParentForm);
//nlinfo("%s %d %d %d %d", item->data(index.column()).toString().toStdString().c_str(),
// item->valueFrom(),
// item->nodeFrom(),
// smodel->showParents(),
// (item->valueFrom() == NLGEORGES::UFormElm::NodeParentForm));
// if elm not existing it must be some kind of default or type value // if elm not existing it must be some kind of default or type value
if(!item->getFormElm()) if(!item->getFormElm())
{ {
@ -86,7 +74,6 @@ namespace Plugin
bool CGeorgesFormProxyModel::filterAcceptsColumn(int sourceRow, bool CGeorgesFormProxyModel::filterAcceptsColumn(int sourceRow,
const QModelIndex &sourceParent) const const QModelIndex &sourceParent) const
{ {
//nlinfo("CGeorgesFormProxyModel::filterAcceptsColumn");
return QSortFilterProxyModel::filterAcceptsColumn(sourceRow, sourceParent); return QSortFilterProxyModel::filterAcceptsColumn(sourceRow, sourceParent);
} }
} /* namespace Plugin */ } /* namespace Plugin */