Ejemplo n.º 1
0
// Check if any managed widgets are selected. If so, iterate over
// selection and deselect all unmanaged objects
bool ObjectInspector::ObjectInspectorPrivate::checkManagedWidgetSelection(const QModelIndexList &rowSelection)
{
    bool isManagedWidgetSelection = false;
    QItemSelectionModel *selectionModel = m_treeView->selectionModel();
    const QModelIndexList::const_iterator cscend = rowSelection.constEnd();
    for (QModelIndexList::const_iterator it = rowSelection.constBegin(); it != cscend; ++it) {
        QObject *object = m_model->objectAt(*it);
        if (selectionType(m_formWindow, object) == ManagedWidgetSelection) {
            isManagedWidgetSelection = true;
            break;
        }
    }

    if (!isManagedWidgetSelection)
        return false;
    // Need to unselect unmanaged ones
    const bool blocked = selectionModel->blockSignals(true);
    for (QModelIndexList::const_iterator it = rowSelection.constBegin(); it != cscend; ++it) {
        QObject *object = m_model->objectAt(*it);
        if (selectionType(m_formWindow, object) != ManagedWidgetSelection)
            selectionModel->select(*it, QItemSelectionModel::Deselect|QItemSelectionModel::Rows);
    }
    selectionModel->blockSignals(blocked);
    return true;
}
Ejemplo n.º 2
0
QList<QgsSymbolV2*> QgsGraduatedSymbolRendererV2Widget::selectedSymbols()
{
  QList<QgsSymbolV2*> selectedSymbols;

  QItemSelectionModel* m = viewGraduated->selectionModel();
  QModelIndexList selectedIndexes = m->selectedRows( 1 );
  if ( m && selectedIndexes.size() > 0 )
  {
    const QgsRangeList& ranges = mRenderer->ranges();
    QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
    for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
    {
      QStandardItem* currentItem = qobject_cast<const QStandardItemModel*>( m->model() )->itemFromIndex( *indexIt );
      if ( currentItem )
      {
        QStringList list = currentItem->data( 0 ).toString().split( " " );
        if ( list.size() < 3 )
        {
          continue;
        }

        double lowerBound = list.at( 0 ).toDouble();
        double upperBound = list.at( 2 ).toDouble();
        QgsSymbolV2* s = findSymbolForRange( lowerBound, upperBound, ranges );
        if ( s )
        {
          selectedSymbols.append( s );
        }
      }
    }
  }
  return selectedSymbols;
}
Ejemplo n.º 3
0
// Slot for performing action when the Add button is clicked
void SaSourceSelect::addTables()
{
  mSelectedTables.clear();

  QItemSelection selection = mTablesTreeView->selectionModel()->selection();
  QModelIndexList selectedIndices = selection.indexes();
  QModelIndexList::const_iterator selected_it = selectedIndices.constBegin();
  for ( ; selected_it != selectedIndices.constEnd(); ++selected_it )
  {
    if ( !selected_it->parent().isValid() || selected_it->column() > 0 )
    {
      //top level items only contain the schema names
      continue;
    }

    mSelectedTables << layerURI( mProxyModel.mapToSource( *selected_it ) );
  }

  if ( mSelectedTables.empty() )
  {
    QMessageBox::information( this, tr( "Select Table" ), tr( "You must select a table in order to add a layer." ) );
  }
  else
  {
    accept();
  }
}
Ejemplo n.º 4
0
void DesktopWindow::onStickToCurrentPos(bool toggled) {
    QModelIndexList indexes = listView_->selectionModel()->selectedIndexes();
    if(!indexes.isEmpty()) {
        bool relayout(false);
        QModelIndexList::const_iterator it;
        for(it = indexes.constBegin(); it != indexes.constEnd(); ++it) {
            auto file = proxyModel_->fileInfoFromIndex(*it);
            auto name = file->name();
            if(toggled) { // remember the current custom position
                QRect itemRect = listView_->rectForIndex(*it);
                customItemPos_[name] = itemRect.topLeft();
            }
            else { // cancel custom position and perform relayout
                auto item = customItemPos_.find(name);
                if(item != customItemPos_.end()) {
                    customItemPos_.erase(item);
                    relayout = true;
                }
            }
        }
        saveItemPositions();
        if(relayout) {
            relayoutItems();
        }
    }
}
Ejemplo n.º 5
0
QList<int>* listview_t::get_selectedIndexes()
{//descending
    QList<int>* result = new QList<int>;
    QVector<int> temp;
    QModelIndexList list = selectedIndexes();
    QModelIndexList::const_iterator it;
    for (it = list.constBegin(); it != list.constEnd(); it++)
        temp.push_back(it->row());

    if (!temp.empty())
    {
        for (int j = 0; j < temp.size() - 1; j++)
        {
            for (int i = 0; i < temp.size() - j - 1; i++)
                if (temp[i] > temp[i+1])
                {
                    int tmp = temp[i];
                    temp[i] = temp[i+1];
                    temp[i+1] = tmp;
                }
            result->push_back(temp[temp.size() - j - 1]);
        }
        result->push_back(temp[0]);
    }
    return result;
}
Ejemplo n.º 6
0
void NMGMeasureListWidget::selectAllItems(QAbstractItemModel* model, 
                                          QItemSelectionModel* selectionModel,
                                          const QModelIndex& parent)
{
  if(model->hasChildren(parent))
  {
    if(selectionModel->isSelected(parent))
    {
      // this is done because of the removeSelectedItems() behaviour and the signals emitted,
      // to avoid extra signaling (e.g. extra parent deletion signal done by 
      // removeSelectedItems() due to no more children).
      selectionModel->select(parent, QItemSelectionModel::Deselect);
    }
    QModelIndex topLeft = model->index(0, 0, parent);
    QModelIndex bottomRight = model->index(model->rowCount(parent)-1, 
                                           model->columnCount(parent)-1, parent);
    QItemSelection selection;
    selection.select(topLeft, bottomRight);    
    selectionModel->select(selection, QItemSelectionModel::Select | QItemSelectionModel::Rows);
    
    QModelIndexList selectedIndexes = selection.indexes();
    QModelIndexList::const_iterator it;
    for(it = selectedIndexes.constBegin(); it != selectedIndexes.constEnd(); it++)
    {
      selectAllItems(model, selectionModel, *it);
    }
  }
}
Ejemplo n.º 7
0
void KCompletionModel::Private::removeRows(const QModelIndexList& list)
{
    // First convert the indexes to persistent because we'll remove them one by one
    QList<QPersistentModelIndex> indexes;
    QList<QModelIndex>::const_iterator listIt;
    for (listIt = list.constBegin(); listIt != list.constEnd(); ++listIt) {
        indexes.append(*listIt);
    }
    
    QList<QPersistentModelIndex>::ConstIterator it;
    
    for (it = indexes.constBegin(); it != indexes.constEnd(); ++it) {
        const QPersistentModelIndex &index = *it;
        int pos = index.row();
        
        q->beginRemoveRows(QModelIndex(), pos, pos);
        
        QString match = m_indexes[index];
        
        m_strings.removeAt(pos);
        m_indexes.remove(index);
        m_reverseIndexes.remove(match);
        
        q->endRemoveRows();
    }
}
QList<QgsSymbolV2*> QgsCategorizedSymbolRendererV2Widget::selectedSymbols()
{
  QList<QgsSymbolV2*> selectedSymbols;

  QItemSelectionModel* m = viewCategories->selectionModel();
  QModelIndexList selectedIndexes = m->selectedRows( 1 );

  if ( m && selectedIndexes.size() > 0 )
  {
    const QgsCategoryList& categories = mRenderer->categories();
    QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
    for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
    {
      QStandardItem* currentItem = qobject_cast<const QStandardItemModel*>( m->model() )->itemFromIndex( *indexIt );
      if ( currentItem )
      {
        QgsSymbolV2* s = categories[mRenderer->categoryIndexForValue( currentItem->data() )].symbol();
        if ( s )
        {
          selectedSymbols.append( s );
        }
      }
    }
  }
  return selectedSymbols;
}
QList<QgsSymbol *> QgsGraduatedSymbolRendererWidget::selectedSymbols()
{
  QList<QgsSymbol *> selectedSymbols;

  QItemSelectionModel *m = viewGraduated->selectionModel();
  QModelIndexList selectedIndexes = m->selectedRows( 1 );
  if ( m && !selectedIndexes.isEmpty() )
  {
    const QgsRangeList &ranges = mRenderer->ranges();
    QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
    for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
    {
      QStringList list = m->model()->data( *indexIt ).toString().split( ' ' );
      if ( list.size() < 3 )
      {
        continue;
      }
      // Not strictly necessary because the range should have been sanitized already
      // after user input, but being permissive never hurts
      bool ok = false;
      double lowerBound = qgsPermissiveToDouble( list.at( 0 ), ok );
      if ( ! ok )
        lowerBound = 0.0;
      double upperBound = qgsPermissiveToDouble( list.at( 2 ), ok );
      if ( ! ok )
        upperBound = 0.0;
      QgsSymbol *s = findSymbolForRange( lowerBound, upperBound, ranges );
      if ( s )
      {
        selectedSymbols.append( s );
      }
    }
  }
  return selectedSymbols;
}
Ejemplo n.º 10
0
QtItemSelection::QtItemSelection(const QItemSelection& sel)
: m_Selection(new ContainerType())
{
  QModelIndexList indexes = sel.indexes();
  for (QModelIndexList::const_iterator index = indexes.constBegin(); index != indexes.constEnd(); ++index)
  {
    Object::Pointer indexObj(new QModelIndexObject(*index));
    m_Selection->push_back(indexObj);
  }
}
Ejemplo n.º 11
0
// Helpers to retrieve model data
// Convenience to extract a list of selected indexes
QList<int> selectedRows(const QAbstractItemView *view)
{
    const QModelIndexList indexList = view->selectionModel()->selectedRows(0);
    if (indexList.empty())
        return QList<int>();
    QList<int> rc;
    const QModelIndexList::const_iterator cend = indexList.constEnd();
    for (QModelIndexList::const_iterator it = indexList.constBegin(); it != cend; ++it)
        rc.push_back(it->row());
    return rc;
}
Ejemplo n.º 12
0
// Convert indexes to object vectors taking into account that
// some index lists are multicolumn ranges
static inline QObjectVector indexesToObjects(const ObjectInspectorModel *model, const QModelIndexList &indexes)
{
    if (indexes.empty())
        return  QObjectVector();
    QObjectVector rc;
    rc.reserve(indexes.size());
    const QModelIndexList::const_iterator icend = indexes.constEnd();
    for (QModelIndexList::const_iterator it = indexes.constBegin(); it != icend; ++it)
        if (it->column() == 0)
            rc.push_back(model->objectAt(*it));
    return rc;
}
QgsRangeList QgsGraduatedSymbolRendererV2Widget::selectedRanges()
{
  QgsRangeList selectedRanges;
  QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
  QModelIndexList::const_iterator sIt = selectedRows.constBegin();

  for ( ; sIt != selectedRows.constEnd(); ++sIt )
  {
    selectedRanges.append( mModel->rendererRange( *sIt ) );
  }
  return selectedRanges;
}
Ejemplo n.º 14
0
FmFileInfoList* FolderView::selectedFiles() const {
  if(model_) {
    QModelIndexList selIndexes = mode == DetailedListMode ? selectedRows() : selectedIndexes();
    if(!selIndexes.isEmpty()) {
      FmFileInfoList* files = fm_file_info_list_new();
      QModelIndexList::const_iterator it;
      for(it = selIndexes.constBegin(); it != selIndexes.constEnd(); ++it) {
        FmFileInfo* file = model_->fileInfoFromIndex(*it);
        fm_file_info_list_push_tail(files, file);
      }
      return files;
    }
  }
  return nullptr;
}
Ejemplo n.º 15
0
QList<int> KRenameWindow::selectedFileItems() const
{
    QList<int> selected;

    QItemSelectionModel *selection = m_pageFiles->fileList->selectionModel();
    QModelIndexList      indices = selection->selectedIndexes();
    QModelIndexList::const_iterator it = indices.constBegin();

    while (it != indices.constEnd()) {
        selected.append((*it).row());
        ++it;
    }

    return selected;
}
void UserphraseSortFilterProxyModel::remove(QModelIndexList indexList)
{
    if (indexList.empty()) {
        qDebug() << "indexList is empty";
        return;
    }

    QModelIndexList sourceIndexList;

    for (auto i = indexList.constBegin(); i != indexList.constEnd(); ++i) {
        sourceIndexList.push_back(mapToSource(*i));
    }

    sourceModel()->remove(std::move(sourceIndexList));
}
Ejemplo n.º 17
0
/*!
    \reimp
 */
QModelIndexList QIdentityProxyModel::match(const QModelIndex& start, int role, const QVariant& value, int hits, Qt::MatchFlags flags) const
{
    Q_D(const QIdentityProxyModel);
    Q_ASSERT(start.isValid() ? start.model() == this : true);
    if (!d->model)
        return QModelIndexList();

    const QModelIndexList sourceList = d->model->match(mapToSource(start), role, value, hits, flags);
    QModelIndexList::const_iterator it = sourceList.constBegin();
    const QModelIndexList::const_iterator end = sourceList.constEnd();
    QModelIndexList proxyList;
    for ( ; it != end; ++it)
        proxyList.append(mapFromSource(*it));
    return proxyList;
}
Ejemplo n.º 18
0
void ThumbView::startDrag(Qt::DropActions)
{
	QModelIndexList indexesList = selectionModel()->selectedIndexes();
	if (indexesList.isEmpty()) {
		return;
	}

	QDrag *drag = new QDrag(this);
	QMimeData *mimeData = new QMimeData;
	QList<QUrl> urls;
	for (QModelIndexList::const_iterator it = indexesList.constBegin(),
										end = indexesList.constEnd(); it != end; ++it)
	{
		urls << QUrl(thumbViewModel->item(it->row())->data(FileNameRole).toString());
	}
	mimeData->setUrls(urls);
	drag->setMimeData(mimeData);
	QPixmap pix;
	if (indexesList.count() > 1) {
		pix = QPixmap(128, 112);
		pix.fill(Qt::transparent);
		QPainter painter(&pix);
		painter.setBrush(Qt::NoBrush);
		painter.setPen(QPen(Qt::white, 2));
		int x = 0, y = 0, xMax = 0, yMax = 0;
		for (int i = 0; i < qMin(5, indexesList.count()); ++i) {
			QPixmap pix = thumbViewModel->item(indexesList.at(i).row())->icon().pixmap(72);
			if (i == 4) {
				x = (xMax - pix.width()) / 2;
				y = (yMax - pix.height()) / 2;
			}
			painter.drawPixmap(x, y, pix);
			xMax = qMax(xMax, qMin(128, x + pix.width()));
			yMax = qMax(yMax, qMin(112, y + pix.height()));
			painter.drawRect(x + 1, y + 1, qMin(126, pix.width() - 2), qMin(110, pix.height() - 2));
			x = !(x == y) * 56;
			y = !y * 40;
		}
		painter.end();
		pix = pix.copy(0, 0, xMax, yMax);
		drag->setPixmap(pix);
	} else {
		pix = thumbViewModel->item(indexesList.at(0).row())->icon().pixmap(128);
		drag->setPixmap(pix);
	}
	drag->setHotSpot(QPoint(pix.width() / 2, pix.height() / 2));
	drag->exec(Qt::CopyAction | Qt::MoveAction | Qt::LinkAction, Qt::IgnoreAction);
}
Ejemplo n.º 19
0
Archivo: rmap.cpp Proyecto: 87maxi/oom
QList<int> RouteMapDock::getSelectedRows()/*{{{*/
{
	QList<int> rv;
	QItemSelectionModel* smodel = routeList->selectionModel();
	if (smodel->hasSelection())
	{
		QModelIndexList indexes = smodel->selectedRows();
		QList<QModelIndex>::const_iterator id;
		for (id = indexes.constBegin(); id != indexes.constEnd(); ++id)
		{
			int row = (*id).row();
			rv.append(row);
		}
	}
	return rv;
}/*}}}*/
Ejemplo n.º 20
0
QmitkDataNodeSelection::QmitkDataNodeSelection(
    const QItemSelection& sel) :
  mitk::DataNodeSelection(), berry::QtItemSelection(sel)
{
  QModelIndexList indexes = sel.indexes();
  for (QModelIndexList::const_iterator index = indexes.constBegin(); index
      != indexes.constEnd(); ++index)
  {
    QVariant data = index->data(QmitkDataNodeRole);
    mitk::DataNode::Pointer node =
        data.value<mitk::DataNode::Pointer> ();
    if (node.IsNotNull())
    {
      berry::Object::Pointer obj(new mitk::DataNodeObject(node));
      mitk::DataNodeSelection::m_Selection->push_back(obj);
    }
  }
}
Ejemplo n.º 21
0
void QgsSpatiaLiteSourceSelect::addTables()
{
  m_selectedTables.clear();

  typedef QMap < int, bool >schemaInfo;
  QMap < QString, schemaInfo > dbInfo;

  QItemSelection selection = mTablesTreeView->selectionModel()->selection();
  QModelIndexList selectedIndices = selection.indexes();
  QStandardItem *currentItem = 0;

  QModelIndexList::const_iterator selected_it = selectedIndices.constBegin();
  for ( ; selected_it != selectedIndices.constEnd(); ++selected_it )
  {
    if ( !selected_it->parent().isValid() )
    {
      //top level items only contain the schema names
      continue;
    }
    currentItem = mTableModel.itemFromIndex( mProxyModel.mapToSource( *selected_it ) );
    if ( !currentItem )
    {
      continue;
    }

    QString currentSchemaName = currentItem->parent()->text();

    int currentRow = currentItem->row();
    if ( !dbInfo[currentSchemaName].contains( currentRow ) )
    {
      dbInfo[currentSchemaName][currentRow] = true;
      m_selectedTables << layerURI( mProxyModel.mapToSource( *selected_it ) );
    }
  }

  if ( m_selectedTables.empty() )
  {
    QMessageBox::information( this, tr( "Select Table" ), tr( "You must select a table in order to add a Layer." ) );
  }
  else
  {
    accept();
  }
}
void QgsDatumTransformTableWidget::editDatumTransform()
{
  QModelIndexList selectedIndexes = mTableView->selectionModel()->selectedIndexes();
  if ( selectedIndexes.count() > 0 )
  {
    QgsCoordinateReferenceSystem sourceCrs;
    QgsCoordinateReferenceSystem destinationCrs;
    int sourceTransform = -1;
    int destinationTransform = -1;
    for ( QModelIndexList::const_iterator it = selectedIndexes.constBegin(); it != selectedIndexes.constEnd(); it ++ )
    {
      switch ( it->column() )
      {
        case QgsDatumTransformTableModel::SourceCrsColumn:
          sourceCrs = QgsCoordinateReferenceSystem( mModel->data( *it, Qt::DisplayRole ).toString() );
          break;
        case QgsDatumTransformTableModel::DestinationCrsColumn:
          destinationCrs = QgsCoordinateReferenceSystem( mModel->data( *it, Qt::DisplayRole ).toString() );
          break;
        case QgsDatumTransformTableModel::SourceTransformColumn:
          sourceTransform = mModel->data( *it, Qt::UserRole ).toInt();
          break;
        case QgsDatumTransformTableModel::DestinationTransformColumn:
          destinationTransform = mModel->data( *it, Qt::UserRole ).toInt();
          break;
        default:
          break;
      }
    }
    if ( sourceCrs.isValid() && destinationCrs.isValid() &&
         ( sourceTransform != -1 || destinationTransform != -1 ) )
    {
      QgsDatumTransformDialog dlg( sourceCrs, destinationCrs, qMakePair( sourceTransform, destinationTransform ) );
      if ( dlg.exec() )
      {
        QPair< QPair<QgsCoordinateReferenceSystem, int>, QPair<QgsCoordinateReferenceSystem, int > > dt = dlg.selectedDatumTransforms();
        QgsCoordinateTransformContext context = mModel->transformContext();
        // QMap::insert takes care of replacing existing value
        context.addSourceDestinationDatumTransform( sourceCrs, destinationCrs, dt.first.second, dt.second.second );
        mModel->setTransformContext( context );
      }
    }
  }
}
Ejemplo n.º 23
0
void ObjectInspector::ObjectInspectorPrivate::selectIndexRange(const QModelIndexList &indexes, unsigned flags)
{
    if (indexes.empty())
        return;

    QItemSelectionModel::SelectionFlags selectFlags = QItemSelectionModel::Select|QItemSelectionModel::Rows;
    if (!(flags & AddToSelection))
        selectFlags |= QItemSelectionModel::Clear;
    if (flags & MakeCurrent)
        selectFlags |= QItemSelectionModel::Current;

    QItemSelectionModel *selectionModel = m_treeView->selectionModel();
    const QModelIndexList::const_iterator cend = indexes.constEnd();
    for (QModelIndexList::const_iterator it = indexes.constBegin(); it != cend; ++it)
        if (it->column() == 0) {
            selectionModel->select(*it, selectFlags);
            selectFlags &= ~(QItemSelectionModel::Clear|QItemSelectionModel::Current);
        }
    if (flags & MakeCurrent)
        m_treeView->scrollTo(indexes.front(), QAbstractItemView::EnsureVisible);
}
void QgsDatumTransformTableModel::removeTransform( const QModelIndexList &indexes )
{
  QgsCoordinateReferenceSystem sourceCrs;
  QgsCoordinateReferenceSystem destinationCrs;
  for ( QModelIndexList::const_iterator it = indexes.constBegin(); it != indexes.constEnd(); it ++ )
  {
    if ( it->column() == SourceCrsColumn )
    {
      sourceCrs = QgsCoordinateReferenceSystem( data( *it, Qt::DisplayRole ).toString() );
    }
    if ( it->column() == DestinationCrsColumn )
    {
      destinationCrs = QgsCoordinateReferenceSystem( data( *it, Qt::DisplayRole ).toString() );
    }
    if ( sourceCrs.isValid() && destinationCrs.isValid() )
    {
      mTransformContext.removeSourceDestinationDatumTransform( sourceCrs, destinationCrs );
      reset();
      break;
    }
  }
}
Ejemplo n.º 25
0
    virtual QString value()
    {
        if ( viewModel == 0 )
            return QString();

        QStringList result;
        QModelIndexList selected = treeView->selectionModel()->selectedIndexes();

        if ( selected.size() <= 0 )
            return QString();

        QModelIndexList::const_iterator iter = selected.constBegin();
        while ( iter != selected.constEnd() )
        {
            QModelIndex index = (QModelIndex)(*iter);

            result << viewModel->data(index, Qt::UserRole).toString();

            ++iter;
        }

        return result.join(QString(","));
    }
Ejemplo n.º 26
0
void GuiPanel::setSelection(const QModelIndexList &newsel, int k){
  int sel=-1;
  int nsel = (int)newsel.size();
  if (newsel.size()!=0) sel = newsel[0].row();

  //bool vertexani=false;
  //bool skinned=false;
  //bool vertexcolor=false;
  /*bool manyMaterials=false;
  int flags=-1;
  char materialSt[255]="";
  bool differentAni = false;

  int nv=0, nf=0, nfr=0, np=0;
  int last = -1;

  for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
    sel = i->row();
    if (k==MESH && sel<(int)data->mesh.size() ) {
      BrfMesh *m = &(data->mesh[sel]);
      skinned |= m->IsSkinned();
      vertexani |= m->frame.size()>1;
      vertexcolor |= m->hasVertexColor;
      np += m->frame[0].pos.size();
      nv += m->vert.size();
      int k = m->frame.size();
      if (nfr>k || !nfr) nfr=k;

      if (!differentAni) {

        if (last!=-1) {
          if (data->mesh[sel].frame.size()!=data->mesh[last].frame.size()) differentAni=true;
          else for (unsigned int fi=0; fi < data->mesh[sel].frame.size(); fi++)
            if (data->mesh[sel].frame[fi].time!=data->mesh[last].frame[fi].time) differentAni=true;
        } else {
          for (unsigned int fi=0; fi < data->mesh[sel].frame.size(); fi++)
            _frameTime[fi]=data->mesh[sel].frame[fi].time;
        }
        last = sel;
      }

      nf += m->face.size();
      if (!materialSt[0]) sprintf(materialSt,"%s",m->material);
      else if (strcmp(materialSt,m->material)) {
        sprintf(materialSt,"%s","<various>");
        manyMaterials=true;
      }
      if (flags==-1) flags=m->flags; else {
        if (flags!=(int)m->flags) flags=-2;
      }
    }


  }
  if (k==-1) k=NONE;

  BrfMesh *m = NULL;
  BrfTexture *tex = NULL;
  BrfAnimation *ani = NULL;
*/
_selectedIndex = sel;
//_nsel =
switch (TokenEnum(k)){
  case MATERIAL:{
    myClear(ui->leMatBump);
    myClear(ui->leMatDifA);
    myClear(ui->leMatDifB);
    myClear(ui->leMatEnv);
    myClear(ui->leMatShader);
    myClear(ui->leMatSpec);

    myClear(ui->leMatFlags);
    //myClear(ui->leMatRendOrd);
    myClear(ui->leMatCoeff);
    myClear(ui->leMatR);
    myClear(ui->leMatG);
    myClear(ui->leMatB);

    for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
      int sel = i->row();
      if (sel<0 || sel>=(int)data->material.size())  break;
      BrfMaterial &m(data->material[sel]);

      mySetText(ui->leMatBump,  m.bump );
      mySetText(ui->leMatDifA,  m.diffuseA );
      mySetText(ui->leMatDifB,  m.diffuseB );
      mySetText(ui->leMatEnv,   m.enviro);
      mySetText(ui->leMatShader,m.shader );
      mySetText(ui->leMatSpec,  m.spec );

      mySetText(ui->leMatFlags, StringH(m.flags) );
      //mySetText(ui->leMatRendOrd, m.RenderOrder() );
      mySetText(ui->leMatCoeff, StringF(m.specular,3) );
      mySetText(ui->leMatR, StringF( m.r ,3));
      mySetText(ui->leMatG, StringF( m.g ,3));
      mySetText(ui->leMatB, StringF( m.b ,3));
    }
    break;
    }

  case MESH: {
    myClear(ui->boxFlags);
    myClear(ui->boxMaterial);
    myClear(ui->boxTexture);
    myClear(ui->boxNVerts);
    myClear(ui->boxNFaces);
    myClear(ui->boxNPos);
    myClear(ui->boxNVerts);
    myClear(ui->boxNFrames);
    ui->meshDataAni->setVisible(false);
    ui->rbRiggingcolor->setEnabled(false);
    ui->rbVertexcolor->setEnabled(false);
    ui->viewRefAni->setVisible( false );

    int hasAni=-1,hasCol=-1,hasTan=-1,hasRig=-1;
    bool hasBump=false, hasSpec=false, hasTran = false;

    for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
      int sel = i->row();
      if (sel<0 || sel>=(int)data->mesh.size()) continue;
      BrfMesh *m=&(data->mesh[sel]);

      mySetText(ui->boxFlags, StringH(m->flags & ~(3<<16) ));
      mySetText( ui->boxMaterial ,  m->material );

      mySetValueAdd( ui->boxNVerts , (int)m->vert.size());
      mySetValueAdd( ui->boxNFaces , (int)m->face.size());
      mySetValueAdd( ui->boxNPos   , (int)m->frame[0].pos.size());
      mySetValueMax( ui->boxNFrames, (int)m->frame.size());

      mySetCompositeVal(hasAni, m->HasVertexAni());
      mySetCompositeVal(hasCol, m->hasVertexColor);
      mySetCompositeVal(hasTan, m->StoresTangentField());
      mySetCompositeVal(hasRig, m->IsSkinned());

      bool ta,tb,tc;
      QString s = inidata.mat2tex(m->material,&ta,&tb,&tc);
      if (s.isEmpty()) s = tr("<not found>");
      hasBump |= ta;
      hasSpec |= tb;
      hasTran |= tc;

      mySetText( ui->boxTexture, s );

      for (unsigned int fi=0; fi < m->frame.size(); fi++)
         frameTime[fi]=m->frame[fi].time;
    }

    if (hasRig>0)  {
      ui->rbRiggingcolor->setEnabled( true );
      ui->viewRefAni->setVisible( true );
    }
    if (hasCol>0) ui->rbVertexcolor->setEnabled(true);
    if (hasAni>0) ui->meshDataAni->setVisible(true);
    ui->cbMeshHasAni->setCheckState(myCheckState(hasAni));
    ui->cbMeshHasCol->setCheckState(myCheckState(hasCol));
    ui->cbMeshHasTan->setCheckState(myCheckState(hasTan));
    ui->cbMeshHasRig->setCheckState(myCheckState(hasRig));

    ui->cbTransp->setEnabled( hasTran );
    ui->cbNormalmap->setEnabled( hasBump );
    ui->cbSpecularmap->setEnabled( hasSpec );


    ui->timeOfFrame->setEnabled( newsel.size()==1 );

    int nfr = (int)ui->boxNFrames->value();
    if (nfr>0)
    ui->frameNumber->setMaximum(nfr -1 );
    ui->frameNumber->setMinimum( 0 );
    ui->frameNumber->setWrapping(true);

    break;
    }

  case TEXTURE:
    myClear(ui->boxTextureFlags);

    for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
      int j=i->row();
      if (j>=0 && j<(int)data->texture.size())
        mySetText(ui->boxTextureFlags,StringH(data->texture[j].flags));
      int nf = data->texture[j].NFrames();
      if (nf==0)
        ui->labNFrames->setHidden(true);
      else {
        ui->labNFrames->setHidden(false);
        ui->labNFrames->setText(QString("x %1").arg(nf));
      }

    }
    break;
  case SKELETON: {
    {
        int hasHb=-1;
        myClear(ui->boxSkelNBones);
        for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
          int sel = i->row();
          if (sel<0 || sel>=(int)data->skeleton.size()) continue;
          BrfSkeleton *s=&(data->skeleton[sel]);
          int bi=-1;
          if (hitBoxes) bi = hitBoxes->Find(s->name,BODY);
          mySetCompositeVal(hasHb,bi>=0);
          mySetValue(ui->boxSkelNBones,(int)s->bone.size());
        }
        ui->cbSkelHasHitbox->setCheckState(myCheckState(hasHb));

    }

    ui->cbTransp->setEnabled( true );
    ui->cbNormalmap->setEnabled( true );
    ui->cbSpecularmap->setEnabled( true );

    BodyPartModel* bmp = ((BodyPartModel*)(ui->lvBones->model()));
    if (sel>=0 && nsel==1 && sel<(int)data->skeleton.size()) {
      BrfSkeleton &s(data->skeleton[sel]);
      bmp->setSkel(s);      
    } else  bmp->clear();

    emit selectedSubPiece(-1); // unselect all
    ui->lvBones->selectionModel()->clearSelection();
    ui->hitboxEdit->setVisible(false); // until a piece is not selected

    break; }
  case ANIMATION:
    {

    myClear(ui->boxAniNBones);
    myClear(ui->boxAniNFrames);
    myClear(ui->boxAniMinFrame);
    myClear(ui->boxAniMaxFrame);

    for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
      int sel = i->row();
      if (sel<0 || sel>=(int)data->animation.size()) continue;
      BrfAnimation *a=&(data->animation[sel]);

      mySetValue(ui->boxAniNBones,a->nbones);
      mySetValue(ui->boxAniNFrames,a->frame.size());
      mySetValue(ui->boxAniMinFrame,a->FirstIndex());
      mySetValue(ui->boxAniMaxFrame,a->LastIndex() );
    }


    BrfAnimation *ani =NULL;
    if (sel>=0 && nsel==1 && sel<(int)data->animation.size()) ani=&(data->animation[sel]);
    if (ani) {
      for (unsigned int fi=0; fi < ani->frame.size(); fi++)
       frameTime[fi]=ani->frame[fi].index;
      ui->frameNumberAni->setMaximum(ani->frame.size());
      ui->frameNumberAni->setMinimum(1);
      updateFrameNumber( ui->frameNumberAni->value() );
    }

    ui->cbTransp->setEnabled( true );
    ui->cbNormalmap->setEnabled( true );
    ui->cbSpecularmap->setEnabled( true );

    ui->rbRiggingcolor->setEnabled( true ); // quick: use "true": just let user edit them
    ui->rbVertexcolor->setEnabled( true );
    ui->viewRefSkel->setVisible( true );
    if (ani) setAnimation(ani);
    }
    break;
  case SHADER:
      {
      if (!newsel.size()) break;
      int sel = newsel[0].row();
      if (sel<0 || sel>=(int)data->shader.size())  break;
      BrfShader &s(data->shader[sel]);
      ui->leShaderTechnique->setText( s.technique );
      ui->leShaderFallback->setText( s.fallback );
      ui->leShaderFlags->setText( StringH(s.flags) );
      ui->leShaderRequires->setText( StringH(s.requires) );
      updateShaderTextaccSize();
      }
      break;
    case BODY:

      bool collisionBodyHasMesh;
      if (nsel==1) {
          char* bodyname = data->body[sel].name;
          int si = data->Find(bodyname,SKELETON);

          collisionBodyHasSkel= (si>=0);
          if (si>=0) skel = &(data->skeleton[si]); else skel = NULL;
          collisionBodyHasMesh = false;
          for (int i=0; i<(int)data->mesh.size(); i++) {
              if (data->mesh[i].IsNamedAsBody(bodyname)) collisionBodyHasMesh = true;
          }
      } else {
          collisionBodyHasMesh = true;
          collisionBodyHasSkel = false;
      }
      ui->cbComparisonMesh->setEnabled( collisionBodyHasMesh || collisionBodyHasSkel );
      updateBodyPartData();
      break;
    default:

      break;
  }

  ui->animationData->setVisible(k == ANIMATION);
  ui->textureData->setVisible(k == TEXTURE);
  ui->meshData->setVisible(k == MESH);
  ui->materialData->setVisible( k==MATERIAL );
  ui->skeletonData->setVisible( k==SKELETON );
  ui->shaderData->setVisible( k==SHADER );
  ui->bodyData->setVisible( k==BODY );
  ui->generalView->setVisible( k!=SHADER && k!=NONE );

  QRect rect = ui->generalView->geometry();
  if (k==MATERIAL)
    rect.setTop( ui->materialData->geometry().bottom() + 40 );
  else
    rect.setTop( ui->meshData->geometry().bottom() + 40 );
  ui->generalView->setGeometry(rect);

  displaying=k;
  updateVisibility();
  updateFrameNumber( ui->frameNumber->value() );

}