void trn_mdl::rsz() { int c_rws = hstr_.size() / 2; //c_rws = std::max(c_rws, 1); if (c_rws == rw_cnt_ - 1) /* no need to insert or remove rows */ { emit(dataChanged(createIndex(c_rws, 0), createIndex(c_rws, 1))); } else if (c_rws > rw_cnt_ - 1) /* we have to insert some rows */ { beginInsertRows(QModelIndex(), rw_cnt_, c_rws); endInsertRows(); emit(dataChanged(createIndex(rw_cnt_ - 1, 0), createIndex(c_rws, 1))); } else /* we have to remove some rows */ { beginRemoveRows(QModelIndex(), c_rws + 1, rw_cnt_ -1); endRemoveRows(); emit(dataChanged(createIndex(rw_cnt_ - 1, 0), createIndex(c_rws, 1))); } rw_cnt_ = c_rws + 1; }
bool FormularModel::removeRows(int row, int count, const QModelIndex &parent) { if (row >= 0) { beginRemoveRows(parent, row, row + count - 1); for(int i = 0; i < count; i++) { FieldData *field = m_formularData.takeAt(row); if(field != NULL) { switch(field->getType()) { case FieldData::Integer: case FieldData::Real: case FieldData::Boolean: case FieldData::String: case FieldData::Unused: { delete field; break; } case FieldData::Scalable: { delete static_cast<FieldScalable*>(field); break; } case FieldData::Enumeration: { delete static_cast<FieldEnumeration*>(field); break; } case FieldData::Constant: { delete static_cast<FieldConstant*>(field); break; } } } } endRemoveRows(); emit dataChanged(index(row), index(row + count - 1, formularHeaderSections.size() - 1)); return true; } return false; }
bool MatrixModel::removeRows(int row, int count, const QModelIndex &parent) { beginRemoveRows(parent, row, row + count - 1); d_rows -= count; d_data_block_size = QSize(d_rows, d_cols); int removedCells = count * d_cols; int size = d_rows * d_cols; for (int i = row * d_cols; i < size; i++) d_data[i] = d_data[i + removedCells]; double *new_data = (double *)realloc(d_data, size * sizeof(double)); if (new_data == NULL) { // could not realloc, but orig still valid QMessageBox::critical(d_matrix, tr("MantidPlot") + " - " + tr("Memory Allocation Error"), tr("Not enough memory, operation aborted!")); } else { d_data = new_data; } endRemoveRows(); return true; }
void WindowListModel::onWindowRemoved(WId id) { int count = m_winList.count(); int iter = 0; bool found = false; while( iter < count ) { if( m_winList[iter].win() == id ) { found = true; break; } ++iter; } if( found ) { beginRemoveRows( QModelIndex(), iter, iter + 1 ); m_winList.removeAt(iter); endRemoveRows(); } }
void KPageWidgetModel::removePage(KPageWidgetItem *item) { if (!item) { return; } Q_D(KPageWidgetModel); PageItem *pageItem = d->rootItem->findChild(item); if (!pageItem) { qDebug("Invalid KPageWidgetItem passed!"); return; } emit layoutAboutToBeChanged(); disconnect(item, SIGNAL(changed()), this, SLOT(_k_itemChanged())); disconnect(item, SIGNAL(toggled(bool)), this, SLOT(_k_itemToggled(bool))); PageItem *parentPageItem = pageItem->parent(); int row = parentPageItem->row(); QModelIndex index; if (parentPageItem != d->rootItem) { index = createIndex(row, 0, parentPageItem); } beginRemoveRows(index, pageItem->row(), pageItem->row()); parentPageItem->removeChild(pageItem->row()); delete pageItem; endRemoveRows(); emit layoutChanged(); }
void QDBusModel::refresh(const QModelIndex &aIndex) { QModelIndex index = aIndex; while (index.isValid() && static_cast<QDBusItem *>(index.internalPointer())->type != PathItem) { index = index.parent(); } QDBusItem *item = static_cast<QDBusItem *>(index.internalPointer()); if (!item) item = root; if (!item->children.isEmpty()) { beginRemoveRows(index, 0, item->children.count() - 1); qDeleteAll(item->children); item->children.clear(); endRemoveRows(); } addPath(item); if (!item->children.isEmpty()) { beginInsertRows(index, 0, item->children.count() - 1); endInsertRows(); } }
void LauncherModel::unpin(const QString &appId) { if (!m_includePinnedApps) return; Application *found = Q_NULLPTR; Q_FOREACH (Application *item, m_list) { if (!item->isPinned()) break; if (item->appId() != appId) continue; found = item; } if (!found) return; Q_ASSERT(found->isPinned()); int i = m_list.indexOf(found); // Remove the item when unpinned and not running if (found->isRunning()) { found->setPinned(false); moveRows(i, 1, m_list.size() - 1); } else { beginRemoveRows(QModelIndex(), i, i); m_list.takeAt(i)->deleteLater(); endRemoveRows(); } pinLauncher(appId, false); }
void QgsMapLayerModel::setAdditionalItems( const QStringList &items ) { if ( items == mAdditionalItems ) return; int offset = 0; if ( mAllowEmpty ) offset++; offset += mLayers.count(); //remove existing if ( !mAdditionalItems.isEmpty() ) { beginRemoveRows( QModelIndex(), offset, offset + mAdditionalItems.count() - 1 ); mAdditionalItems.clear(); endRemoveRows(); } //add new beginInsertRows( QModelIndex(), offset, offset + items.count() - 1 ); mAdditionalItems = items; endInsertRows(); }
void ColumnNameResult::setColumnValues(QList<QStringList> columns) { if (rowCount() != 1) { beginRemoveRows(QModelIndex(), 1, rowCount()-1); columnValues.clear(); endRemoveRows(); } if (columnCount() != 0) { beginRemoveColumns(QModelIndex(), 0, columnCount()-1); columnNames.clear(); endRemoveColumns(); } QStringList first = columns.first(); beginInsertColumns(QModelIndex(), 0, first.count()-1); for(int i = 0; i < first.count(); i++) columnNames.append(QString()); endInsertColumns(); beginInsertRows(QModelIndex(), 0, columns.count()-1); columnValues = columns; endInsertRows(); }
Application *LauncherModel::addApplication(const QString &appId, bool pinned) { auto app = new Application(appId, pinned, this); if (pinned && !app->isValid()) { pinLauncher(appId, false); return nullptr; } QObject::connect(app, &Application::launched, [=]() { QModelIndex modelIndex = index(indexFromAppId(appId)); emit dataChanged(modelIndex, modelIndex); QTimer::singleShot(5000, [=]() { if (app->isStarting()) { qDebug() << "Application failed to start!" << appId; auto i = indexFromAppId(appId); if (app->isPinned()) { QModelIndex modelIndex = index(i); app->setState(Application::NotRunning); emit dataChanged(modelIndex, modelIndex); } else { beginRemoveRows(QModelIndex(), i, i); m_list.takeAt(i)->deleteLater(); endRemoveRows(); } } else { qDebug() << "Application is now running" << appId; } }); }); m_list.append(app); return app; }
bool CategoryListModel::removeRows(int position, int rows, const QModelIndex &index) { Q_UNUSED(index); beginRemoveRows(QModelIndex(), position, position+rows-1); for (int row = 0; row < rows; ++row) { boost::shared_ptr<Category> category = d_category_list.at(position); if (category->resourceList().count() > 0) { //TODO: Popup msgbox, Please delete all attached resources of this category before deleting it. } else { d_category_list.removeAt(position); } } endRemoveRows(); return true; }
void RoutesTableModel::_removeRoute(int index) { beginRemoveRows(QModelIndex(), index, index); QPoint from = m_routes[index].first; QPoint to = m_routes[index].second; m_from[from].removeOne(index); if (m_from[from].empty()) { m_from.remove(from); } m_to[to].removeOne(index); if (m_to[to].empty()) { m_to.remove(to); } m_routes.removeAt(index); m_factors.removeAt(index); endRemoveRows(); }
void HWStubContextModel::EnableDummy(bool en, const QString& text) { /* if needed, create/remove raw */ if(m_has_dummy && !en) { /* remove row */ beginRemoveRows(QModelIndex(), 0, 0); m_has_dummy = false; endRemoveRows(); } else if(!m_has_dummy && en) { /* add row */ beginInsertRows(QModelIndex(), 0, 0); m_has_dummy = true; m_dummy_text = text; endInsertRows(); } else if(en) { /* text change only */ emit dataChanged(index(0, GetNameColumn()), index(0, GetNameColumn())); } }
bool MessageModel::removeRows(int row, int count, const QModelIndex & parent) { MessageTableEntry *rec = priv->index(row); if(count != 1 || !rec) // Can only remove one row at a time, and cannot remove rows not in model. return false; { LOCK(cs_smsgDB); SecMsgDB dbSmsg; if (!dbSmsg.Open("cr+")) //throw runtime_error("Could not open DB."); return false; dbSmsg.EraseSmesg(&rec->chKey[0]); } beginRemoveRows(parent, row, row); priv->cachedMessageTable.removeAt(row); endRemoveRows(); return true; }
//-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- bool UiTreeModelPdm::removeRows_special(int position, int count, const QModelIndex &parent /*= QModelIndex()*/) { if (count <= 0) return true; PdmUiTreeItem* parentItem = NULL; if (parent.isValid()) { parentItem = getTreeItemFromIndex(parent); } else { parentItem = m_treeItemRoot; } if (!parentItem) return true; bool success = true; beginRemoveRows(parent, position, position + count - 1); success = parentItem->removeChildren(position, count); endRemoveRows(); return success; }
void MergeModel::RemoveModel (QAbstractItemModel *model) { auto i = FindModel (model); if (i == Models_.end ()) { qWarning () << Q_FUNC_INFO << "not found model" << model; return; } for (auto r = Root_->begin (); r != Root_->end (); ) if ((*r)->GetModel () == model) { const auto idx = std::distance (Root_->begin (), r); beginRemoveRows ({}, idx, idx); r = Root_->EraseChild (r); endRemoveRows (); } else ++r; Models_.erase (i); }
bool CurveNameList::removeRows (int row, int count, const QModelIndex &parent) { bool skip = (count != 1 || row < 0 || row > rowCount () || parent.isValid()); LOG4CPP_DEBUG_S ((*mainCat)) << "CurveNameList::removeRows" << " row=" << row << " count=" << count << " isRoot=" << (parent.isValid () ? "no" : "yes") << " skip=" << (skip ? "yes" : "no"); bool success = false; beginRemoveRows (QModelIndex (), row, row + count - 1); m_modelCurvesEntries.removeAt (row); endRemoveRows (); return success; }
bool QgsComposerAttributeTableColumnModelV2::moveRow( int row, ShiftDirection direction ) { if (( direction == ShiftUp && row <= 0 ) || ( direction == ShiftDown && row >= rowCount() - 1 ) ) { //row is already at top/bottom return false; } //we shift a row by removing the next row up/down, then reinserting it before/after the target row int swapWithRow = direction == ShiftUp ? row - 1 : row + 1; //remove row beginRemoveRows( QModelIndex(), swapWithRow, swapWithRow ); QgsComposerTableColumn* temp = mComposerTable->columns()->takeAt( swapWithRow ); endRemoveRows(); //insert row beginInsertRows( QModelIndex(), row, row ); mComposerTable->columns()->insert( row, temp ); endInsertRows(); return true; }
bool SetsModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int /*column*/, const QModelIndex &parent) { if (action != Qt::MoveAction) return false; if (row == -1) { if (!parent.isValid()) return false; row = parent.row(); } int oldRow = qobject_cast<const SetsMimeData *>(data)->getOldRow(); beginRemoveRows(QModelIndex(), oldRow, oldRow); CardSet *temp = sets.takeAt(oldRow); endRemoveRows(); if (oldRow < row) row--; beginInsertRows(QModelIndex(), row, row); sets.insert(row, temp); endInsertRows(); for (int i = 0; i < sets.size(); i++) sets[i]->setSortKey(i); return true; }
void WSortFilterProxyModel::sourceRowsAboutToBeRemoved (const WModelIndex& parent, int start, int end) { WModelIndex pparent = mapFromSource(parent); // distinguish between invalid parent being root item or being filtered out if (parent.isValid() && !pparent.isValid()) return; Item *item = itemFromIndex(pparent); for (int row = start; row <= end; ++row) { int mappedRow = item->sourceRowMap_[row]; if (mappedRow != -1) { beginRemoveRows(pparent, mappedRow, mappedRow); item->proxyRowMap_.erase(item->proxyRowMap_.begin() + mappedRow); rebuildSourceRowMap(item); // erase may have shifted some endRemoveRows(); } } int count = end - start + 1; startShiftModelIndexes(parent, start, -count, mappedIndexes_); }
bool RataModel::removeRow(int row, const QModelIndex &parent) { beginRemoveRows(parent, row, row); bool res = false; Sarja *s = 0; if (parent.isValid()) { s = m_sarjat.at(parent.row()); res = s->getRastit().at(row).dbDelete(); s->removeRasti(row); } else { s = m_sarjat.at(row); res = s->dbDelete(); m_sarjat.removeAt(row); } endRemoveRows(); return res; }
bool DeckListModel::removeRows(int row, int count, const QModelIndex &parent) { InnerDecklistNode *node = getNode<InnerDecklistNode *>(parent); if (!node) return false; if (row + count > node->size()) return false; beginRemoveRows(parent, row, row + count - 1); for (int i = 0; i < count; i++) { AbstractDecklistNode *toDelete = node->takeAt(row); if (DecklistModelCardNode *temp = dynamic_cast<DecklistModelCardNode *>(toDelete)) deckList->deleteNode(temp->getDataNode()); delete toDelete; } endRemoveRows(); if (!node->size() && (node != root)) removeRows(parent.row(), 1, parent.parent()); else emitRecursiveUpdates(parent); return true; }
void RKModificationTracker::moveObject (RContainerObject *parent, RObject* child, int old_index, int new_index) { RK_TRACE (OBJECTS); RK_ASSERT (!child->isPseudoObject ()); QModelIndex parent_index; if (!updates_locked) { parent_index = indexFor (parent); beginRemoveRows (parent_index, old_index, old_index); } RK_ASSERT (parent->findChildByIndex (old_index) == child); parent->removeChildNoDelete (child); if (!updates_locked) { endRemoveRows (); beginInsertRows (parent_index, new_index, new_index); } parent->insertChild (child, new_index); RK_ASSERT (parent->findChildByIndex (new_index) == child); if (!updates_locked) { endInsertRows (); sendListenerNotification (RObjectListener::ChildMoved, parent, old_index, new_index, 0); } }
void ShortcutModel::remove(const QModelIndex& index) { if (!m_userRule) { return; } if (!index.isValid()) { return; } if (index.row() >= m_entries.size()) { return; } beginRemoveRows(QModelIndex(), index.row(), index.row()); KkcKeymap* map = kkc_rule_get_keymap(KKC_RULE(m_userRule), m_entries[index.row()].mode()); kkc_keymap_set(map, m_entries[index.row()].event(), NULL); g_object_unref(map); m_entries.removeAt(index.row()); endRemoveRows(); setNeedSave(true); }
void PhonemeGroupModel::onPhonemeGroupsRemoved() { endRemoveRows(); }
bool PlaylistModel::handle_change (const Xmms::Dict &chg) { int32_t change = chg.get<int32_t> ("type"); int32_t pos = 0, npos = 0; int32_t id = 0; QString s; if (chg.contains ("position")) { pos = chg.get<int32_t> ("position"); } if (chg.contains ("id")) { #if HAVE_XMMSV id = chg.get<int32_t> ("id"); #else id = chg.get<uint32_t> ("id"); #endif } if (chg.contains ("name")) { s = XClient::stdToQ (chg.get<std::string> ("name")); } if (s != m_name) { return true; } QModelIndex idx = QModelIndex (); switch (change) { case XMMS_PLAYLIST_CHANGED_ADD: beginInsertRows (idx, pos, pos); m_plist.append (id); endInsertRows (); break; case XMMS_PLAYLIST_CHANGED_INSERT: beginInsertRows (idx, pos, pos); m_plist.insert (pos, id); endInsertRows (); break; case XMMS_PLAYLIST_CHANGED_MOVE: npos = chg.get<int32_t> ("newposition"); beginRemoveRows (idx, pos, pos); m_plist.removeAt (pos); endRemoveRows (); beginInsertRows (idx, npos, npos); m_plist.insert (npos, id); endInsertRows (); if (pos < npos && pos) pos --; emit entryMoved (index (pos, 0), index (npos, 0)); break; case XMMS_PLAYLIST_CHANGED_REMOVE: m_client->cache ()->invalidate (m_plist[pos]); beginRemoveRows (idx, pos, pos); m_plist.removeAt (pos); endRemoveRows (); break; default: m_client->cache ()->invalidate_all (); m_client->playlist ()->listEntries () (Xmms::bind (&PlaylistModel::handle_list, this)); break; } /* TODO: call this only for the necessary methods */ emitTotalPlaytime (); return true; }
void QgsCategorizedSymbolRendererV2Model::removeAllRows( ) { beginRemoveRows( QModelIndex(), 0, mRenderer->categories().size() - 1 ); mRenderer->deleteAllCategories(); endRemoveRows(); }
void PluginModel::clear() { beginRemoveRows(QModelIndex(), 0, rowCount()); items_.clear(); endRemoveRows(); }
void LanguageResourceModel::onLanguageResourceRemoved() { endRemoveRows(); }
void Utils::ModelListModel::handleRowsRemoved() { endRemoveRows(); emit layoutChanged(); }