commit
0f86e107b7
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
@ -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 */
|
@ -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
|
@ -0,0 +1,162 @@
|
|||||||
|
// 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 "formitem.h"
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/o_xml.h>
|
||||||
|
#include <nel/georges/u_type.h>
|
||||||
|
#include <nel/georges/form.h>
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
CFormItem::CFormItem(NLGEORGES::UFormElm* elm, const QList<QVariant> &data, CFormItem *parent,
|
||||||
|
NLGEORGES::UFormElm::TWhereIsValue wV, NLGEORGES::UFormElm::TWhereIsNode wN)
|
||||||
|
{
|
||||||
|
parentItem = parent;
|
||||||
|
itemData = data;
|
||||||
|
formElm = elm;
|
||||||
|
whereV = wV;
|
||||||
|
whereN = wN;
|
||||||
|
}
|
||||||
|
|
||||||
|
CFormItem::~CFormItem()
|
||||||
|
{
|
||||||
|
qDeleteAll(childItems);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFormItem::appendChild(CFormItem *item)
|
||||||
|
{
|
||||||
|
childItems.append(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
CFormItem *CFormItem::child(int row)
|
||||||
|
{
|
||||||
|
return childItems.value(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
int CFormItem::childCount() const
|
||||||
|
{
|
||||||
|
return childItems.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
int CFormItem::columnCount() const
|
||||||
|
{
|
||||||
|
//nlinfo("columnCount %d",itemData.count());
|
||||||
|
return itemData.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant CFormItem::data(int column) const
|
||||||
|
{
|
||||||
|
return itemData.value(column);
|
||||||
|
}
|
||||||
|
|
||||||
|
CFormItem *CFormItem::parent()
|
||||||
|
{
|
||||||
|
return parentItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
int CFormItem::row() const
|
||||||
|
{
|
||||||
|
if (parentItem)
|
||||||
|
return parentItem->childItems.indexOf(const_cast<CFormItem*>(this));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CFormItem::setData(int column, const QVariant &value)
|
||||||
|
{
|
||||||
|
if (column < 0 || column >= itemData.size())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// TODO: default values
|
||||||
|
if (!formElm)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
itemData[column] = value;
|
||||||
|
if (formElm->isAtom())
|
||||||
|
{
|
||||||
|
const NLGEORGES::UType *type = formElm->getType();
|
||||||
|
if (type)
|
||||||
|
{
|
||||||
|
switch (type->getType())
|
||||||
|
{
|
||||||
|
case NLGEORGES::UType::UnsignedInt:
|
||||||
|
case NLGEORGES::UType::SignedInt:
|
||||||
|
case NLGEORGES::UType::Double:
|
||||||
|
case NLGEORGES::UType::String:
|
||||||
|
if (parentItem->formElm->isArray())
|
||||||
|
{
|
||||||
|
//((NLGEORGES::CFormElm*)parentItem->formElm);//->arrayInsertNodeByName(
|
||||||
|
//if(parentItem->formElm->getArrayNode(elmName, num))
|
||||||
|
//{
|
||||||
|
//}
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
// TODO: the node can be renamed from eg "#0" to "foobar"
|
||||||
|
int arrayIndex = itemData[0].toString().remove("#").toInt(&ok);
|
||||||
|
if(ok)
|
||||||
|
{
|
||||||
|
NLGEORGES::UFormElm *elmt = 0;
|
||||||
|
if(parentItem->formElm->getArrayNode(&elmt, arrayIndex) && elmt)
|
||||||
|
{
|
||||||
|
if (elmt->isAtom())
|
||||||
|
{
|
||||||
|
((NLGEORGES::CFormElmAtom*)elmt)->setValue(value.toString().toStdString().c_str());
|
||||||
|
nldebug(QString("array element string %1 %2")
|
||||||
|
.arg(itemData[0].toString()).arg(value.toString())
|
||||||
|
.toStdString().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(parentItem->formElm->setValueByName(
|
||||||
|
value.toString().toStdString().c_str(),
|
||||||
|
itemData[0].toString().toStdString().c_str()))
|
||||||
|
{
|
||||||
|
nldebug(QString("string %1 %2")
|
||||||
|
.arg(itemData[0].toString()).arg(value.toString())
|
||||||
|
.toStdString().c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nldebug(QString("FAILED string %1 %2")
|
||||||
|
.arg(itemData[0].toString()).arg(value.toString())
|
||||||
|
.toStdString().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case NLGEORGES::UType::Color:
|
||||||
|
nldebug("Color is TODO");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nldebug("setting sth other than Atom");
|
||||||
|
}
|
||||||
|
//formElm->setValueByName();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
// 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 FORMITEM_H
|
||||||
|
#define FORMITEM_H
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/georges/u_form_elm.h>
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QList>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
class CFormItem
|
||||||
|
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CFormItem(NLGEORGES::UFormElm *elm, const QList<QVariant> &data,
|
||||||
|
CFormItem *parent = 0,
|
||||||
|
NLGEORGES::UFormElm::TWhereIsValue = NLGEORGES::UFormElm::ValueForm,
|
||||||
|
NLGEORGES::UFormElm::TWhereIsNode = NLGEORGES::UFormElm::NodeForm);
|
||||||
|
~CFormItem();
|
||||||
|
|
||||||
|
void appendChild(CFormItem *child);
|
||||||
|
|
||||||
|
CFormItem *child(int row);
|
||||||
|
int childCount() const;
|
||||||
|
int columnCount() const;
|
||||||
|
QVariant data(int column) const;
|
||||||
|
int row() const;
|
||||||
|
CFormItem *parent();
|
||||||
|
bool setData(int column, const QVariant &value);
|
||||||
|
NLGEORGES::UFormElm* getFormElm() {return formElm;}
|
||||||
|
NLGEORGES::UFormElm::TWhereIsValue valueFrom()
|
||||||
|
{
|
||||||
|
return whereV;
|
||||||
|
}
|
||||||
|
NLGEORGES::UFormElm::TWhereIsNode nodeFrom()
|
||||||
|
{
|
||||||
|
return whereN;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<CFormItem*> childItems;
|
||||||
|
QList<QVariant> itemData;
|
||||||
|
CFormItem *parentItem;
|
||||||
|
NLGEORGES::UFormElm* formElm;
|
||||||
|
NLGEORGES::UFormElm::TWhereIsValue whereV;
|
||||||
|
NLGEORGES::UFormElm::TWhereIsNode whereN;
|
||||||
|
}; // CFormItem
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // FORMITEM_H
|
@ -0,0 +1,64 @@
|
|||||||
|
// 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 "georges.h"
|
||||||
|
#include "nel/misc/o_xml.h"
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/georges/u_form_loader.h>
|
||||||
|
#include <nel/georges/u_form.h>
|
||||||
|
#include <nel/georges/u_type.h>
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
|
||||||
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
CGeorges::CGeorges(): FormLoader(0)
|
||||||
|
{
|
||||||
|
FormLoader = UFormLoader::createLoader();
|
||||||
|
}
|
||||||
|
|
||||||
|
CGeorges::~CGeorges()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
UForm *CGeorges::loadForm(std::string formName)
|
||||||
|
{
|
||||||
|
UForm *form = FormLoader->loadForm(formName.c_str());
|
||||||
|
|
||||||
|
return form;
|
||||||
|
}
|
||||||
|
|
||||||
|
UFormDfn *CGeorges::loadFormDfn(std::string formName)
|
||||||
|
{
|
||||||
|
UFormDfn *formdfn = FormLoader->loadFormDfn(formName.c_str());
|
||||||
|
|
||||||
|
return formdfn;
|
||||||
|
}
|
||||||
|
|
||||||
|
UType *CGeorges::loadFormType(std::string formName)
|
||||||
|
{
|
||||||
|
UType *type = FormLoader->loadFormType(formName.c_str());
|
||||||
|
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace Plugin */
|
@ -0,0 +1,69 @@
|
|||||||
|
// 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 GEORGES_H
|
||||||
|
#define GEORGES_H
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
|
||||||
|
namespace NLGEORGES
|
||||||
|
{
|
||||||
|
class UType;
|
||||||
|
class UForm;
|
||||||
|
class UFormDfn;
|
||||||
|
class UFormLoader;
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
@class CGeorges
|
||||||
|
A CGeorges class loading and viewing sheets.
|
||||||
|
*/
|
||||||
|
class CGeorges
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// Default constructor.
|
||||||
|
CGeorges();
|
||||||
|
virtual ~CGeorges();
|
||||||
|
|
||||||
|
// Load the given form root
|
||||||
|
UForm* loadForm(std::string formName);
|
||||||
|
// Load a dfn
|
||||||
|
UFormDfn* loadFormDfn(std::string formName);
|
||||||
|
// Load a type
|
||||||
|
UType *loadFormType (std::string formName);
|
||||||
|
|
||||||
|
// A form loader
|
||||||
|
UFormLoader *FormLoader;
|
||||||
|
|
||||||
|
};/* class CGeorges */
|
||||||
|
|
||||||
|
} /* namespace Plugin */
|
||||||
|
|
||||||
|
#endif // GEORGES_H
|
@ -0,0 +1,388 @@
|
|||||||
|
// 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 "georges_treeview_dialog.h"
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QtGui/QWidget>
|
||||||
|
#include <QSettings>
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/path.h>
|
||||||
|
#include <nel/misc/file.h>
|
||||||
|
#include <nel/misc/o_xml.h>
|
||||||
|
#include <nel/georges/form.h>
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
#include "georges.h"
|
||||||
|
#include "georgesform_model.h"
|
||||||
|
#include "georgesform_proxy_model.h"
|
||||||
|
#include "formitem.h"
|
||||||
|
#include "formdelegate.h"
|
||||||
|
#include "expandable_headerview.h"
|
||||||
|
|
||||||
|
using namespace NLMISC;
|
||||||
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
CGeorgesTreeViewDialog::CGeorgesTreeViewDialog(QWidget *parent /*= 0*/)
|
||||||
|
: QDockWidget(parent),
|
||||||
|
m_header(0),
|
||||||
|
m_modified(false)
|
||||||
|
{
|
||||||
|
m_georges = new CGeorges;
|
||||||
|
|
||||||
|
loadedForm = "";
|
||||||
|
|
||||||
|
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()->setStretchLastSection(true);
|
||||||
|
m_ui.treeViewTabWidget->setTabEnabled (2,false);
|
||||||
|
|
||||||
|
m_ui.checkBoxParent->setStyleSheet("background-color: rgba(0,255,0,30)");
|
||||||
|
m_ui.checkBoxDefaults->setStyleSheet("background-color: rgba(255,0,0,30)");
|
||||||
|
m_form = 0;
|
||||||
|
|
||||||
|
FormDelegate *formdelegate = new FormDelegate(this);
|
||||||
|
m_ui.treeView->setItemDelegateForColumn(1, formdelegate);
|
||||||
|
|
||||||
|
connect(m_ui.treeView, SIGNAL(doubleClicked (QModelIndex)),
|
||||||
|
this, SLOT(doubleClicked (QModelIndex)));
|
||||||
|
connect(m_ui.checkBoxParent, SIGNAL(toggled(bool)),
|
||||||
|
this, SLOT(filterRows()));
|
||||||
|
connect(m_ui.checkBoxDefaults, SIGNAL(toggled(bool)),
|
||||||
|
this, SLOT(filterRows()));
|
||||||
|
connect(m_header, SIGNAL(headerClicked(int)),
|
||||||
|
this, SLOT(headerClicked(int)));
|
||||||
|
}
|
||||||
|
|
||||||
|
CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog()
|
||||||
|
{
|
||||||
|
delete m_form;
|
||||||
|
qDebug() << "DTOR";
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
m_form = (UForm*)form;
|
||||||
|
}
|
||||||
|
|
||||||
|
CForm* CGeorgesTreeViewDialog::getFormByName(const QString formName)
|
||||||
|
{
|
||||||
|
if(NLMISC::CPath::exists(formName.toStdString()))
|
||||||
|
{
|
||||||
|
return (CForm*)m_georges->loadForm(formName.toStdString());
|
||||||
|
}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// CForm *form = 0;
|
||||||
|
// // Load the DFN
|
||||||
|
// std::string extStr = NLMISC::CFile::getExtension( formName.toStdString() );
|
||||||
|
// QString dfnName = QString("%1.dfn").arg(extStr.c_str());
|
||||||
|
// UFormDfn *formdfn;
|
||||||
|
// if (NLMISC::CPath::exists(dfnName.toStdString()))
|
||||||
|
// {
|
||||||
|
// formdfn = _georges->loadFormDfn (dfnName.toStdString());
|
||||||
|
// if (!formdfn)
|
||||||
|
// {
|
||||||
|
// nlwarning("Failed to load dfn: %s", dfnName.toStdString().c_str());
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// nlwarning("Cannot find dfn: %s", dfnName.toStdString().c_str());
|
||||||
|
// return 0;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// form = new CForm;
|
||||||
|
|
||||||
|
// // Build the root element
|
||||||
|
// ((CFormElmStruct*)&form->getRootNode())->build((CFormDfn*)formdfn);
|
||||||
|
|
||||||
|
// uint i;
|
||||||
|
// for (i=0; i<CForm::HeldElementCount; i++)
|
||||||
|
// {
|
||||||
|
// ((CFormElmStruct*)(((CForm*)form)->HeldElements[i]))->build ((CFormDfn*)formdfn);
|
||||||
|
// }
|
||||||
|
// return form;
|
||||||
|
//}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesTreeViewDialog::loadFormIntoDialog(CForm *form)
|
||||||
|
{
|
||||||
|
|
||||||
|
if(form)
|
||||||
|
m_form = form;
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
UFormElm *root = 0;
|
||||||
|
root = &m_form->getRootNode();
|
||||||
|
|
||||||
|
QStringList parents;
|
||||||
|
for (uint i = 0; i < m_form->getNumParent(); i++)
|
||||||
|
{
|
||||||
|
UForm *u = m_form->getParentForm(i);
|
||||||
|
parents << u->getFilename().c_str();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString comments;
|
||||||
|
comments = m_form->getComment().c_str();
|
||||||
|
|
||||||
|
if (!comments.isEmpty())
|
||||||
|
{
|
||||||
|
m_ui.treeViewTabWidget->setTabEnabled (1,true);
|
||||||
|
m_ui.commentEdit->setPlainText(comments);
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList strList;
|
||||||
|
std::set<std::string> dependencies;
|
||||||
|
m_form->getDependencies(dependencies);
|
||||||
|
|
||||||
|
QMap< QString, QStringList> deps;
|
||||||
|
Q_FOREACH(std::string str, dependencies)
|
||||||
|
{
|
||||||
|
QString file = str.c_str();
|
||||||
|
if (str == m_form->getFilename()) continue;
|
||||||
|
deps[file.remove(0,file.indexOf(".")+1)] << str.c_str();
|
||||||
|
}
|
||||||
|
nlinfo("typ's %d",deps["typ"].count());
|
||||||
|
nlinfo("dfn's %d",deps["dfn"].count());
|
||||||
|
|
||||||
|
//nlwarning(strList.join(";").toStdString().c_str());
|
||||||
|
if (root)
|
||||||
|
{
|
||||||
|
loadedForm = m_form->getFilename().c_str();
|
||||||
|
|
||||||
|
CGeorgesFormModel *model = new CGeorgesFormModel(root,deps,comments,parents,m_header->expanded());
|
||||||
|
CGeorgesFormProxyModel *proxyModel = new CGeorgesFormProxyModel();
|
||||||
|
proxyModel->setSourceModel(model);
|
||||||
|
m_ui.treeView->setModel(proxyModel);
|
||||||
|
m_ui.treeView->expandAll();
|
||||||
|
// this is a debug output row
|
||||||
|
m_ui.treeView->hideColumn(3);
|
||||||
|
|
||||||
|
filterRows();
|
||||||
|
|
||||||
|
// //_ui.treeView->setRowHidden(0,QModelIndex(),true);
|
||||||
|
connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)),
|
||||||
|
this, SLOT(modifiedFile()));
|
||||||
|
|
||||||
|
setWindowTitle(loadedForm);
|
||||||
|
// //Modules::mainWin().getTabBar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesTreeViewDialog::addParentForm(CForm *form)
|
||||||
|
{
|
||||||
|
//((CForm*)_form)->insertParent(((CForm*)_form)->getParentCount(), form->getFilename().c_str(), form);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesTreeViewDialog::modifiedFile( )
|
||||||
|
{
|
||||||
|
if (!m_modified)
|
||||||
|
{
|
||||||
|
m_modified = true;
|
||||||
|
setWindowTitle(windowTitle() + "*");
|
||||||
|
}
|
||||||
|
Q_EMIT modified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesTreeViewDialog::write( )
|
||||||
|
{
|
||||||
|
|
||||||
|
//COFile file;
|
||||||
|
//std::string s = CPath::lookup(loadedForm.toStdString(), false);
|
||||||
|
//if (file.open (s))
|
||||||
|
//{
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// if (loadedForm.contains(".typ"))
|
||||||
|
// {
|
||||||
|
// //nlassert (Type != NULL);
|
||||||
|
|
||||||
|
// //// Write the file
|
||||||
|
// //// Modified ?
|
||||||
|
// //if (IsModified ())
|
||||||
|
// //{
|
||||||
|
// // Type->Header.MinorVersion++;
|
||||||
|
// // flushValueChange ();
|
||||||
|
// //}
|
||||||
|
// //Type->write (xmlStream.getDocument (), theApp.Georges4CVS);
|
||||||
|
// //modify (NULL, NULL, false);
|
||||||
|
// //flushValueChange ();
|
||||||
|
// //UpdateAllViews (NULL);
|
||||||
|
// //return TRUE;
|
||||||
|
// }
|
||||||
|
// else if (loadedForm.contains(".dfn"))
|
||||||
|
// {
|
||||||
|
// //nlassert (Dfn != NULL);
|
||||||
|
|
||||||
|
// //// Write the file
|
||||||
|
// //if (IsModified ())
|
||||||
|
// //{
|
||||||
|
// // Dfn->Header.MinorVersion++;
|
||||||
|
// // flushValueChange ();
|
||||||
|
// //}
|
||||||
|
// //Dfn->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS);
|
||||||
|
// //modify (NULL, NULL, false);
|
||||||
|
// //UpdateAllViews (NULL);
|
||||||
|
// //return TRUE;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// nlassert (_form != NULL);
|
||||||
|
|
||||||
|
// // Write the file
|
||||||
|
// /*if (IsModified ())
|
||||||
|
// {
|
||||||
|
// ((CForm*)(UForm*)Form)->Header.MinorVersion++;
|
||||||
|
// }*/
|
||||||
|
// //((CForm*)(UForm*)Form)->write (xmlStream.getDocument (), lpszPathName, theApp.Georges4CVS);
|
||||||
|
// _form->write(file, false);
|
||||||
|
// setWindowTitle(windowTitle().remove("*"));
|
||||||
|
// _modified = false;
|
||||||
|
// //if (strcmp (xmlStream.getErrorString (), "") != 0)
|
||||||
|
// //{
|
||||||
|
// // char message[512];
|
||||||
|
// // smprintf (message, 512, "Error while saving file: %s", xmlStream.getErrorString ());
|
||||||
|
// //theApp.outputError (message);
|
||||||
|
// //}
|
||||||
|
// //modify (NULL, NULL, false);
|
||||||
|
// //flushValueChange ();
|
||||||
|
// //UpdateAllViews (NULL);
|
||||||
|
|
||||||
|
// // Get the left view
|
||||||
|
// //CView* pView = getLeftView ();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// catch (Exception &e)
|
||||||
|
// {
|
||||||
|
// nlerror("Error while loading file: %s", e.what());
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{ //if (!file.open())
|
||||||
|
// nlerror("Can't open the file %s for writing.", s.c_str());
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index )
|
||||||
|
{
|
||||||
|
// TODO: this is messy :( perhaps this can be done better
|
||||||
|
CGeorgesFormProxyModel * proxyModel =
|
||||||
|
dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
|
||||||
|
CGeorgesFormModel *model =
|
||||||
|
dynamic_cast<CGeorgesFormModel *>(proxyModel->sourceModel());
|
||||||
|
QModelIndex sourceIndex = proxyModel->mapToSource(index);
|
||||||
|
|
||||||
|
CFormItem *item = model->getItem(sourceIndex);
|
||||||
|
|
||||||
|
if (item->parent() && item->parent()->data(0) == "parents")
|
||||||
|
{
|
||||||
|
Q_EMIT changeFile(CPath::lookup(item->data(0).toString().toStdString(),false).c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
//// col containing additional stuff like icons
|
||||||
|
//if (index.column() == 2)
|
||||||
|
//{
|
||||||
|
// QModelIndex in2 = m->index(in.row(),in.column()-1,in.parent());
|
||||||
|
// CFormItem *item = m->getItem(in2);
|
||||||
|
// QString value = item->data(1).toString();
|
||||||
|
|
||||||
|
// QString path = CPath::lookup(value.toStdString(),false).c_str();
|
||||||
|
|
||||||
|
// if(value.contains(".tga") || value.contains(".png"))
|
||||||
|
// {
|
||||||
|
// QString file = QFileDialog::getOpenFileName(
|
||||||
|
// this,
|
||||||
|
// "Select a new image",
|
||||||
|
// path,
|
||||||
|
// "Images (*.png *.tga)"
|
||||||
|
// );
|
||||||
|
// if (file.isNull())
|
||||||
|
// return;
|
||||||
|
// QFileInfo info = QFileInfo(file);
|
||||||
|
|
||||||
|
// // TODO?
|
||||||
|
// // right way would be another delegate but im too lazy :)
|
||||||
|
// // so for now i just call it directly
|
||||||
|
// m->setData(in2, info.fileName());
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// if (path.contains(".shape") || path.contains(".ps"))
|
||||||
|
// {
|
||||||
|
// if (Modules::objViewInt())
|
||||||
|
// {
|
||||||
|
// Modules::objViewInt()->resetScene();
|
||||||
|
// //Modules::config().configRemapExtensions();
|
||||||
|
// Modules::objViewInt()->loadMesh(path.toStdString(),"");
|
||||||
|
// }
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // open eg parent files
|
||||||
|
// if (!path.isEmpty())
|
||||||
|
// Q_EMIT changeFile(path);
|
||||||
|
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesTreeViewDialog::closeEvent(QCloseEvent *event)
|
||||||
|
{
|
||||||
|
Q_EMIT closing();
|
||||||
|
deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesTreeViewDialog::checkVisibility(bool visible) {
|
||||||
|
// this prevents invisible docks from getting tab focus
|
||||||
|
qDebug() << "checkVisibility" << visible;
|
||||||
|
setEnabled(visible);
|
||||||
|
//if (visible)
|
||||||
|
Q_EMIT modified();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGeorgesTreeViewDialog::filterRows()
|
||||||
|
{
|
||||||
|
CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(m_ui.treeView->model());
|
||||||
|
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
|
||||||
|
if (m) {
|
||||||
|
m->setShowParents(m_ui.checkBoxParent->isChecked());
|
||||||
|
m->setShowDefaults(m_ui.checkBoxDefaults->isChecked());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
@ -0,0 +1,96 @@
|
|||||||
|
// 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 GEORGES_TREEVIEWER_DIALOG_H
|
||||||
|
#define GEORGES_TREEVIEWER_DIALOG_H
|
||||||
|
|
||||||
|
#include "ui_georges_treeview_form.h"
|
||||||
|
#include "expandable_headerview.h"
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QtGui/QDockWidget>
|
||||||
|
|
||||||
|
// STL includes
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
|
||||||
|
// Project includes
|
||||||
|
|
||||||
|
namespace NLGEORGES
|
||||||
|
{
|
||||||
|
class UForm;
|
||||||
|
class CForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
class CGeorges;
|
||||||
|
|
||||||
|
class CGeorgesTreeViewDialog: public QDockWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
CGeorgesTreeViewDialog(QWidget *parent = 0);
|
||||||
|
~CGeorgesTreeViewDialog();
|
||||||
|
|
||||||
|
bool isModified() {return m_modified;}
|
||||||
|
void setModified(bool m) {m_modified = m;}
|
||||||
|
|
||||||
|
CForm* getFormByName(const QString);
|
||||||
|
void addParentForm(CForm *form);
|
||||||
|
|
||||||
|
void write ( );
|
||||||
|
|
||||||
|
QTabWidget* tabWidget() { return m_ui.treeViewTabWidget; }
|
||||||
|
|
||||||
|
QString loadedForm;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void closeEvent(QCloseEvent *event);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void changeFile(QString);
|
||||||
|
void modified();
|
||||||
|
void closing();
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
void setForm(const CForm*);
|
||||||
|
void loadFormIntoDialog(CForm *form = 0);
|
||||||
|
void modifiedFile( );
|
||||||
|
void checkVisibility(bool);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void doubleClicked ( const QModelIndex & index );
|
||||||
|
void filterRows();
|
||||||
|
void headerClicked(int);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Ui::CGeorgesTreeViewDialog m_ui;
|
||||||
|
ExpandableHeaderView *m_header;
|
||||||
|
UForm *m_form;
|
||||||
|
CGeorges *m_georges;
|
||||||
|
|
||||||
|
bool m_modified;
|
||||||
|
|
||||||
|
}; /* CGeorgesTreeViewDialog */
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
#endif // GEORGES_TREEVIEWER_DIALOG_H
|
@ -0,0 +1,130 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>CGeorgesTreeViewDialog</class>
|
||||||
|
<widget class="QDockWidget" name="CGeorgesTreeViewDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>199</width>
|
||||||
|
<height>165</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="dockWidgetContents">
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QTabWidget" name="treeViewTabWidget">
|
||||||
|
<property name="tabPosition">
|
||||||
|
<enum>QTabWidget::West</enum>
|
||||||
|
</property>
|
||||||
|
<property name="currentIndex">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<widget class="QWidget" name="form_tab">
|
||||||
|
<property name="focusPolicy">
|
||||||
|
<enum>Qt::NoFocus</enum>
|
||||||
|
</property>
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Form</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_3">
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item row="0" column="0" colspan="4">
|
||||||
|
<widget class="QTreeView" name="treeView">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QCheckBox" name="checkBoxParent">
|
||||||
|
<property name="text">
|
||||||
|
<string>Parent</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="2">
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QCheckBox" name="checkBoxDefaults">
|
||||||
|
<property name="text">
|
||||||
|
<string>Defaults</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="comment_tab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Comment</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPlainTextEdit" name="commentEdit">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="log_tab">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Log</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_4">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPlainTextEdit" name="logEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<resources>
|
||||||
|
<include location="georges_editor.qrc"/>
|
||||||
|
</resources>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -0,0 +1,674 @@
|
|||||||
|
// 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 "georgesform_model.h"
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/types_nl.h>
|
||||||
|
#include <nel/misc/rgba.h>
|
||||||
|
#include <nel/misc/path.h>
|
||||||
|
#include <nel/georges/u_form_elm.h>
|
||||||
|
#include <nel/georges/u_type.h>
|
||||||
|
#include <nel/georges/u_form_dfn.h>
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QColor>
|
||||||
|
#include <QBrush>
|
||||||
|
#include <QApplication>
|
||||||
|
#include <QStyle>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QStylePainter>
|
||||||
|
#include <QStyleOption>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
|
// project includes
|
||||||
|
#include "formitem.h"
|
||||||
|
|
||||||
|
using namespace NLGEORGES;
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
CGeorgesFormModel::CGeorgesFormModel(UFormElm *rootElm, QMap< QString, QStringList> deps,
|
||||||
|
QString comment, QStringList parents, bool *expanded, QObject *parent) : QAbstractItemModel(parent)
|
||||||
|
{
|
||||||
|
QList<QVariant> rootData;
|
||||||
|
rootData << "Value" << "Data" << "Extra";// << "Type";
|
||||||
|
m_rootElm = rootElm;
|
||||||
|
m_rootItem = new CFormItem(m_rootElm, rootData);
|
||||||
|
m_dependencies = deps;
|
||||||
|
m_comments = comment;
|
||||||
|
m_parents = parents;
|
||||||
|
m_parentRows = new QList<const QModelIndex*>;
|
||||||
|
m_expanded = expanded;
|
||||||
|
|
||||||
|
setupModelData();
|
||||||
|
}
|
||||||
|
|
||||||
|
CGeorgesFormModel::~CGeorgesFormModel()
|
||||||
|
{
|
||||||
|
delete m_rootItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
QVariant CGeorgesFormModel::data(const QModelIndex &p_index, int p_role) const
|
||||||
|
{
|
||||||
|
if (!p_index.isValid())
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
switch (p_role)
|
||||||
|
{
|
||||||
|
case Qt::DisplayRole:
|
||||||
|
{
|
||||||
|
return getItem(p_index)->data(p_index.column());
|
||||||
|
}
|
||||||
|
case Qt::BackgroundRole:
|
||||||
|
{
|
||||||
|
QBrush defaultBrush = QBrush(QColor(255,0,0,30));
|
||||||
|
QBrush parentBrush = QBrush(QColor(0,255,0,30));
|
||||||
|
|
||||||
|
// if elm not existing it must be some kind of default or type value
|
||||||
|
if(!getItem(p_index)->getFormElm())
|
||||||
|
{
|
||||||
|
return defaultBrush;
|
||||||
|
}
|
||||||
|
|
||||||
|
// else it might be some parent elm
|
||||||
|
switch (getItem(p_index)->nodeFrom())
|
||||||
|
{
|
||||||
|
case NLGEORGES::UFormElm::NodeParentForm:
|
||||||
|
{
|
||||||
|
return parentBrush;
|
||||||
|
}
|
||||||
|
case NLGEORGES::UFormElm::NodeForm:
|
||||||
|
{
|
||||||
|
switch (getItem(p_index)->valueFrom())
|
||||||
|
{
|
||||||
|
case NLGEORGES::UFormElm::ValueParentForm:
|
||||||
|
{
|
||||||
|
return parentBrush;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
// parent status test kindof ugly, testing only 2 steps deep
|
||||||
|
// only needed for colorization as treeview default hides childs
|
||||||
|
// when parent is hidden
|
||||||
|
CFormItem *parent = getItem(p_index)->parent();
|
||||||
|
if (parent)
|
||||||
|
{
|
||||||
|
if (parent->nodeFrom() == NLGEORGES::UFormElm::NodeParentForm)
|
||||||
|
{
|
||||||
|
return parentBrush;
|
||||||
|
}
|
||||||
|
|
||||||
|
CFormItem *parentParent = parent->parent();
|
||||||
|
if (parentParent)
|
||||||
|
{
|
||||||
|
if (parentParent->nodeFrom() == NLGEORGES::UFormElm::NodeParentForm)
|
||||||
|
{
|
||||||
|
return parentBrush;
|
||||||
|
}
|
||||||
|
} // endif parentParent
|
||||||
|
} // endif parent
|
||||||
|
} // end default
|
||||||
|
} // end switch valueFrom
|
||||||
|
} // end case nodeForm
|
||||||
|
} // end switch nodeFrom
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
case Qt::DecorationRole:
|
||||||
|
{
|
||||||
|
if (p_index.column() == 2)
|
||||||
|
{
|
||||||
|
//p_index.
|
||||||
|
QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent());
|
||||||
|
CFormItem *item = getItem(in);
|
||||||
|
|
||||||
|
QString value = item->data(1).toString();
|
||||||
|
//QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str();
|
||||||
|
|
||||||
|
/*if (value.contains(".shape"))
|
||||||
|
{
|
||||||
|
if (Modules::objViewInt())
|
||||||
|
{
|
||||||
|
QIcon *icon = Modules::objViewInt()->saveOneImage(value.toStdString());
|
||||||
|
if (icon)
|
||||||
|
{
|
||||||
|
if(icon->isNull())
|
||||||
|
return QIcon(":/images/pqrticles.png");
|
||||||
|
else
|
||||||
|
return QIcon(*icon);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QIcon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
if(value.contains(".tga") || value.contains(".png"))
|
||||||
|
{
|
||||||
|
QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str();
|
||||||
|
if(path.isEmpty())
|
||||||
|
{
|
||||||
|
path = ":/images/pqrticles.png";
|
||||||
|
}
|
||||||
|
return QIcon(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case Qt::ToolTipRole:
|
||||||
|
{
|
||||||
|
if (p_index.column() == 2)
|
||||||
|
{
|
||||||
|
QModelIndex in = index(p_index.row(),p_index.column()-1,p_index.parent());
|
||||||
|
CFormItem *item = getItem(in);
|
||||||
|
QString value = item->data(1).toString();
|
||||||
|
|
||||||
|
/*if (value.contains(".shape"))
|
||||||
|
{
|
||||||
|
if (Modules::objViewInt())
|
||||||
|
{
|
||||||
|
QIcon *icon = Modules::objViewInt()->saveOneImage(value.toStdString());
|
||||||
|
if (icon)
|
||||||
|
{
|
||||||
|
if(icon->isNull())
|
||||||
|
return QIcon(":/images/pqrticles.png");
|
||||||
|
else
|
||||||
|
return QIcon(*icon);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return QIcon();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
if(value.contains(".tga") || value.contains(".png"))
|
||||||
|
{
|
||||||
|
QString path = NLMISC::CPath::lookup(value.toStdString(),false).c_str();
|
||||||
|
if(path.isEmpty())
|
||||||
|
{
|
||||||
|
path = ":/images/pqrticles.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
QString imageTooltip = QString("<img src='%1'>").arg(path);
|
||||||
|
|
||||||
|
return imageTooltip;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
CFormItem *CGeorgesFormModel::getItem(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (index.isValid())
|
||||||
|
{
|
||||||
|
CFormItem *item = static_cast<CFormItem*>(index.internalPointer());
|
||||||
|
if (item)
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
return m_rootItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
bool CGeorgesFormModel::setData(const QModelIndex &index, const QVariant &value,
|
||||||
|
int role)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (role != Qt::EditRole)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CFormItem *item = getItem(index);
|
||||||
|
bool result = item->setData(index.column(), value);
|
||||||
|
|
||||||
|
Q_EMIT dataChanged(index, index);
|
||||||
|
|
||||||
|
//setupModelData();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
Qt::ItemFlags CGeorgesFormModel::flags(const QModelIndex& index) const {
|
||||||
|
|
||||||
|
if (!index.isValid())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
Qt::ItemFlags returnValue = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
|
||||||
|
|
||||||
|
if(index.column() == 1)
|
||||||
|
returnValue |= Qt::ItemIsEditable;
|
||||||
|
|
||||||
|
return returnValue;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
QVariant CGeorgesFormModel::headerData(int section,
|
||||||
|
Qt::Orientation orientation, int role) const
|
||||||
|
{
|
||||||
|
if (orientation == Qt::Horizontal)
|
||||||
|
{
|
||||||
|
if (role == Qt::DisplayRole)
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
QModelIndex CGeorgesFormModel::index(int row, int column, const QModelIndex &parent)
|
||||||
|
const
|
||||||
|
{
|
||||||
|
if (!hasIndex(row, column, parent))
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
CFormItem *parentItem;
|
||||||
|
|
||||||
|
if (!parent.isValid())
|
||||||
|
parentItem = m_rootItem;
|
||||||
|
else
|
||||||
|
parentItem = static_cast<CFormItem*>(parent.internalPointer());
|
||||||
|
|
||||||
|
CFormItem *childItem = parentItem->child(row);
|
||||||
|
if (childItem)
|
||||||
|
return createIndex(row, column, childItem);
|
||||||
|
else
|
||||||
|
return QModelIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
QModelIndex CGeorgesFormModel::parent(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
if (!index.isValid())
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
CFormItem *childItem = static_cast<CFormItem*>(index.internalPointer());
|
||||||
|
CFormItem *parentItem = childItem->parent();
|
||||||
|
|
||||||
|
if (parentItem == m_rootItem)
|
||||||
|
return QModelIndex();
|
||||||
|
|
||||||
|
return createIndex(parentItem->row(), 0, parentItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
int CGeorgesFormModel::rowCount(const QModelIndex &parent) const {
|
||||||
|
|
||||||
|
CFormItem *parentItem;
|
||||||
|
if (parent.column() > 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if (!parent.isValid())
|
||||||
|
parentItem = m_rootItem;
|
||||||
|
else
|
||||||
|
parentItem = static_cast<CFormItem*>(parent.internalPointer());
|
||||||
|
|
||||||
|
return parentItem->childCount();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
int CGeorgesFormModel::columnCount(const QModelIndex &parent) const {
|
||||||
|
|
||||||
|
if (parent.isValid())
|
||||||
|
return static_cast<CFormItem*>(parent.internalPointer())->columnCount();
|
||||||
|
else
|
||||||
|
return m_rootItem->columnCount();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
void CGeorgesFormModel::loadFormData(UFormElm *root, CFormItem *parent) {
|
||||||
|
|
||||||
|
if (!root)
|
||||||
|
return;
|
||||||
|
|
||||||
|
uint num = 0;
|
||||||
|
|
||||||
|
|
||||||
|
if (root->isStruct())
|
||||||
|
{
|
||||||
|
//((CFormElm*)root)->getForm()->getComment();
|
||||||
|
uint structSize = 0;
|
||||||
|
root->getStructSize(structSize);
|
||||||
|
while (num < structSize)
|
||||||
|
{
|
||||||
|
UFormElm::TWhereIsNode *whereN = new UFormElm::TWhereIsNode;
|
||||||
|
UFormElm::TWhereIsValue *whereV = new UFormElm::TWhereIsValue;
|
||||||
|
// Append a new item to the current parent's list of children.
|
||||||
|
std::string elmName;
|
||||||
|
if(root->getStructNodeName(num, elmName))
|
||||||
|
{
|
||||||
|
QList<QVariant> columnData;
|
||||||
|
//QVariant value;
|
||||||
|
std::string value;
|
||||||
|
//NLMISC::CRGBA value_color;
|
||||||
|
//uint value_uint;
|
||||||
|
//sint value_sint;
|
||||||
|
//double value_double;
|
||||||
|
QString elmtType = "";
|
||||||
|
UFormElm *elmt = 0;
|
||||||
|
if(root->getNodeByName(&elmt, elmName.c_str(), whereN, true))
|
||||||
|
{
|
||||||
|
if (elmt)
|
||||||
|
{
|
||||||
|
if (elmt->isArray())
|
||||||
|
elmtType = "Array";
|
||||||
|
if (elmt->isStruct())
|
||||||
|
elmtType = "Struct";
|
||||||
|
if (elmt->isAtom())
|
||||||
|
{
|
||||||
|
elmtType = "Atom";
|
||||||
|
uint numDefinitions = 0;
|
||||||
|
const UType *type = elmt->getType();
|
||||||
|
if (type)
|
||||||
|
{
|
||||||
|
numDefinitions = type->getNumDefinition();
|
||||||
|
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
|
||||||
|
switch (type->getType())
|
||||||
|
{
|
||||||
|
case UType::UnsignedInt:
|
||||||
|
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString();
|
||||||
|
elmtType.append("_uint");break;
|
||||||
|
case UType::SignedInt:
|
||||||
|
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble()).toStdString();
|
||||||
|
elmtType.append("_sint");break;
|
||||||
|
case UType::Double:
|
||||||
|
value = QString("%1").arg(QString("%1").arg(value.c_str()).toDouble(),0,'f',1).toStdString();
|
||||||
|
elmtType.append("_double");break;
|
||||||
|
case UType::String:
|
||||||
|
elmtType.append("_string");break;
|
||||||
|
case UType::Color:
|
||||||
|
elmtType.append("_color");break;
|
||||||
|
default:
|
||||||
|
elmtType.append("_unknownType");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
elmtType.append("_noType");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (numDefinitions)
|
||||||
|
{
|
||||||
|
std::string l, v;
|
||||||
|
QString tmpLabel, tmpValue;
|
||||||
|
for (uint i = 0; i < numDefinitions; i++)
|
||||||
|
{
|
||||||
|
type->getDefinition(i,l,v);
|
||||||
|
tmpLabel = l.c_str();
|
||||||
|
tmpValue = v.c_str();
|
||||||
|
if (type->getType() == UType::SignedInt)
|
||||||
|
{
|
||||||
|
if (QString("%1").arg(value.c_str()).toDouble() == tmpValue.toDouble()) {
|
||||||
|
value = l;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (type->getType() == UType::String)
|
||||||
|
{
|
||||||
|
if (QString(value.c_str()) == tmpValue)
|
||||||
|
{
|
||||||
|
value = l;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (elmt->isVirtualStruct())
|
||||||
|
{
|
||||||
|
root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
|
||||||
|
elmtType = "VirtualStruct";
|
||||||
|
}
|
||||||
|
switch (*whereN)
|
||||||
|
{
|
||||||
|
case UFormElm::NodeForm:
|
||||||
|
elmtType.append("_fromForm"); break;
|
||||||
|
case UFormElm::NodeParentForm:
|
||||||
|
elmtType.append("_fromParentForm"); break;
|
||||||
|
case UFormElm::NodeDfn:
|
||||||
|
elmtType.append("_isDFN"); break;
|
||||||
|
case UFormElm::NodeType:
|
||||||
|
elmtType.append("_isType"); break;
|
||||||
|
default:
|
||||||
|
elmtType.append("_noNode");
|
||||||
|
}
|
||||||
|
switch (*whereV)
|
||||||
|
{
|
||||||
|
case UFormElm::ValueForm:
|
||||||
|
elmtType.append("_formValue"); break;
|
||||||
|
case UFormElm::ValueParentForm:
|
||||||
|
elmtType.append("_parentValue"); break;
|
||||||
|
case UFormElm::ValueDefaultDfn:
|
||||||
|
elmtType.append("_dfnValue"); break;
|
||||||
|
case UFormElm::ValueDefaultType:
|
||||||
|
elmtType.append("_typeValue"); break;
|
||||||
|
default:
|
||||||
|
elmtType.append("_noValue");
|
||||||
|
}
|
||||||
|
columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType;
|
||||||
|
parent->appendChild(new CFormItem(elmt, columnData, parent, *whereV, *whereN));
|
||||||
|
//if (parents.last()->childCount() > 0) {
|
||||||
|
// parents << parents.last()->child(parents.last()->childCount()-1);
|
||||||
|
//}
|
||||||
|
loadFormData(elmt, parent->child(parent->childCount()-1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// add Defaults
|
||||||
|
// TODO: spams warnings for non ATOM values but i dont get type of non existing nodes
|
||||||
|
bool success = root->getValueByName(value, elmName.c_str(),UFormElm::Eval,whereV);
|
||||||
|
switch (*whereN)
|
||||||
|
{
|
||||||
|
case UFormElm::NodeForm:
|
||||||
|
elmtType.append("_fromForm"); break;
|
||||||
|
case UFormElm::NodeParentForm:
|
||||||
|
elmtType.append("_fromParentForm"); break;
|
||||||
|
case UFormElm::NodeDfn:
|
||||||
|
elmtType.append("_isDFN"); break;
|
||||||
|
case UFormElm::NodeType:
|
||||||
|
elmtType.append("_isType"); break;
|
||||||
|
default:
|
||||||
|
elmtType.append("_noNode");
|
||||||
|
}
|
||||||
|
switch (*whereV)
|
||||||
|
{
|
||||||
|
case UFormElm::ValueForm:
|
||||||
|
elmtType.append("_formValue"); break;
|
||||||
|
case UFormElm::ValueParentForm:
|
||||||
|
elmtType.append("_parentValue"); break;
|
||||||
|
case UFormElm::ValueDefaultDfn:
|
||||||
|
elmtType.append("_dfnValue"); break;
|
||||||
|
case UFormElm::ValueDefaultType:
|
||||||
|
elmtType.append("_typeValue"); break;
|
||||||
|
default:
|
||||||
|
elmtType.append("_noValue");
|
||||||
|
}
|
||||||
|
|
||||||
|
columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType;
|
||||||
|
parent->appendChild(new CFormItem(elmt, columnData, parent, *whereV, *whereN));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nlinfo("getNodeByName returned false");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (root->isArray())
|
||||||
|
{
|
||||||
|
uint arraySize = 0;
|
||||||
|
root->getArraySize(arraySize);
|
||||||
|
while (num < arraySize)
|
||||||
|
{
|
||||||
|
std::string elmName;
|
||||||
|
if(root->getArrayNodeName(elmName, num))
|
||||||
|
{
|
||||||
|
QList<QVariant> columnData;
|
||||||
|
std::string value;
|
||||||
|
QString elmtType = "";
|
||||||
|
|
||||||
|
UFormElm *elmt = 0;
|
||||||
|
if(root->getArrayNode(&elmt,0) && elmt)
|
||||||
|
{
|
||||||
|
if (elmt->isArray())
|
||||||
|
elmtType = "Array";
|
||||||
|
if (elmt->isStruct()) {
|
||||||
|
elmtType = "Struct";
|
||||||
|
}
|
||||||
|
if (elmt->isAtom())
|
||||||
|
{
|
||||||
|
elmt->getValue(value);
|
||||||
|
elmtType = "Atom";
|
||||||
|
}
|
||||||
|
if (elmt->isVirtualStruct())
|
||||||
|
elmtType = "VirtualStruct";
|
||||||
|
|
||||||
|
elmtType.append("_arrayValue");
|
||||||
|
columnData << QString(elmName.c_str()) << QString(value.c_str()) << "";// << elmtType;
|
||||||
|
parent->appendChild(new CFormItem(elmt, columnData, parent));
|
||||||
|
loadFormData(elmt, parent->child(parent->childCount()-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
void CGeorgesFormModel::loadFormHeader()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (m_parents.size())
|
||||||
|
{
|
||||||
|
CFormItem *fi_pars = new CFormItem(m_rootElm, QList<QVariant>() << "parents" << "" << "", m_rootItem);
|
||||||
|
m_rootItem->appendChild(fi_pars);
|
||||||
|
|
||||||
|
Q_FOREACH(QString str, m_parents)
|
||||||
|
{
|
||||||
|
fi_pars->appendChild(new CFormItem(m_rootElm, QList<QVariant>() << str << "" << "", fi_pars));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*QStringList dfns = _dependencies["dfn"];
|
||||||
|
QStringList typs = _dependencies["typ"];
|
||||||
|
|
||||||
|
_dependencies.remove("dfn");
|
||||||
|
_dependencies.remove("typ");
|
||||||
|
|
||||||
|
CFormItem *fi_dep = new CFormItem(_rootElm, QList<QVariant>() << "dependencies", _rootItem);
|
||||||
|
_rootItem->appendChild(fi_dep);
|
||||||
|
|
||||||
|
if (!dfns.isEmpty()) {
|
||||||
|
CFormItem *fi_dfn = new CFormItem(_rootElm, QList<QVariant>() << "dfn", fi_dep);
|
||||||
|
fi_dep->appendChild(fi_dfn);
|
||||||
|
foreach(QString str, dfns) {
|
||||||
|
fi_dfn->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_dfn));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!typs.isEmpty()) {
|
||||||
|
CFormItem *fi_typ = new CFormItem(_rootElm, QList<QVariant>() << "typ", fi_dep);
|
||||||
|
fi_dep->appendChild(fi_typ);
|
||||||
|
foreach(QString str, typs) {
|
||||||
|
fi_typ->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_typ));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!_dependencies.isEmpty()) {
|
||||||
|
CFormItem *fi_other = new CFormItem(_rootElm, QList<QVariant>() << "other", fi_dep);
|
||||||
|
fi_dep->appendChild(fi_other);
|
||||||
|
foreach(QStringList list, _dependencies) {
|
||||||
|
foreach(QString str, list) {
|
||||||
|
fi_other->appendChild(new CFormItem(_rootElm, QList<QVariant>() << str, fi_other));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
void CGeorgesFormModel::setupModelData()
|
||||||
|
{
|
||||||
|
loadFormHeader();
|
||||||
|
loadFormData(m_rootElm, m_rootItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
void CGeorgesFormModel::setShowParents( bool show ) {
|
||||||
|
m_showParents = show;
|
||||||
|
Q_EMIT layoutAboutToBeChanged();
|
||||||
|
Q_EMIT layoutChanged();
|
||||||
|
}
|
||||||
|
void CGeorgesFormModel::setShowDefaults( bool show )
|
||||||
|
{
|
||||||
|
m_showDefaults = show;
|
||||||
|
Q_EMIT layoutAboutToBeChanged();
|
||||||
|
Q_EMIT layoutChanged();
|
||||||
|
}
|
||||||
|
} /* namespace Plugin */
|
||||||
|
|
||||||
|
/* end of file */
|
@ -0,0 +1,80 @@
|
|||||||
|
// 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 GEORGESFORM_MODEL_H
|
||||||
|
#define GEORGESFORM_MODEL_H
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QAbstractItemModel>
|
||||||
|
#include <QModelIndex>
|
||||||
|
#include <QStringList>
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
// project includes
|
||||||
|
|
||||||
|
namespace NLGEORGES {
|
||||||
|
class UFormElm;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
class CFormItem;
|
||||||
|
|
||||||
|
class CGeorgesFormModel : public QAbstractItemModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
CGeorgesFormModel(NLGEORGES::UFormElm *root, QMap< QString, QStringList> deps,
|
||||||
|
QString comment, QStringList parents, bool* expanded, QObject *parent = 0);
|
||||||
|
~CGeorgesFormModel();
|
||||||
|
|
||||||
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||||
|
Qt::ItemFlags flags(const QModelIndex &index) 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 parent(const QModelIndex &index) const;
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||||
|
CFormItem *getItem(const QModelIndex &index) const;
|
||||||
|
CGeorgesFormModel *model() { return this; }
|
||||||
|
bool showParents() { return m_showParents;}
|
||||||
|
bool showDefaults() { return m_showDefaults;}
|
||||||
|
void setShowParents( bool show );
|
||||||
|
void setShowDefaults( bool show );
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setupModelData();
|
||||||
|
void loadFormData(NLGEORGES::UFormElm *rootElm, CFormItem *parent);
|
||||||
|
void loadFormHeader();
|
||||||
|
|
||||||
|
CFormItem* m_rootItem;
|
||||||
|
NLGEORGES::UFormElm* m_rootElm;
|
||||||
|
QMap< QString, QStringList> m_dependencies;
|
||||||
|
QString m_comments;
|
||||||
|
QStringList m_parents;
|
||||||
|
QList<const QModelIndex*>* m_parentRows;
|
||||||
|
|
||||||
|
bool m_showParents;
|
||||||
|
bool m_showDefaults;
|
||||||
|
bool *m_expanded;
|
||||||
|
|
||||||
|
};/* class CGeorgesFormModel */
|
||||||
|
|
||||||
|
} /* namespace Plugin */
|
||||||
|
|
||||||
|
#endif // GEORGESFORM_MODEL_H
|
@ -0,0 +1,81 @@
|
|||||||
|
// 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/>.
|
||||||
|
|
||||||
|
// NeL includes
|
||||||
|
#include <nel/misc/debug.h>
|
||||||
|
#include <nel/georges/u_form_elm.h>
|
||||||
|
|
||||||
|
// project includes
|
||||||
|
#include "formitem.h"
|
||||||
|
#include "georgesform_proxy_model.h"
|
||||||
|
#include "georgesform_model.h"
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
bool CGeorgesFormProxyModel::filterAcceptsRow(int sourceRow,
|
||||||
|
const QModelIndex &sourceParent) const
|
||||||
|
{
|
||||||
|
// column doesnt matter for item
|
||||||
|
CGeorgesFormModel *smodel = dynamic_cast<CGeorgesFormModel *>(sourceModel());
|
||||||
|
QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent);
|
||||||
|
CFormItem *item = smodel->getItem(index);
|
||||||
|
|
||||||
|
// if elm not existing it must be some kind of default or type value
|
||||||
|
if(!item->getFormElm())
|
||||||
|
{
|
||||||
|
return smodel->showDefaults();
|
||||||
|
}
|
||||||
|
|
||||||
|
// else it might be some parent elm
|
||||||
|
switch (item->nodeFrom())
|
||||||
|
{
|
||||||
|
case NLGEORGES::UFormElm::NodeParentForm:
|
||||||
|
{
|
||||||
|
return smodel->showParents();
|
||||||
|
}
|
||||||
|
case NLGEORGES::UFormElm::NodeForm:
|
||||||
|
{
|
||||||
|
switch (item->valueFrom())
|
||||||
|
{
|
||||||
|
case NLGEORGES::UFormElm::ValueParentForm:
|
||||||
|
{
|
||||||
|
return smodel->showParents();
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
CFormItem *parent = item->parent();
|
||||||
|
if (parent && (parent->nodeFrom() == NLGEORGES::UFormElm::NodeParentForm))
|
||||||
|
{
|
||||||
|
return smodel->showParents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
|
bool CGeorgesFormProxyModel::filterAcceptsColumn(int sourceRow,
|
||||||
|
const QModelIndex &sourceParent) const
|
||||||
|
{
|
||||||
|
return QSortFilterProxyModel::filterAcceptsColumn(sourceRow, sourceParent);
|
||||||
|
}
|
||||||
|
} /* namespace Plugin */
|
||||||
|
|
||||||
|
/* end of file */
|
@ -0,0 +1,45 @@
|
|||||||
|
// 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 GEORGESFORM_PROXY_MODEL_H
|
||||||
|
#define GEORGESFORM_PROXY_MODEL_H
|
||||||
|
|
||||||
|
// Qt includes
|
||||||
|
#include <QSortFilterProxyModel>
|
||||||
|
|
||||||
|
namespace Plugin
|
||||||
|
{
|
||||||
|
|
||||||
|
class CGeorgesFormProxyModel : public QSortFilterProxyModel
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
CGeorgesFormProxyModel(QObject *parent = 0): QSortFilterProxyModel(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
~CGeorgesFormProxyModel()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool filterAcceptsColumn ( int source_column, const QModelIndex & source_parent ) const ;
|
||||||
|
virtual bool filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const ;
|
||||||
|
|
||||||
|
};/* class CGeorgesFormProxyModel */
|
||||||
|
|
||||||
|
} /* namespace NLQT */
|
||||||
|
|
||||||
|
#endif // GEORGESFORM_PROXY_MODEL_H
|
Binary file not shown.
After Width: | Height: | Size: 9.1 KiB |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue