RemoveGlobalQuantityRowsCommand::RemoveGlobalQuantityRowsCommand( QModelIndexList rows, CQGlobalQuantityDM * pGlobalQuantityDM, const QModelIndex&) : CCopasiUndoCommand("Global Quantity", GLOBALQUANTITY_REMOVE) , mpGlobalQuantityDM(pGlobalQuantityDM) , mRows(rows) , mpGlobalQuantityData() , mFirstTime(true) { CCopasiDataModel * pDataModel = pGlobalQuantityDM->getDataModel(); assert(pDataModel != NULL); CModel * pModel = pDataModel->getModel(); assert(pModel != NULL); QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { CModelValue* pModelValue = &pModel->getModelValues()[i->row()]; if (pGlobalQuantityDM->isDefaultRow(*i) || pModelValue == NULL) continue; UndoGlobalQuantityData *data = new UndoGlobalQuantityData(pModelValue); mpGlobalQuantityData.append(data); } setText(QObject::tr(": Removed Global Quantity")); }
std::vector<std::string> CSVWorld::Table::listRevertableSelectedIds() const { /// \todo Do not use hardcoded column numbers std::vector<std::string> revertableIds; if (mProxyModel->columnCount()>0) { QModelIndexList selectedRows = selectionModel()->selectedRows(); for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter) { QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0)); CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State> ( mModel->data (mModel->index (index.row(), 1)).toInt()); if (state!=CSMWorld::RecordBase::State_BaseOnly) { std::string id = mModel->data (mModel->index (index.row(), 0)). toString().toUtf8().constData(); revertableIds.push_back (id); } } } return revertableIds; }
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); } } }
std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const { std::vector<std::string> deletableIds; if (mProxyModel->columnCount()>0) { QModelIndexList selectedRows = selectionModel()->selectedRows(); for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter) { QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0)); CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State> ( mModel->data (mModel->index (index.row(), 1)).toInt()); if (state!=CSMWorld::RecordBase::State_Deleted) { int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id); std::string id = mModel->data (mModel->index (index.row(), columnIndex)). toString().toUtf8().constData(); deletableIds.push_back (id); } } } return deletableIds; }
template<class T> std::vector<T> getSelectedIds( const QTableView* view, const QSqlQueryModel* model, const QString& colName) { QModelIndexList selected = view->selectionModel()->selectedIndexes(); std::vector<T> selectedIds; std::set<int> rows; for( QModelIndexList::const_iterator it = selected.begin(); it != selected.end(); ++it ) { rows.insert(it->row()); } for( std::set<int>::const_iterator it = rows.begin(); it != rows.end(); ++it ) { QSqlRecord selectedRecord = model->record(*it); selectedIds.push_back( selectedRecord.value(colName).value<library_song_id_t>()); } return selectedIds; }
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; }
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); } }
// 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; }
// 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; }
QMimeData* CategoryModel::mimeData(const QModelIndexList& indexes) const { QMimeData *mimeData = new QMimeData; QByteArray encodedData; QDataStream stream(&encodedData, QIODevice::WriteOnly); for (QModelIndexList::const_iterator it = indexes.begin(); it != indexes.end(); ++it) { quint64 address = reinterpret_cast<quint64>(it->internalPointer()); stream << address; } mimeData->setData("application/editor.categorymodel.index", encodedData); return mimeData; }
bool CQUnitDM::removeRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CCopasiDataModel* pDataModel = &CCopasiRootContainer::getDatamodelList()->operator[](0); assert(pDataModel != NULL); CModel * pModel = pDataModel->getModel(); if (pModel == NULL) return false; // Build the list of pointers to items to be deleted // before actually deleting any item. QList <CUnitDefinition *> pUnitDefQList; QModelIndexList::const_iterator i; CUnitDefinition * pUnitDef; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && (pUnitDef = &CCopasiRootContainer::getUnitList()->operator[](i->row())) != NULL && pModel->getUnitSymbolUsage(pUnitDef->getSymbol()).empty() && !pUnitDef->isReadOnly())//Don't delete built-ins or used units pUnitDefQList.append(&CCopasiRootContainer::getUnitList()->operator[](i->row())); } for (QList <CUnitDefinition *>::const_iterator j = pUnitDefQList.begin(); j != pUnitDefQList.end(); ++j) { size_t delRow = CCopasiRootContainer::getUnitList()->CCopasiVector< CUnitDefinition >::getIndex(*j); if (delRow != C_INVALID_INDEX) { CCopasiObject::DataObjectSet DeletedObjects; DeletedObjects.insert(*j); QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "unit", FROM_UTF8((*j)->getObjectName()), DeletedObjects); if (choice == QMessageBox::Ok) removeRow((int) delRow); } } return true; }
bool CQReportDM::removeRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; assert(mpDataModel != NULL); CCopasiVector< CReportDefinition > * pReportList = mpDataModel->getReportDefinitionList(); if (pReportList == NULL) return false; QList< CReportDefinition * > Reports; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && &pReportList->operator[](i->row())) Reports.append(&pReportList->operator[](i->row())); } QList< CReportDefinition * >::const_iterator j; for (j = Reports.begin(); j != Reports.end(); ++j) { CReportDefinition * pReport = *j; size_t delRow = pReportList->getIndex(pReport); if (delRow != C_INVALID_INDEX) { std::set< const CCopasiObject * > DeletedObjects; DeletedObjects.insert(pReport); QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "report", FROM_UTF8(pReport->getObjectName()), DeletedObjects); if (choice == QMessageBox::Ok) { removeRow((int) delRow); } } } return true; }
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); }
bool CQFunctionDM::removeRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; assert(mpDataModel != NULL); CModel * pModel = mpDataModel->getModel(); if (pModel == NULL) return false; //Build the list of pointers to items to be deleted //before actually deleting any item. QList <CEvaluationTree *> pFunctions; CFunction * pFunction; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && (pFunction = &CRootContainer::getFunctionList()->loadedFunctions()[i->row()]) != NULL && !pFunction->isReadOnly()) pFunctions.append(&CRootContainer::getFunctionList()->loadedFunctions()[i->row()]); } QList <CEvaluationTree *>::const_iterator j; for (j = pFunctions.begin(); j != pFunctions.end(); ++j) { CEvaluationTree * pFunction = *j; size_t delRow = CRootContainer::getFunctionList()->loadedFunctions().CDataVector< CFunction >::getIndex(pFunction); if (delRow != C_INVALID_INDEX) { QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "function", FROM_UTF8(pFunction->getObjectName()), pFunction); if (choice == QMessageBox::Ok) removeRow((int) delRow); } } return true; }
std::vector<std::string> CSVWorld::Table::listDeletableSelectedIds() const { std::vector<std::string> deletableIds; if (mProxyModel->columnCount()>0) { QModelIndexList selectedRows = selectionModel()->selectedRows(); for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter) { QModelIndex index = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0)); // check record state CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State> ( mModel->data (mModel->index (index.row(), 1)).toInt()); if (state==CSMWorld::RecordBase::State_Deleted) continue; // check other columns (only relevant for a subset of the tables) int dialogueTypeIndex = mModel->searchColumnIndex (CSMWorld::Columns::ColumnId_DialogueType); if (dialogueTypeIndex!=-1) { int type = mModel->data (mModel->index (index.row(), dialogueTypeIndex)).toInt(); if (type!=ESM::Dialogue::Topic && type!=ESM::Dialogue::Journal) continue; } // add the id to the collection int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id); std::string id = mModel->data (mModel->index (index.row(), columnIndex)). toString().toUtf8().constData(); deletableIds.push_back (id); } } return deletableIds; }
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); } } }
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 ); } } } }
bool CQSpecieDM::removeSpecieRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; GET_MODEL_OR(pModel, return false); switchToWidget(CCopasiUndoCommand::SPECIES); //Build the list of pointers to items to be deleted //before actually deleting any item. QList <CMetab *> pSpecies; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && &pModel->getMetabolites()[i->row()]) pSpecies.append(&pModel->getMetabolites()[i->row()]); } QList <CMetab *>::const_iterator j; for (j = pSpecies.begin(); j != pSpecies.end(); ++j) { CMetab * pSpecie = *j; size_t delRow = pModel->getMetabolites().CCopasiVector< CMetab >::getIndex(pSpecie); if (delRow == C_INVALID_INDEX) continue; QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "species", FROM_UTF8(pSpecie->getObjectName()), pSpecie->getDeletedObjects()); if (choice == QMessageBox::Ok) removeRow((int) delRow); } return true; }
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()"); }
QMimeData *NGM::Model::ResourceItemModel::mimeData( const QModelIndexList &indexes) const { qDebug() << "Mr. Mime"; QMimeData *mimeData = new QMimeData(); std::stringstream ss; QByteArray array; for (QModelIndexList::const_iterator i = indexes.begin(); i != indexes.end(); ++i) { ss << i->internalPointer() << std::endl; qDebug() << i->internalPointer(); } std::string str = ss.str(); array.append(str.c_str(), str.size()); mimeData->setData(QStringLiteral("Natural-GM/Model-Drag"), array); internalMime = mimeData; return mimeData; }
bool CQGlobalQuantityDM::removeGlobalQuantityRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; switchToWidget(CCopasiUndoCommand::GLOBALQUANTITYIES); //Build the list of pointers to items to be deleted //before actually deleting any item. QList <CModelValue *> pGlobalQuantities; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && &mpGlobalQuantities->operator [](i->row())) pGlobalQuantities.append(&mpGlobalQuantities->operator [](i->row())); } QList <CModelValue *>::const_iterator j; for (j = pGlobalQuantities.begin(); j != pGlobalQuantities.end(); ++j) { CModelValue * pGQ = *j; size_t delRow = mpGlobalQuantities->CCopasiVector< CModelValue >::getIndex(pGQ); if (delRow == C_INVALID_INDEX) continue; QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "quantity", FROM_UTF8(pGQ->getObjectName()), pGQ->getDeletedObjects()); if (choice == QMessageBox::Ok) removeRow((int) delRow); } return true; }
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); } } }
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 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); } } }
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; } } }
RemoveSpecieRowsCommand::RemoveSpecieRowsCommand( QModelIndexList rows, CQSpecieDM * pSpecieDM, const QModelIndex&) : CCopasiUndoCommand("Species", SPECIES_REMOVE) , mpSpecieDM(pSpecieDM) , mRows(rows) , mpSpeciesData() , mFirstTime(true) { GET_MODEL_OR_RETURN(pModel); QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (pSpecieDM->isDefaultRow(*i) || &pModel->getMetabolites()[i->row()] == NULL) continue; UndoSpeciesData *data = new UndoSpeciesData(&pModel->getMetabolites()[i->row()]); mpSpeciesData.append(data); } setText(QObject::tr(": Removed Species")); }
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()"); }
void CQLayoutsWidget::deleteSelectedLayouts() { const QItemSelectionModel * pSelectionModel = mpTblLayouts->selectionModel(); QModelIndexList mappedSelRows; size_t i, imax = mpLayoutsDM->rowCount(); for (i = 0; i < imax; i++) { if (pSelectionModel->isRowSelected((int) i, QModelIndex())) { mappedSelRows.append(mpProxyModel->mapToSource(mpProxyModel->index((int) i, 0))); } } if (mappedSelRows.empty()) return; // We need to make sure that we remove the window mapped for each layout QModelIndexList::const_iterator it = mappedSelRows.begin(); QModelIndexList::const_iterator end = mappedSelRows.end(); assert(CCopasiRootContainer::getDatamodelList()->size() > 0); CListOfLayouts * pListOfLayouts = (*CCopasiRootContainer::getDatamodelList())[0]->getListOfLayouts(); for (; it != end; ++it) { LayoutWindowMap::iterator itWindow = mLayoutWindowMap.find((*pListOfLayouts)[it->row()]->getKey()); if (itWindow != mLayoutWindowMap.end()) { mLayoutWindowMap.erase(itWindow); delete itWindow->second; } } mpLayoutsDM->removeRows(mappedSelRows); }
bool CQCompartmentDM::removeRows(QModelIndexList rows, const QModelIndex& index) { if (rows.isEmpty()) return false; // Build the list of pointers to items to be deleted // before actually deleting any item. QList <CCompartment *> Compartments; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) if (!isDefaultRow(*i) && &mpCompartments->operator[](i->row()) != NULL) { Compartments.append(&mpCompartments->operator[](i->row())); } QList< CCompartment * >::const_iterator j; for (j = Compartments.begin(); j != Compartments.end(); ++j) { CCompartment * pCompartment = *j; QMessageBox::StandardButton choice = CQMessageBox::confirmDelete(NULL, "compartment", FROM_UTF8(pCompartment->getObjectName()), pCompartment); if (choice == QMessageBox::Ok) { removeRows(mpCompartments->getIndex(pCompartment->getObjectName()), 1); } } return true; }
void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) { // configure dispatcher QModelIndexList selectedRows = selectionModel()->selectedRows(); std::vector<std::string> records; int columnIndex = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id); for (QModelIndexList::const_iterator iter (selectedRows.begin()); iter!=selectedRows.end(); ++iter) { int row = mProxyModel->mapToSource (mProxyModel->index (iter->row(), 0)).row(); records.push_back (mModel->data ( mModel->index (row, columnIndex)).toString().toUtf8().constData()); } mDispatcher->setSelection (records); std::vector<CSMWorld::UniversalId> extendedTypes = mDispatcher->getExtendedTypes(); mDispatcher->setExtendedTypes (extendedTypes); // create context menu QMenu menu (this); /// \todo add menu items for select all and clear selection { // Request UniversalId editing from table columns. int currRow = rowAt( event->y() ), currCol = columnAt( event->x() ); currRow = mProxyModel->mapToSource(mProxyModel->index( currRow, 0 )).row(); CSMWorld::ColumnBase::Display colDisplay = static_cast<CSMWorld::ColumnBase::Display>( mModel->headerData( currCol, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display ).toInt()); QString cellData = mModel->data(mModel->index( currRow, currCol )).toString(); CSMWorld::UniversalId::Type colType = CSMWorld::TableMimeData::convertEnums( colDisplay ); if ( !cellData.isEmpty() && colType != CSMWorld::UniversalId::Type_None ) { mEditCellAction->setText(tr("Edit '").append(cellData).append("'")); menu.addAction( mEditCellAction ); mEditCellId = CSMWorld::UniversalId( colType, cellData.toUtf8().constData() ); } } if (!mEditLock && !(mModel->getFeatures() & CSMWorld::IdTableBase::Feature_Constant)) { if (selectedRows.size()==1) { menu.addAction (mEditAction); if (mCreateAction) menu.addAction(mCloneAction); } if (mCreateAction) menu.addAction (mCreateAction); if (mDispatcher->canRevert()) { menu.addAction (mRevertAction); if (!extendedTypes.empty()) menu.addAction (mExtendedRevertAction); } if (mDispatcher->canDelete()) { menu.addAction (mDeleteAction); if (!extendedTypes.empty()) menu.addAction (mExtendedDeleteAction); } if (mModel->getFeatures() & CSMWorld::IdTableBase::Feature_ReorderWithinTopic) { /// \todo allow reordering of multiple rows if (selectedRows.size()==1) { int column = mModel->searchColumnIndex (CSMWorld::Columns::ColumnId_Topic); if (column==-1) column = mModel->searchColumnIndex (CSMWorld::Columns::ColumnId_Journal); if (column!=-1) { int row = mProxyModel->mapToSource ( mProxyModel->index (selectedRows.begin()->row(), 0)).row(); QString curData = mModel->data(mModel->index(row, column)).toString(); if (row > 0) { QString prevData = mModel->data(mModel->index(row - 1, column)).toString(); if (Misc::StringUtils::ciEqual(curData.toStdString(), prevData.toStdString())) { menu.addAction(mMoveUpAction); } } if (row < mModel->rowCount() - 1) { QString nextData = mModel->data(mModel->index(row + 1, column)).toString(); if (Misc::StringUtils::ciEqual(curData.toStdString(), nextData.toStdString())) { menu.addAction(mMoveDownAction); } } } } } } if (selectedRows.size()==1) { int row = selectedRows.begin()->row(); row = mProxyModel->mapToSource (mProxyModel->index (row, 0)).row(); if (mModel->getFeatures() & CSMWorld::IdTableBase::Feature_View) { CSMWorld::UniversalId id = mModel->view (row).first; int index = mDocument.getData().getCells().searchId (id.getId()); // index==-1: the ID references a worldspace instead of a cell (ignore for now and go // ahead) if (index==-1 || !mDocument.getData().getCells().getRecord (index).isDeleted()) menu.addAction (mViewAction); } if (mModel->getFeatures() & CSMWorld::IdTableBase::Feature_Preview) { QModelIndex index = mModel->index (row, mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Modification)); CSMWorld::RecordBase::State state = static_cast<CSMWorld::RecordBase::State> ( mModel->data (index).toInt()); if (state!=CSMWorld::RecordBase::State_Deleted) menu.addAction (mPreviewAction); } } menu.exec (event->globalPos()); }