コード例 #1
0
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);

    }
}
コード例 #2
0
void CGeorgesTreeViewDialog::filterRows()
{
    nlinfo("CGeorgesTreeViewDialog::filterRows");
    CGeorgesFormProxyModel * mp = dynamic_cast<CGeorgesFormProxyModel *>(_ui.treeView->model());
    CGeorgesFormModel *m = dynamic_cast<CGeorgesFormModel *>(mp->sourceModel());
    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
    //}
}
コード例 #3
0
	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;
	}