void CGeorgesTreeViewDialog::doubleClicked ( const QModelIndex & index ) { // TODO: this is messy :( perhaps this can be done better CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(_ui.treeView->model()); CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel()); QModelIndex in = mp->mapToSource(index); // 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.toUtf8().constData(),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.toUtf8().constData(),""); } return; } } // open eg parent files if (!path.isEmpty()) Q_EMIT changeFile(path); } }
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; }
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).toUtf8().constData()); // 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; }