vtkIdType *
SpreadsheetTable::selectedColumnIndices(int &nvals) const
{
    vtkIdType *ids = 0;
    nvals = 0;

    QModelIndexList sel(selectedIndexes());
    nvals = model()->rowCount();
    if(nvals > 0)
    {
        int col = 0;
        ids = new vtkIdType[nvals];

        for(QModelIndexList::iterator it = sel.begin(); it != sel.end(); ++it)
        {
            col = it->column();
            break;
        }

        for(int row = 0; row < nvals; ++row)
            ids[nvals-1-row] = (vtkIdType)model()->index(row, col).internalId();
    }

    return ids;
}
Exemple #2
0
void NotesModel::matchSelToMain()
{
    QModelIndexList lSelFiles (m_pCommonData->m_pFilesG->selectionModel()->selection().indexes());

    set<int> sSel;
    for (QModelIndexList::iterator it = lSelFiles.begin(), end = lSelFiles.end(); it != end; ++it)
    {
        int nCol (it->column());
        if (nCol > 0) // skip file name
        {
            sSel.insert(nCol - 1);
        }
    }

    QItemSelectionModel* pNotesSelModel (m_pCommonData->m_pNotesG->selectionModel());
    pNotesSelModel->clearSelection();
    bool bFirstFound (false);
    for (int i = 0, nNoteCnt = cSize(m_pCommonData->getCrtNotes()); i < nNoteCnt; ++i)
    {
        const Note* pNote (m_pCommonData->getCrtNotes()[i]);
        int nPos (m_pCommonData->findPos(pNote));
        if (sSel.count(nPos) > 0)
        {
            if (!bFirstFound)
            {
                bFirstFound = true;
                m_pCommonData->m_pNotesG->setCurrentIndex(index(i, 0));
            }
            pNotesSelModel->select(index(i, 0), QItemSelectionModel::Select | QItemSelectionModel::Rows);
        }
    }
}
Exemple #3
0
void FilesModel::fixSelection() // deselects cells that are selected but are on a different row from the "current" cell and selects the file name
{
    // it works OK when getFltHandlers() is empty
    QItemSelectionModel* pSelModel (m_pCommonData->m_pFilesG->selectionModel());
    QModelIndexList lstSel (pSelModel->selection().indexes());
    QModelIndex crt (m_pCommonData->m_pFilesG->selectionModel()->currentIndex());
    int nCrtRow (crt.row());
    int nCrtCol (crt.column());

    if (0 == nCrtCol)
    {
        for (QModelIndexList::iterator it = lstSel.begin(), end = lstSel.end(); it != end; ++it)
        {
            if (0 != it->column())
            {
                pSelModel->select(*it, QItemSelectionModel::Deselect);
            }
        }
    }
    else
    {
        set<int> sSelectableColumns;
        sSelectableColumns.insert(0);
        for (int i = 0, n = cSize(m_pCommonData->getCrtNotes()); i < n; ++i) // ttt2 poor performance
        {
            const Note* pNote (m_pCommonData->getCrtNotes()[i]);
            sSelectableColumns.insert(m_pCommonData->findPos(pNote) + 1);
        }

        for (QModelIndexList::iterator it = lstSel.begin(), end = lstSel.end(); it != end; ++it)
        {
            if ((it->row() != nCrtRow && 0 != it->column()) || 0 == sSelectableColumns.count(it->column()))
            {
                pSelModel->select(*it, QItemSelectionModel::Deselect);
            }
        }

        if (nCrtRow >= 0)
        {
            pSelModel->select(index(nCrtRow, 0), QItemSelectionModel::Select);
        }
    }
}
Exemple #4
0
void CommandDataModel::removeRows(QModelIndexList indices)
{
    while (!indices.empty()) {
        const int row = indices.takeFirst().row();
        if (row >= mCommands.size())
            continue;

        beginRemoveRows(QModelIndex(), row, row);
        mCommands.removeAt(row);

        // Decrement later indices since we removed a row
        for (QModelIndexList::iterator i = indices.begin(); i != indices.end();
                                                                            ++i)
            if (i->row() > row)
                *i = i->sibling(i->row() - 1, i->column());

        endRemoveRows();
    }
}