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

    }
}