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; }
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; }
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; }
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; }
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; }
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")); }
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; }
// 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; }
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; }
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")); }
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 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); }
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; }
void SheetTableView::removeRows() { assert(sheet != 0); QModelIndexList rows = selectionModel()->selectedRows(); std::vector<int> sortedRows; /* Make sure rows are sorted in descending order */ for (QModelIndexList::const_iterator it = rows.begin(); it != rows.end(); ++it) sortedRows.push_back(it->row()); std::sort(sortedRows.begin(), sortedRows.end(), std::greater<int>()); /* Remove rows */ Gui::Command::openCommand("Remove rows"); for (std::vector<int>::const_iterator it = sortedRows.begin(); it != sortedRows.end(); ++it) { Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.removeRows('%s', %d)", sheet->getNameInDocument(), rowName(*it).c_str(), 1); } 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); }
void SheetTableView::insertRows() { assert(sheet != 0); QModelIndexList rows = selectionModel()->selectedRows(); std::vector<int> sortedRows; /* Make sure rows are sorted in ascending order */ for (QModelIndexList::const_iterator it = rows.begin(); it != rows.end(); ++it) sortedRows.push_back(it->row()); std::sort(sortedRows.begin(), sortedRows.end()); /* Insert rows */ Gui::Command::openCommand("Insert rows"); std::vector<int>::const_reverse_iterator it = sortedRows.rbegin(); while (it != sortedRows.rend()) { int prev = *it; int count = 1; /* Collect neighbouring rows into one chunk */ ++it; while (it != sortedRows.rend()) { if (*it == prev - 1) { prev = *it; ++count; ++it; } else break; } Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.insertRows('%s', %d)", sheet->getNameInDocument(), rowName(prev).c_str(), count); } Gui::Command::commitCommand(); Gui::Command::doCommand(Gui::Command::Doc, "App.ActiveDocument.recompute()"); }
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 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(); if (row>0 && mModel->data (mModel->index (row, column))== mModel->data (mModel->index (row-1, column))) { menu.addAction (mMoveUpAction); } if (row<mModel->rowCount()-1 && mModel->data (mModel->index (row, column))== mModel->data (mModel->index (row+1, column))) { 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()); }
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()); }
bool CQModifiedDM::removeRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; //Build the list of pointers to items to be deleted //before actually deleting any item. QList < CModification * > pModifieds; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && &mpMIRIAMInfo->getModifications()[i->row()]) pModifieds.append(&mpMIRIAMInfo->getModifications()[i->row()]); } bool retVal = false, askEveryItem = true; QMessageBox::StandardButton choice = QMessageBox::NoToAll; QList <CModification *>::const_iterator j; for (j = pModifieds.begin(); j != pModifieds.end(); ++j) { CModification * pModified = *j; size_t delRow = mpMIRIAMInfo->getModifications().CCopasiVector< CModification >::getIndex(pModified); if (delRow != C_INVALID_INDEX) { if (askEveryItem) { QString dateModified = data(this->index((int) delRow, COL_DATE_MODIFIED), Qt::DisplayRole).toString(); QString msg = "Do you want to delete Date/Time Modified '"; if (!dateModified.isNull()) { msg.append(dateModified); } msg.append("'?"); choice = CQMessageBox::question(NULL, tr("Confirm Delete"), msg, QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll, QMessageBox::No); } if (choice == QMessageBox::NoToAll) { return retVal; } else if (choice == QMessageBox::Yes) { retVal = removeRow((int) delRow); } else if (choice == QMessageBox::YesToAll) { askEveryItem = false; retVal = removeRow((int) delRow); } } } return retVal; }
bool CQReferenceDM::removeRows(QModelIndexList rows, const QModelIndex&) { if (rows.isEmpty()) return false; //Build the list of pointers to items to be deleted //before actually deleting any item. QList <CReference *> pReferences; QModelIndexList::const_iterator i; for (i = rows.begin(); i != rows.end(); ++i) { if (!isDefaultRow(*i) && &mpMIRIAMInfo->getReferences()[i->row()]) pReferences.append(&mpMIRIAMInfo->getReferences()[i->row()]); } bool retVal = false, askEveryItem = true; QMessageBox::StandardButton choice = QMessageBox::NoToAll; QList <CReference *>::const_iterator j; for (j = pReferences.begin(); j != pReferences.end(); ++j) { CReference * pReference = *j; size_t delRow = mpMIRIAMInfo->getReferences().CCopasiVector< CReference >::getIndex(pReference); if (delRow != C_INVALID_INDEX) { if (askEveryItem) { QString resource = data(this->index((int) delRow, COL_RESOURCE_REFERENCE), Qt::DisplayRole).toString(); QString Id = data(this->index((int) delRow, COL_ID_REFERENCE), Qt::DisplayRole).toString(); QString msg = "Do you want to delete Reference '"; if (!resource.isNull()) { msg.append(resource); } if (!Id.isNull()) { msg.append(":"); msg.append(Id); } msg.append("'?"); choice = CQMessageBox::question(NULL, tr("Confirm Delete"), msg, QMessageBox::Yes | QMessageBox::YesToAll | QMessageBox::No | QMessageBox::NoToAll, QMessageBox::No); } if (choice == QMessageBox::NoToAll) {return retVal;} else if (choice == QMessageBox::Yes) {retVal = removeRow((int) delRow);} else if (choice == QMessageBox::YesToAll) { askEveryItem = false; retVal = removeRow((int) delRow); } } } return true; }