void CameraConfigModel::swapChannels(const int &i, const int &j) { if(i < 0 || j < 0 || i >= rowCount() || j >= rowCount()) return; int a = qMin(i, j); int b = qMax(i, j); QList<QStandardItem *> bItems = takeRow(b); QList<QStandardItem *> aItems = takeRow(a); insertRow(a, bItems); insertRow(b, aItems); ChannelItem *newA = ChannelItem::cast(bItems[0]); ChannelItem *newB = ChannelItem::cast(aItems[0]); newA->setI(a); newB->setI(b); updateConfig(); }
QStandardItem* mail_item_model::reparent_msg(mail_msg* msg, mail_id_t parent_id) { DBG_PRINTF(7, "reparent_msg"); QMap<mail_id_t, QStandardItem*>::iterator itp = items_map.find(parent_id); if (itp==items_map.end()) return NULL; QMap<mail_id_t, QStandardItem*>::iterator itc = items_map.find(msg->get_id()); if (itc!=items_map.end()) { QModelIndex index_child=this->indexFromItem(itc.value()); QStandardItem* old_parent=itc.value()->parent(); QStandardItem* new_parent=itp.value(); if (old_parent==new_parent) return NULL; QList<QStandardItem*> ql; if (!old_parent) { ql=takeRow(index_child.row()); } else { DBG_PRINTF(9,"old_parent for mail_id=%d", msg->get_id()); ql=old_parent->takeRow(index_child.row()); } new_parent->appendRow(ql); DBG_PRINTF(9, "reparented %d as child of %d", msg->get_id(), parent_id); return new_parent; } else { DBG_PRINTF(1, "ERR: mail_id=%d not found in items_map", msg->get_id()); } return NULL; }
void AttachmentModel::moveAttachmentsUpOrDown(QList<Attachment *> attachments, bool up) { auto attachmentRowMap = QHash<Attachment *, int>{}; for (auto const &attachment : attachments) attachmentRowMap[attachment] = rowForAttachment(*attachment); std::sort(attachments.begin(), attachments.end(), [&attachmentRowMap](Attachment *a, Attachment *b) { return attachmentRowMap[a] < attachmentRowMap[b]; }); if (!up) std::reverse(attachments.begin(), attachments.end()); auto couldNotBeMoved = QHash<Attachment *, bool>{}; auto isSelected = QHash<Attachment *, bool>{}; auto const direction = up ? -1 : +1; auto const numRows = rowCount(); for (auto const &attachment : attachments) { isSelected[attachment] = true; auto currentRow = rowForAttachment(*attachment); Q_ASSERT(0 <= currentRow); auto targetRow = currentRow + direction; if ( (0 > targetRow) || (numRows <= targetRow) || couldNotBeMoved[attachmentForRow(targetRow).get()]) couldNotBeMoved[attachment] = true; else insertRow(targetRow, takeRow(currentRow)); } }
bool QgsLegendModel::removeRows( int row, int count, const QModelIndex & parent ) { if ( count < 1 ) { return false; } if ( parent.isValid() ) { for ( int i = row + count - 1; i >= row; --i ) { QStandardItem* item = itemFromIndex( parent ); if ( item ) { item->takeRow( i ); } } } else { for ( int i = row + count - 1; i >= row; --i ) { takeRow( i ); } } return true; }
void FavoriteEditor::on_down_button_clicked() { int row = table->currentRow(); qDebug("FavoriteEditor::on_down_button_clicked: current_row: %d", row); if ((row+1) >= table->rowCount()) return; // take whole rows QList<QTableWidgetItem*> source_items = takeRow(row); QList<QTableWidgetItem*> dest_items = takeRow(row+1); // set back in reverse order setRow(row, dest_items); setRow(row+1, source_items); table->setCurrentCell(row+1, table->currentColumn()); }
bool TransferItem::removeRow(int i) { if (TransferItem *item = takeRow(i)) { item->deleteLater(); return true; } return false; }
// ------------------------------------------------------------------ bool JcnModel::rmvEntry(const QByteArray & s, int itemRow) { if (jcndbg) std::cout << "JcnModel::rmvEntry: " << s.simplified().toUpper() << std::endl; _entryMap.erase(s.simplified().toUpper()); takeRow(itemRow); return true; }
void QgsGlobePluginDialog::moveRow( QTableWidget* widget, bool up ) { //moves QTableWidget row up or down if ( widget->selectedItems().count() > 0 ) { const int sourceRow = widget->currentItem()->row(); const int destRow = ( up ? sourceRow - 1 : sourceRow + 1 ); if ( destRow >= 0 && destRow < widget->rowCount() ) { // take whole rows QList<QTableWidgetItem*> sourceItems = takeRow( widget, sourceRow ); QList<QTableWidgetItem*> destItems = takeRow( widget, destRow ); // set back in reverse order setRow( widget, sourceRow, destItems ); setRow( widget, destRow, sourceItems ); widget->selectRow( destRow ); } } }
unsigned SubmitFileModel::filter(const QStringList &filter, int column) { unsigned rc = 0; for (int r = rowCount() - 1; r >= 0; r--) if (const QStandardItem *i = item(r, column)) if (!filter.contains(i->text())) { qDeleteAll(takeRow(r)); rc++; } return rc; }
bool SourceFileModel::dropSourceFiles(QMimeData const *data, Qt::DropAction action, int row, QModelIndex const &parent) { if (action != Qt::MoveAction) return QAbstractItemModel::dropMimeData(data, action, row, 0, parent); auto encoded = data->data(mtx::gui::MimeTypes::MergeSourceFileModelItem); QDataStream stream{&encoded, QIODevice::ReadOnly}; while (!stream.atEnd()) { quint64 value; stream >> value; auto sourceFile = m_sourceFileMap[value]; auto sourceIdx = indexFromSourceFile(sourceFile.get()); if (!sourceIdx.isValid()) continue; auto sourceParent = sourceIdx.parent(); auto sourceParentItem = sourceParent.isValid() ? itemFromIndex(sourceParent) : invisibleRootItem(); auto rowItems = sourceParentItem->takeRow(sourceIdx.row()); if (!parent.isValid()) { if ((sourceParent == parent) && (sourceIdx.row() < row)) --row; invisibleRootItem()->insertRow(row, rowItems); ++row; } else { auto parentFile = fromIndex(parent); Q_ASSERT(parentFile); if (sourceFile->isAdditionalPart()) row = std::min(row, parentFile->m_additionalParts.size()); else row = std::max(row, parentFile->m_additionalParts.size()); if ((sourceParent == parent) && (sourceIdx.row() < row)) --row; itemFromIndex(parent)->insertRow(row, rowItems); ++row; } updateSourceFileLists(); } return false; }
unsigned SubmitFileModel::filter(const QStringList &filter, int column) { unsigned rc = 0; for (int r = rowCount() - 1; r >= 0; r--) if (const QStandardItem *i = item(r, column)) if (!filter.contains(i->text())) { qDeleteAll(takeRow(r)); rc++; } if (VCSBase::Constants::Internal::debug) qDebug() << Q_FUNC_INFO << " deleted " << rc << " items using " << filter << " , remaining " << rowCount(); return rc; }
void PrinterModel::getDestsFinished() { KCupsRequest *request = qobject_cast<KCupsRequest *>(sender()); if (request) { if (request->hasError()) { emit error(request->error(), request->serverError(), request->errorMsg()); if (request->error() == IPP_SERVICE_UNAVAILABLE) { // Check if the service is up again QTimer::singleShot(1000, this, SLOT(update())); } // clear the model after so that the proper widget can be shown clear(); } else { KCupsPrinters printers = request->printers(); for (int i = 0; i < printers.size(); ++i) { // If there is a printer and it's not the current one add it // as a new destination int dest_row = destRow(printers.at(i).name()); if (dest_row == -1) { // not found, insert new one insertDest(i, printers.at(i)); } else if (dest_row == i) { // update the printer updateDest(item(i), printers.at(i)); } else { // found at wrong position // take it and insert on the right position QList<QStandardItem *> row = takeRow(dest_row); insertRow(i, row); updateDest(item(i), printers.at(i)); } } // remove old printers // The above code starts from 0 and make sure // dest == modelIndex(x) and if it's not the // case it either inserts or moves it. // so any item > num_jobs can be safely deleted while (rowCount() > printers.size()) { removeRow(rowCount() - 1); } emit error(IPP_OK, QString(), QString()); } request->deleteLater(); } else { kWarning() << "Should not be called from a non KCupsRequest class" << sender(); } }
void QgsLegendModel::setLayerSetAndGroups( const QStringList& layerIds, const QList< GroupLayerInfo >& groupInfo ) { setLayerSet( layerIds ); QStandardItem* currentItem = 0; QStandardItem* currentGroupItem = 0; int i = 0; QList< GroupLayerInfo >::const_iterator infoIt = groupInfo.constBegin(); for ( ; infoIt != groupInfo.constEnd() && i < invisibleRootItem()->rowCount(); ) { currentItem = invisibleRootItem()->child( i, 0 ); QString infoKey = infoIt->first; if ( infoKey.isNull() ) //a toplevel layer { ++i; } else //a group { currentGroupItem = addGroup( infoKey, i ); ++i; QList<QString> layerList = infoIt->second; QList<QString>::const_iterator groupLayerIt = layerList.constBegin(); for ( ; currentItem && ( groupLayerIt != layerList.constEnd() ); ++groupLayerIt ) { //check if current item is contained in this group QgsComposerLayerItem* layerItem = dynamic_cast<QgsComposerLayerItem*>( currentItem ); if ( !layerItem ) { return; //should never happen } //QString layerID = currentItem->data(Qt::UserRole + 2).toString(); QString layerID = layerItem->layerID(); if ( layerList.contains( layerID ) ) { takeRow( i ); currentGroupItem->setChild( currentGroupItem->rowCount(), 0, currentItem ); } else { ++i; } currentItem = invisibleRootItem()->child( i, 0 ); } } ++infoIt; } }
void PrintQueueModel::getJobFinished() { KCupsRequest *request = static_cast<KCupsRequest *>(sender()); if (request) { if (request->hasError()) { // emit error(request->error(), request->serverError(), request->errorMsg()); // clear the model after so that the proper widget can be shown // clear();// TODO remove also in printerModel } else { KCupsJobs jobs = request->jobs(); kDebug() << jobs.size(); for (int i = 0; i < jobs.size(); ++i) { if (jobs.at(i).state() == IPP_JOB_PROCESSING) { m_processingJob = jobs.at(i).name(); } // try to find the job row int job_row = jobRow(jobs.at(i).id()); if (job_row == -1) { // not found, insert new one insertJob(i, jobs.at(i)); } else if (job_row == i) { // update the job updateJob(i, jobs.at(i)); } else { // found at wrong position // take it and insert on the right position QList<QStandardItem *> row = takeRow(job_row); insertRow(i, row); updateJob(i, jobs.at(i)); } } // remove old printers // The above code starts from 0 and make sure // dest == modelIndex(x) and if it's not the // case it either inserts or moves it. // so any item > num_jobs can be safely deleted while (rowCount() > jobs.size()) { removeRow(rowCount() - 1); } } request->deleteLater(); } else { kWarning() << "Should not be called from a non KCupsRequest class" << sender(); } m_jobRequest = 0; }
void ActionModel::remove(int row) { qDeleteAll(takeRow(row)); }
void SourceFileModel::moveSourceFilesUpOrDown(QList<SourceFile *> files, bool up) { sortSourceFiles(files, !up); // qDebug() << "move up?" << up << "files" << files; auto couldNotBeMoved = QHash<SourceFile *, bool>{}; auto isSelected = QHash<SourceFile *, bool>{}; auto const direction = up ? -1 : +1; auto const topRows = rowCount(); for (auto const &file : files) { isSelected[file] = true; if (!file->isRegular() && isSelected[file->m_appendedTo]) continue; auto idx = indexFromSourceFile(file); Q_ASSERT(idx.isValid()); auto targetRow = idx.row() + direction; if (couldNotBeMoved[fromIndex(idx.sibling(targetRow, 0)).get()]) { couldNotBeMoved[file] = true; continue; } if (file->isRegular()) { if (!((0 <= targetRow) && (targetRow < topRows))) { couldNotBeMoved[file] = true; continue; } // qDebug() << "top level: would like to move" << idx.row() << "to" << targetRow; insertRow(targetRow, takeRow(idx.row())); continue; } auto parentItem = itemFromIndex(idx.parent()); auto const appendedAdditionalRows = countAppendedAndAdditionalParts(parentItem); auto const additionalPartsRows = appendedAdditionalRows.first; auto const appendedRows = appendedAdditionalRows.second; auto const lowerLimit = (file->isAdditionalPart() ? 0 : additionalPartsRows); auto const upperLimit = (file->isAdditionalPart() ? 0 : appendedRows) + additionalPartsRows; if ((lowerLimit <= targetRow) && (targetRow < upperLimit)) { // qDebug() << "appended level normal: would like to move" << idx.row() << "to" << targetRow; parentItem->insertRow(targetRow, parentItem->takeRow(idx.row())); continue; } auto parentIdx = parentItem->index(); Q_ASSERT(parentIdx.isValid()); auto newParentRow = parentIdx.row() + direction; if ((0 > newParentRow) || (rowCount() <= newParentRow)) { // qDebug() << "appended, cannot move further"; couldNotBeMoved[file] = true; continue; } auto newParent = fromIndex(index(newParentRow, 0)); auto newParentItem = itemFromIndex(index(newParentRow, 0)); auto rowItems = parentItem->takeRow(idx.row()); auto newParentNumbers = countAppendedAndAdditionalParts(newParentItem); targetRow = up && file->isAdditionalPart() ? newParentNumbers.first : up ? newParentNumbers.first + newParentNumbers.second : !up && file->isAdditionalPart() ? 0 : newParentNumbers.first; Q_ASSERT(!!newParent); // qDebug() << "appended level cross: would like to move" << idx.row() << "from" << file->m_appendedTo << "to" << newParent.get() << "as" << targetRow; newParentItem->insertRow(targetRow, rowItems); file->m_appendedTo = newParent.get(); } updateSourceFileLists(); }
bool SourceFileModel::dropSourceFiles(QMimeData const *data, Qt::DropAction action, int row, QModelIndex const &parent) { if (action != Qt::MoveAction) return QAbstractItemModel::dropMimeData(data, action, row, 0, parent); mxinfo(boost::format("dropMimeData row %1% parent %2%/%3%\n") % row % parent.row() % parent.column()); auto encoded = data->data(MIME_TYPE); QDataStream stream{&encoded, QIODevice::ReadOnly}; while (!stream.atEnd()) { quint64 value; stream >> value; auto sourceFile = m_sourceFileMap[value]; auto sourceIdx = indexFromSourceFile(sourceFile.get()); if (!sourceIdx.isValid()) continue; mxinfo(boost::format(" val %|1$08x| ptr %2% idx %3%/%4%\n") % value % sourceFile.get() % sourceIdx.row() % sourceIdx.column()); auto sourceParent = sourceIdx.parent(); auto sourceParentItem = sourceParent.isValid() ? itemFromIndex(sourceParent) : invisibleRootItem(); auto priorRow = row; auto rowItems = sourceParentItem->takeRow(sourceIdx.row()); if (!parent.isValid()) { if ((sourceParent == parent) && (sourceIdx.row() < row)) --row; mxinfo(boost::format("tried moving case 1 from %1% row %2% to new parent %3% row %4% new row %5%\n") % dumpIdx(sourceIdx.parent()) % sourceIdx.row() % dumpIdx(parent) % priorRow % (row + 1)); invisibleRootItem()->insertRow(row, rowItems); ++row; } else { auto parentFile = fromIndex(parent); Q_ASSERT(parentFile); if (sourceFile->isAdditionalPart()) row = std::min(row, parentFile->m_additionalParts.size()); else row = std::max(row, parentFile->m_additionalParts.size()); if ((sourceParent == parent) && (sourceIdx.row() < row)) --row; mxinfo(boost::format("tried moving case 2 from %1% row %2% to new parent %3% row %4% new row %5%\n") % dumpIdx(sourceIdx.parent()) % sourceIdx.row() % dumpIdx(parent) % priorRow % (row + 1)); itemFromIndex(parent)->insertRow(row, rowItems); ++row; } updateSourceFileLists(); } return false; }