Ejemplo n.º 1
0
void TorrentContentTreeView::keyPressEvent(QKeyEvent *event) {
  if (event->key() != Qt::Key_Space && event->key() != Qt::Key_Select) {
    QTreeView::keyPressEvent(event);
    return;
  }

  event->accept();

  QModelIndex current = currentNameCell();

  QVariant value = current.data(Qt::CheckStateRole);
  if (!value.isValid()) {
    Q_ASSERT(false);
    return;
  }

  Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
                       ? Qt::Unchecked : Qt::Checked);

  QModelIndexList selection = selectionModel()->selectedRows(TorrentContentModelItem::COL_NAME);

  for (QModelIndexList::const_iterator i = selection.begin(); i != selection.end(); ++i) {
    QModelIndex index = *i;
    Q_ASSERT(i->column() == TorrentContentModelItem::COL_NAME);
    model()->setData(index, state, Qt::CheckStateRole);
  }
}
Ejemplo n.º 2
0
void RetroshareDirModel::getDirDetailsFromSelect (const QModelIndexList &list, std::vector <DirDetails>& dirVec)
{
    dirVec.clear();

    /* Fire off requests */
    QModelIndexList::const_iterator it;
    for(it = list.begin(); it != list.end(); it++)
    {
        if(it->column()==1)
        {
            void *ref = it -> internalPointer();

            DirDetails details;
            uint32_t flags = DIR_FLAGS_DETAILS;
            if (RemoteMode)
            {
                flags |= DIR_FLAGS_REMOTE;
            }
            else
            {
                flags |= DIR_FLAGS_LOCAL;
            }

            if (!requestDirDetails(ref, details, flags))
            {
                continue;
            }

            dirVec.push_back(details);
        }
    }
}
Ejemplo n.º 3
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;
}
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;
    }
  }
}
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.º 6
0
void SheetTableView::removeColumns()
{
    assert(sheet != 0);

    QModelIndexList cols = selectionModel()->selectedColumns();
    std::vector<int> sortedColumns;

    /* Make sure rows are sorted in descending order */
    for (QModelIndexList::const_iterator it = cols.begin(); it != cols.end(); ++it)
        sortedColumns.push_back(it->column());
    std::sort(sortedColumns.begin(), sortedColumns.end(), std::greater<int>());

    /* Remove columns */
    Gui::Command::openCommand("Remove rows");
    for (std::vector<int>::const_iterator it = sortedColumns.begin(); it != sortedColumns.end(); ++it)
        Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.removeColumns('%s', %d)", sheet->getNameInDocument(),
                                columnName(*it).c_str(), 1);
    Gui::Command::commitCommand();
    Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}
Ejemplo n.º 7
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);
}
Ejemplo n.º 8
0
void RetroshareDirModel::getDirDetailsFromSelect (const QModelIndexList &list, std::vector <DirDetails>& dirVec)
{
    dirVec.clear();

    /* Fire off requests */
    QModelIndexList::const_iterator it;
    for(it = list.begin(); it != list.end(); it++)
    {
        if(it->column()==1)
        {
            void *ref = it -> internalPointer();

            const DirDetails *details = requestDirDetails(ref, RemoteMode);

            if (!details)
                continue;

            dirVec.push_back(*details);
        }
    }
}
Ejemplo n.º 9
0
void RetroshareDirModel::getDirDetailsFromSelect (const QModelIndexList &list, std::vector <DirDetails>& dirVec)
{
    dirVec.clear();

    /* Fire off requests */
    QModelIndexList::const_iterator it;
    for(it = list.begin(); it != list.end(); it++)
    {
        if(it->column()==1)
        {
            void *ref = it -> internalPointer();

            DirDetails details;
            FileSearchFlags flags = (RemoteMode)?RS_FILE_HINTS_REMOTE:RS_FILE_HINTS_LOCAL;

            if (!requestDirDetails(ref, details, flags))
                continue;

            dirVec.push_back(details);
        }
    }
}
Ejemplo n.º 10
0
void SheetTableView::insertColumns()
{
    assert(sheet != 0);

    QModelIndexList cols = selectionModel()->selectedColumns();
    std::vector<int> sortedColumns;

    /* Make sure rows are sorted in ascending order */
    for (QModelIndexList::const_iterator it = cols.begin(); it != cols.end(); ++it)
        sortedColumns.push_back(it->column());
    std::sort(sortedColumns.begin(), sortedColumns.end());

    /* Insert columns */
    Gui::Command::openCommand("Insert columns");
    std::vector<int>::const_reverse_iterator it = sortedColumns.rbegin();
    while (it != sortedColumns.rend()) {
        int prev = *it;
        int count = 1;

        /* Collect neighbouring columns into one chunk */
        ++it;
        while (it != sortedColumns.rend()) {
            if (*it == prev - 1) {
                prev = *it;
                ++count;
                ++it;
            }
            else
                break;
        }

        Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.insertColumns('%s', %d)", sheet->getNameInDocument(),
                                columnName(prev).c_str(), count);
    }
    Gui::Command::commitCommand();
    Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()");
}