예제 #1
0
void QgsAttributeTableDialog::updateSelection()
{
  QModelIndex index;
  QItemSelection selection;

  QgsFeatureIds::Iterator it = mSelectedFeatures.begin();
  for ( ; it != mSelectedFeatures.end(); ++it )
  {
    QModelIndex leftUpIndex = mFilterModel->mapFromSource( mModel->index( mModel->idToRow( *it ), 0 ) );
    QModelIndex rightBottomIndex = mFilterModel->mapFromSource( mModel->index( mModel->idToRow( *it ), mModel->columnCount() - 1 ) );
    selection.append( QItemSelectionRange( leftUpIndex, rightBottomIndex ) );
    //selection.append(QItemSelectionRange(leftUpIndex, leftUpIndex));
  }

  mSelectionModel->select( selection, QItemSelectionModel::ClearAndSelect );// | QItemSelectionModel::Columns);
  mView->setSelectionModel( mSelectionModel );
  updateTitle();

#if 0
  for ( int i = 0; i < mModel->rowCount(); ++i )
  {
    int id = mModel->rowToId( i );
    QgsDebugMsg( id );
  }
  QgsDebugMsg( "--------------" );
#endif
}
예제 #2
0
void MusicListView::startDrag(Qt::DropActions supportedActions)
{
    Q_D(MusicListView);

    MetaPtrList list;
    for (auto index : selectionModel()->selectedIndexes()) {
        list << d->model->meta(index);
    }

    setAutoScroll(false);
    ListView::startDrag(supportedActions);
    setAutoScroll(true);

    QMap<QString, int> hashIndexs;
    for (int i = 0; i < d->model->rowCount(); ++i) {
        auto index = d->model->index(i, 0);
        auto hash = d->model->data(index).toString();
        Q_ASSERT(!hash.isEmpty());
        hashIndexs.insert(hash, i);
    }
    d->model->playlist()->saveSort(hashIndexs);
    Q_EMIT customSort();

    QItemSelection selection;
    for (auto meta : list) {
        if (!meta.isNull()) {
            auto index = this->findIndex(meta);
            selection.append(QItemSelectionRange(index));
        }
    }
    if (!selection.isEmpty()) {
        selectionModel()->select(selection, QItemSelectionModel::Select);
    }
}
예제 #3
0
void QgsFeatureListView::selectAll()
{
  QItemSelection selection;
  selection.append( QItemSelectionRange( mModel->index( 0, 0 ), mModel->index( mModel->rowCount() - 1, 0 ) ) );

  mFeatureSelectionModel->selectFeatures( selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
}
void AbstractDiagram::setSelection(const QRect& rect , QItemSelectionModel::SelectionFlags command )
{
    const QModelIndexList indexes = d->indexesIn( rect );
    QItemSelection selection;
    KDAB_FOREACH( const QModelIndex& index, indexes )
    {
        selection.append( QItemSelectionRange( index ) );
    }
void QgsFeatureListView::setEditSelection( const QgsFeatureIds &fids )
{
  QItemSelection selection;

  foreach ( QgsFeatureId fid, fids )
  {
    selection.append( QItemSelectionRange( mModel->mapToMaster( mModel->fidToIdx( fid ) ) ) );
  }
void QgsFeatureListView::selectAll()
{
  disconnect( selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), this, SLOT( onSelectionChanged( QItemSelection, QItemSelection ) ) );
  QItemSelection selection;
  selection.append( QItemSelectionRange( mModel->index( 0, 0 ), mModel->index( mModel->rowCount() - 1, 0 ) ) );
  selectionModel()->select( selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
  connect( selectionModel(), SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), this, SLOT( onSelectionChanged( QItemSelection, QItemSelection ) ) );
}
void QgsAttributeTableFilterModel::selectionChanged()
{
  disconnect( mMasterSelection, SIGNAL( selectionChanged( QItemSelection, QItemSelection ) ), this, SLOT( masterSelectionChanged( QItemSelection, QItemSelection ) ) );
  mMasterSelection->clear();

  QItemSelection selection;

  foreach ( QgsFeatureId fid, layer()->selectedFeaturesIds() )
  {
    selection.append( QItemSelectionRange( mTableModel->idToIndex( fid ) ) );
  }
예제 #8
0
파일: ViewerModel.C 프로젝트: jwakely/IQmol
void ViewerModel::selectAll()
{
   QItemSelection select;
   GLObjectList::iterator iter;
   for (iter = m_visibleObjects.begin(); iter != m_visibleObjects.end(); ++iter) {
       if ( ! (*iter)->isSelected()) {
          select.append(QItemSelectionRange((*iter)->index()));
       }
   }

   selectionChanged(select, QItemSelectionModel::Select);
}
예제 #9
0
파일: view.cpp 프로젝트: 0xmono/openmw
void CSVSettings::View::setSelectedValues (const QStringList &list,
                                           bool doViewUpdate, bool signalUpdate) const
{
    QItemSelection selection;

    if (stringListsMatch (list, selectedValues()))
        return;

    if (!mHasFixedValues)
    {
        QStandardItemModel *model  =
                                static_cast <QStandardItemModel *>(mDataModel);

        model->clear();
        model->appendColumn (toStandardItemList (list));

        for (int i = 0; i < model->rowCount(); i++)
        {
            QModelIndex idx = model->index(i, 0);
            selection.append (QItemSelectionRange (idx, idx));
        }
    }
    else
    {
        for (int i = 0; i < mDataModel->rowCount(); i++)
        {
            if (list.contains(value(i)))
            {
                QModelIndex idx = mDataModel->index(i, 0);
                selection.append(QItemSelectionRange (idx, idx));
            }
        }
    }
    select (selection);

    //update the view if the selection was set from the model side, not by the
    //user
    if (doViewUpdate)
         updateView (signalUpdate);
}
예제 #10
0
파일: ViewerModel.C 프로젝트: jwakely/IQmol
void ViewerModel::selectNone()
{
   enableUpdate(false);
   updateVisibleObjects();
   enableUpdate(true);

   QItemSelection all;
   GLObjectList::iterator iter;
   for (iter = m_visibleObjects.begin(); iter != m_visibleObjects.end(); ++iter) {
       all.append(QItemSelectionRange((*iter)->index()));
   }
   selectionChanged(all, QItemSelectionModel::Deselect);
}
예제 #11
0
const QItemSelection AMActionHistoryModel3::indicesBetween(const QModelIndex &brother, const QModelIndex &sister) const{
	QItemSelection selected;
	// Doesn't make sense if they don't share the same parent
	if(brother.parent() != sister.parent())
		return selected;
	QItemSelectionRange selectedRange;
	// Organize in the correct order
	if(brother.row() >= sister.row())
		selectedRange = QItemSelectionRange(sister, brother);
	else
		selectedRange = QItemSelectionRange(brother, sister);
	selected.append(selectedRange);
	return selected;
}
예제 #12
0
void QgsFeatureListView::setEditSelection( const QgsFeatureIds &fids )
{
  QItemSelection selection;

  const auto constFids = fids;
  for ( QgsFeatureId fid : constFids )
  {
    selection.append( QItemSelectionRange( mModel->mapToMaster( mModel->fidToIdx( fid ) ) ) );
  }

  bool ok = true;
  emit aboutToChangeEditSelection( ok );

  if ( ok )
    mCurrentEditSelectionModel->select( selection, QItemSelectionModel::ClearAndSelect );
}
예제 #13
0
/*!
    \reimp
 */
QItemSelection QIdentityProxyModel::mapSelectionToSource(const QItemSelection& selection) const
{
    Q_D(const QIdentityProxyModel);
    QItemSelection sourceSelection;

    if (!d->model)
        return sourceSelection;

    QItemSelection::const_iterator it = selection.constBegin();
    const QItemSelection::const_iterator end = selection.constEnd();
    for ( ; it != end; ++it) {
        Q_ASSERT(it->model() == this);
        const QItemSelectionRange range(mapToSource(it->topLeft()), mapToSource(it->bottomRight()));
        sourceSelection.append(range);
    }

    return sourceSelection;
}
예제 #14
0
void PlaylistView::keyPressEvent(QKeyEvent *event)
{
    PlaylistModel *playlistModel = dynamic_cast<PlaylistModel *>(this->model());
    if (playlistModel == nullptr)
    {
        return;
    }
    
    QModelIndex bot = playlistModel->index(playlistModel->rowCount(QModelIndex()) - 1, 0);
    QModelIndex top = playlistModel->index(0, 0);

    int key = event->key();
    switch (key)
    {
        case Qt::Key_Delete:
        {
            QItemSelection indexList = this->selectionModel()->selection();

            int lastCount = 0;
            for (QItemSelection::const_iterator i = indexList.cbegin(); i != indexList.cend(); ++i)
            {
                int btm = i->bottom();
                int top = i->top();

                if (btm < 0 || top < 0)
                {
                    break;
                }

                lastCount = abs(top - btm) + 1;
                playlistModel->removeRows(min(btm, top), lastCount);
            }
        }
        break;

        case Qt::Key_W:
            this->moveItems(-1);
            break;

        case Qt::Key_S:
            this->moveItems(1);
            break;

        case Qt::Key_Home:
        case Qt::Key_End:
            if ((event->modifiers() & Qt::ShiftModifier) == Qt::ShiftModifier)
            {
                QModelIndex cur = this->currentIndex();
                
                QItemSelectionRange aboveCur(top, cur);
                
                QItemSelection selection;
                selection.append(aboveCur);
                this->selectionModel()->select(selection,
                                               ((key == Qt::Key_Home) ? QItemSelectionModel::Select : QItemSelectionModel::Deselect) | QItemSelectionModel::Rows);
                selection.clear();
                
                QItemSelectionRange belowCur(cur, bot);
                selection.append(belowCur);
                this->selectionModel()->select(selection,
                                               ((key == Qt::Key_Home) ? QItemSelectionModel::Deselect : QItemSelectionModel::Select) | QItemSelectionModel::Rows);
                
                // make sure the current index is selected
                this->selectionModel()->select(this->currentIndex(),
                                               QItemSelectionModel::Select | QItemSelectionModel::Rows);
                
                break;
            }
            else if ((event->modifiers() & Qt::NoModifier) == Qt::NoModifier)
            {
                this->setCurrentIndex((key == Qt::Key_Home) ? top : bot);
                break;
            }
            else
            {
                [[fallthrough]];
            }

        default:
            QTableView::keyPressEvent(event);
            break;
    }
}
void QgsAttributeTableView::selectAll()
{
  QItemSelection selection;
  selection.append( QItemSelectionRange( mFilterModel->index( 0, 0 ), mFilterModel->index( mFilterModel->rowCount() - 1, 0 ) ) );
  selectionModel()->select( selection, QItemSelectionModel::ClearAndSelect | QItemSelectionModel::Rows );
}