Changed: #1168 default checkbox activated, formdelegate adapted to introduced proxymodel

This commit is contained in:
aquiles 2010-11-08 14:14:28 +01:00
parent 9891284603
commit 2e2d0b7d52
9 changed files with 242 additions and 82 deletions

View file

@ -35,6 +35,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QPainter>
// 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<CFormItem*>(index.internalPointer());
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())
if (value.isEmpty() || !mp || !m)
return 0;
const NLGEORGES::UType *type = dynamic_cast<const CGeorgesFormModel *>(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<const CGeorgesFormModel *>(index.model())->
getItem(index)->getFormElm()->getType();
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();
@ -175,8 +179,10 @@ namespace NLQT
void FormDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const
{
const NLGEORGES::UType *type = dynamic_cast<const CGeorgesFormModel *>(index.model())->
getItem(index)->getFormElm()->getType();
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)

View file

@ -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())
{

View file

@ -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<CFormItem*>(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<CGeorgesFormProxyModel *>(_ui.treeView->model());
CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(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<CGeorgesFormProxyModel *>(_ui.treeView->model());
//CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(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 */

View file

@ -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;

View file

@ -18,8 +18,8 @@
</property>
<property name="minimumSize">
<size>
<width>241</width>
<height>236</height>
<width>199</width>
<height>165</height>
</size>
</property>
<property name="windowTitle">

View file

@ -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 */

View file

@ -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<const QModelIndex*>* _parentRows;
bool _showParents;
bool _showDefaults;
};/* class CGeorgesFormModel */
} /* namespace NLQT */

View file

@ -17,9 +17,16 @@
*/
#include "georgesform_proxy_model.h"
#include "georgesform_model.h"
// NeL includes
#include <nel/misc/debug.h>
#include <nel/georges/u_form_elm.h>
// project includes
#include "formitem.h"
#include <QDebug>
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<CGeorgesFormModel *>(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 */

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>472</width>
<height>310</height>
<width>540</width>
<height>370</height>
</rect>
</property>
<property name="sizePolicy">
@ -18,8 +18,8 @@
</property>
<property name="minimumSize">
<size>
<width>89</width>
<height>122</height>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
@ -41,7 +41,7 @@
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
<height>0</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout">