diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/formdelegate.cpp b/code/ryzom/tools/leveldesign/georges_editor_qt/src/formdelegate.cpp index 2dc637058..ff48889fc 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/formdelegate.cpp +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/formdelegate.cpp @@ -35,6 +35,7 @@ along with this program. If not, see . #include // Project includes #include "georgesform_model.h" +#include "georgesform_proxy_model.h" #include "formitem.h" namespace NLQT @@ -49,14 +50,15 @@ namespace NLQT const QStyleOptionViewItem & option , const QModelIndex &index) const { - CFormItem *item = static_cast(index.internalPointer()); + const CGeorgesFormProxyModel * mp = dynamic_cast(index.model()); + const CGeorgesFormModel * m = dynamic_cast(mp->sourceModel()); + CFormItem *item = static_cast(mp->mapToSource(index).internalPointer()); QString value = item->data(1).toString(); - if (value.isEmpty()) + if (value.isEmpty() || !mp || !m) return 0; - const NLGEORGES::UType *type = dynamic_cast(index.model())-> - getItem(index)->getFormElm()->getType(); + const NLGEORGES::UType *type = m->getItem(mp->mapToSource(index))->getFormElm()->getType(); if(type) { int numDefinitions = type->getNumDefinition(); @@ -130,8 +132,10 @@ namespace NLQT void FormDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { - const NLGEORGES::UType *type = dynamic_cast(index.model())-> - getItem(index)->getFormElm()->getType(); + const CGeorgesFormProxyModel * mp = dynamic_cast(index.model()); + const CGeorgesFormModel * m = dynamic_cast(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(); @@ -175,8 +179,10 @@ namespace NLQT void FormDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { - const NLGEORGES::UType *type = dynamic_cast(index.model())-> - getItem(index)->getFormElm()->getType(); + const CGeorgesFormProxyModel * mp = dynamic_cast(index.model()); + const CGeorgesFormModel * m = dynamic_cast(mp->sourceModel()); + + const NLGEORGES::UType *type = m->getItem(mp->mapToSource(index))->getFormElm()->getType(); int numDefinitions = type->getNumDefinition(); if (numDefinitions) diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/formitem.cpp b/code/ryzom/tools/leveldesign/georges_editor_qt/src/formitem.cpp index 74f3f5625..3ec84e4e1 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/formitem.cpp +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/formitem.cpp @@ -85,6 +85,10 @@ namespace NLQT if (column < 0 || column >= itemData.size()) return false; + // TODO: default values + if (!formElm) + return false; + itemData[column] = value; if (formElm->isAtom()) { diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.cpp b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.cpp index 3eb02e301..b163799d2 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.cpp +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.cpp @@ -65,10 +65,12 @@ namespace NLQT _ui.treeView->setItemDelegateForColumn(1, formdelegate); - connect(_ui.treeView, SIGNAL(doubleClicked (QModelIndex)), - this, SLOT(doubleClicked (QModelIndex))); - connect(_ui.checkBoxParent, SIGNAL(stateChanged(int)), - this, SLOT(showParentRows (int))); + //connect(_ui.treeView, SIGNAL(doubleClicked (QModelIndex)), + // this, SLOT(doubleClicked (QModelIndex))); + connect(_ui.checkBoxParent, SIGNAL(toggled(bool)), + this, SLOT(filterRows())); + connect(_ui.checkBoxDefaults, SIGNAL(toggled(bool)), + this, SLOT(filterRows())); } CGeorgesTreeViewDialog::~CGeorgesTreeViewDialog() @@ -131,9 +133,9 @@ namespace NLQT _ui.treeView->resizeColumnToContents(0); _ui.treeView->resizeColumnToContents(1); _ui.treeView->resizeColumnToContents(2); - _ui.treeView->hideColumn(3); + //_ui.treeView->hideColumn(3); - showParentRows(_ui.checkBoxParent->isChecked()); + filterRows(); //_ui.treeView->setRowHidden(0,QModelIndex(),true); connect(model, SIGNAL(dataChanged(const QModelIndex, const QModelIndex)), @@ -237,8 +239,10 @@ namespace NLQT void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) { - if (index.column() == 1) + if (index.column() == 1) { + //QTreeView::doubleClicked(index); return; + } CFormItem *item = static_cast(index.internalPointer()); @@ -264,53 +268,61 @@ namespace NLQT } else { - Modules::mainWin().getTreeViewList().removeOne(this); - if(!Modules::mainWin().getTreeViewList().size()) + if(Modules::mainWin().getTreeViewList().size() == 1) { - Modules::mainWin().createEmptyView(); + Modules::mainWin().createEmptyView( + Modules::mainWin().getTreeViewList().takeFirst()); } deleteLater(); } } - void CGeorgesTreeViewDialog::showParentRows(int newState) + void CGeorgesTreeViewDialog::filterRows() { + nlinfo("CGeorgesTreeViewDialog::filterRows"); CGeorgesFormProxyModel * mp = dynamic_cast(_ui.treeView->model()); CGeorgesFormModel *m = dynamic_cast(mp->sourceModel()); - - for (int i = 0; i < m->rowCount(); i++) - { - const QModelIndex in = m->index(i,0); - if (m->getItem(in)->nodeFrom() == UFormElm::NodeParentForm) - { - if (newState == Qt::Checked) - { - _ui.treeView->setRowHidden(in.row(),in.parent(),false); - } - else - { - _ui.treeView->setRowHidden(in.row(),in.parent(),true); - } - } - else - { // search childs // recursive? - for (int j = 0; j < m->rowCount(in); j++) - { - const QModelIndex in2 = m->index(j,0,in); - if (m->getItem(in2)->nodeFrom() == UFormElm::NodeParentForm) - { - if (newState == Qt::Checked) - { - _ui.treeView->setRowHidden(in2.row(),in,false); - } - else - { - _ui.treeView->setRowHidden(in2.row(),in,true); - } - } - } - } // end of search childs + if (m) { + m->setShowParents(_ui.checkBoxParent->isChecked()); + m->setShowDefaults(_ui.checkBoxDefaults->isChecked()); } + + //CGeorgesFormProxyModel * mp = dynamic_cast(_ui.treeView->model()); + //CGeorgesFormModel *m = dynamic_cast(mp->sourceModel()); + + //for (int i = 0; i < m->rowCount(); i++) + //{ + // const QModelIndex in = m->index(i,0); + // if (m->getItem(in)->nodeFrom() == UFormElm::NodeParentForm) + // { + // if (newState == Qt::Checked) + // { + // _ui.treeView->setRowHidden(in.row(),in.parent(),false); + // } + // else + // { + // _ui.treeView->setRowHidden(in.row(),in.parent(),true); + // } + // } + // else + // { // search childs // recursive? + // for (int j = 0; j < m->rowCount(in); j++) + // { + // const QModelIndex in2 = m->index(j,0,in); + // if (m->getItem(in2)->nodeFrom() == UFormElm::NodeParentForm) + // { + // if (newState == Qt::Checked) + // { + // _ui.treeView->setRowHidden(in2.row(),in,false); + // } + // else + // { + // _ui.treeView->setRowHidden(in2.row(),in,true); + // } + // } + // } + // } // end of search childs + //} } } /* namespace NLQT */ diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.h b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.h index 39e7cfbc9..88fa02c7b 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.h +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_dialog.h @@ -66,7 +66,7 @@ namespace NLQT private Q_SLOTS: void doubleClicked ( const QModelIndex & index ); void modifiedFile( ); - void showParentRows(int); + void filterRows(); private: Ui::CGeorgesTreeViewDialog _ui; diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_form.ui b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_form.ui index 873747794..4cff36c92 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_form.ui +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georges_treeview_form.ui @@ -18,8 +18,8 @@ - 241 - 236 + 199 + 165 diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.cpp b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.cpp index 3ce2c30a6..79fe69319 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.cpp +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.cpp @@ -76,11 +76,48 @@ namespace NLQT } case Qt::BackgroundRole: { - if (getItem(p_index)->valueFrom() == UFormElm::ValueDefaultDfn) - return QBrush(QColor(255,0,0,30)); - if (getItem(p_index)->nodeFrom() == UFormElm::NodeParentForm) - return QBrush(QColor(0,255,0,30)); - return QVariant(); + QBrush defaultBrush = QBrush(QColor(255,0,0,30)); + QBrush parentBrush = QBrush(QColor(0,255,0,30)); + + switch (getItem(p_index)->nodeFrom()) + { + case NLGEORGES::UFormElm::NodeParentForm: + { + switch (getItem(p_index)->valueFrom()) + { + case NLGEORGES::UFormElm::ValueDefaultDfn: + { + return defaultBrush; + } + default: + { + return parentBrush; + } + } + } + case NLGEORGES::UFormElm::NodeForm: + { + switch (getItem(p_index)->valueFrom()) + { + case NLGEORGES::UFormElm::ValueParentForm: + { + return parentBrush; + } + case NLGEORGES::UFormElm::ValueDefaultDfn: + { + return defaultBrush; + } + default: + { + return QVariant(); + } + } + } + default: + { + return QVariant(); + } + } } case Qt::DecorationRole: { @@ -363,21 +400,57 @@ namespace NLQT elmtType.append("_noValue"); } columnData << QString(elmName.c_str()) << QString(value.c_str()) << "" << elmtType; + qDebug() << columnData; 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)); + //columnData << QString(elmName.c_str()) << QString("default") << QString("default"); //parent->appendChild(new CFormItem(elmt, columnData, parent, UFormElm::ValueDefaultDfn, UFormElm::NodeDfn)); } + } + else + { + nlinfo("getNodeByName returned false"); } } - num++; } } @@ -474,6 +547,20 @@ namespace NLQT loadFormHeader(); loadFormData(_rootElm, _rootItem); } + + /******************************************************************************/ + + void CGeorgesFormModel::setShowParents( bool show ) { + _showParents = show; + Q_EMIT layoutAboutToBeChanged(); + Q_EMIT layoutChanged(); + } + void CGeorgesFormModel::setShowDefaults( bool show ) + { + _showDefaults = show; + Q_EMIT layoutAboutToBeChanged(); + Q_EMIT layoutChanged(); + } } /* namespace NLQT */ /* end of file */ diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.h b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.h index 923da9fa1..d7665c271 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.h +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_model.h @@ -55,6 +55,10 @@ namespace NLQT int columnCount(const QModelIndex &parent = QModelIndex()) const; CFormItem *getItem(const QModelIndex &index) const; CGeorgesFormModel *model() { return this; } + bool showParents() { return _showParents;} + bool showDefaults() { return _showDefaults;} + void setShowParents( bool show ); + void setShowDefaults( bool show ); private: void setupModelData(); @@ -68,6 +72,9 @@ namespace NLQT QStringList _parents; QList* _parentRows; + bool _showParents; + bool _showDefaults; + };/* class CGeorgesFormModel */ } /* namespace NLQT */ diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_proxy_model.cpp b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_proxy_model.cpp index 5ab408525..ff09f73f5 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_proxy_model.cpp +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/georgesform_proxy_model.cpp @@ -17,9 +17,16 @@ */ #include "georgesform_proxy_model.h" +#include "georgesform_model.h" // NeL includes #include +#include + +// project includes +#include "formitem.h" + +#include namespace NLQT { @@ -27,21 +34,58 @@ namespace NLQT bool CGeorgesFormProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - nlinfo("CGeorgesFormProxyModel::filterAcceptsRow"); - //QModelIndex index0 = sourceModel()->index(sourceRow, 0, sourceParent); - //QModelIndex index1 = sourceModel()->index(sourceRow, 1, sourceParent); - //QModelIndex index2 = sourceModel()->index(sourceRow, 2, sourceParent); + //nlinfo("CGeorgesFormProxyModel::filterAcceptsRow"); - //return (sourceModel()->data(index0).toString().contains(filterRegExp()) - // || sourceModel()->data(index1).toString().contains(filterRegExp())) - // && dateInRange(sourceModel()->data(index2).toDate()); - - // if (getItem(p_index)->valueFrom() == UFormElm::ValueDefaultDfn) - // return QBrush(QColor(255,0,0,30)); - // if (getItem(p_index)->nodeFrom() == UFormElm::NodeParentForm) - // return QBrush(QColor(0,255,0,30)); - // return QVariant(); - return true; + // column doesnt matter for item + CGeorgesFormModel *smodel = dynamic_cast(sourceModel()); + QModelIndex index = sourceModel()->index(sourceRow, 0, sourceParent); + 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)); + switch (item->nodeFrom()) + { + case NLGEORGES::UFormElm::NodeParentForm: + { + switch (item->valueFrom()) + { + case NLGEORGES::UFormElm::ValueDefaultDfn: + { + return smodel->showDefaults(); + } + default: + { + return smodel->showParents();; + } + } + } + case NLGEORGES::UFormElm::NodeForm: + { + switch (item->valueFrom()) + { + case NLGEORGES::UFormElm::ValueParentForm: + { + return smodel->showParents(); + } + case NLGEORGES::UFormElm::ValueDefaultDfn: + { + return smodel->showDefaults(); + } + default: + { + return true; + } + } + } + default: + { + return true; + } + } } /******************************************************************************/ @@ -49,7 +93,7 @@ namespace NLQT bool CGeorgesFormProxyModel::filterAcceptsColumn(int sourceRow, const QModelIndex &sourceParent) const { - nlinfo("CGeorgesFormProxyModel::filterAcceptsColumn"); + //nlinfo("CGeorgesFormProxyModel::filterAcceptsColumn"); return QSortFilterProxyModel::filterAcceptsColumn(sourceRow, sourceParent); } } /* namespace NLQT */ diff --git a/code/ryzom/tools/leveldesign/georges_editor_qt/src/log_form.ui b/code/ryzom/tools/leveldesign/georges_editor_qt/src/log_form.ui index 7a22af13e..218a6e43d 100644 --- a/code/ryzom/tools/leveldesign/georges_editor_qt/src/log_form.ui +++ b/code/ryzom/tools/leveldesign/georges_editor_qt/src/log_form.ui @@ -6,8 +6,8 @@ 0 0 - 472 - 310 + 540 + 370 @@ -18,8 +18,8 @@ - 89 - 122 + 0 + 0 @@ -41,7 +41,7 @@ 0 - 100 + 0