Esempio n. 1
2
bool PiecesModel::removeRows(int row, int count, const QModelIndex &parent)
{
    if (parent.isValid())
        return false;

    if (row >= pixmaps.size() || row + count <= 0)
        return false;

    int beginRow = qMax(0, row);
    int endRow = qMin(row + count - 1, pixmaps.size() - 1);

    beginRemoveRows(parent, beginRow, endRow);

    while (beginRow <= endRow) {
        pixmaps.removeAt(beginRow);
        locations.removeAt(beginRow);
        ++beginRow;
    }

    endRemoveRows();
    return true;
}
Esempio n. 2
1
bool
CategoryModel::removeRows(int row, int count, const QModelIndex& /*parent*/)
{
	if (model_ == nullptr || count != 1) {
		return false;
	}
	if (row < 0 || static_cast<std::size_t>(row) >= model_->categoryList().size()) {
		return false;
	}
	if (model_->categoryList()[row].use_count() > 1) {
		emit errorOccurred(tr("Can't remove category in use."));
		return false;
	}

	beginRemoveRows(QModelIndex(), row, row);
	model_->categoryList().erase(model_->categoryList().begin() + row);
	endRemoveRows();

	emit categoryChanged();

	return true;
}
Esempio n. 3
0
void HWStubContextModel::SetContext(std::shared_ptr< hwstub::context > context)
{
    int first_row = m_has_dummy ? 1: 0;
    /* clear previous model if any */
    if(m_list.size() > 0)
    {
        beginRemoveRows(QModelIndex(), first_row, first_row + m_list.size() - 1);
        m_list.clear();
        endRemoveRows();
    }
    /* don't forget to unregister callback if context still exists */
    std::shared_ptr< hwstub::context > ctx = m_context.lock();
    if(ctx)
        ctx->unregister_callback(m_callback_ref);
    /* get new context */
    m_context = context;
    if(context)
    {
        /* register new callback */
        m_callback_ref = context->register_callback(
            std::bind(&HWStubContextModel::OnDevChangeLow, this, std::placeholders::_1,
                std::placeholders::_2, std::placeholders::_3));
        /* get dev list */
        std::vector< std::shared_ptr< hwstub::device > > list;
        hwstub::error err = context->get_device_list(list);
        if(err == hwstub::error::SUCCESS)
        {
            beginInsertRows(QModelIndex(), first_row, first_row + list.size() - 1);
            for(auto& d : list)
            {
                Device dev;
                dev.name = GetFriendlyName(d);
                dev.device = d;
                m_list.push_back(dev);
            }
            endInsertRows();
        }
    }
}
Esempio n. 4
0
void WBHistoryFilterModel::sourceRowsInserted(const QModelIndex &parent, int start, int end)
{
    Q_ASSERT(start == end && start == 0);
    Q_UNUSED(end);
    if (!m_loaded)
        return;
    QModelIndex idx = sourceModel()->index(start, 0, parent);
    QString url = idx.data(WBHistoryModel::UrlStringRole).toString();
    if (m_historyHash.contains(url))
    {
        int sourceRow = sourceModel()->rowCount() - m_historyHash[url];
        int realRow = mapFromSource(sourceModel()->index(sourceRow, 0)).row();
        beginRemoveRows(QModelIndex(), realRow, realRow);
        m_sourceRow.removeAt(realRow);
        m_historyHash.remove(url);
        endRemoveRows();
    }
    beginInsertRows(QModelIndex(), 0, 0);
    m_historyHash.insert(url, sourceModel()->rowCount() - start);
    m_sourceRow.insert(0, sourceModel()->rowCount());
    endInsertRows();
}
Esempio n. 5
0
// -------------------------------------------------------------------------------
bool CCollectionModel::removeRow( int iRow, const QModelIndex& parent )
// -------------------------------------------------------------------------------
{
   Q_ASSERT( NULLPTR != mpCollection );
   if ( !mpCollection )
      return FALSE;


   if ( !parent.isValid() )
      return FALSE;

   CInformationElement* pParentIE = mapIndexToIE( parent );
   Q_ASSERT( NULLPTR != pParentIE );
   if ( !pParentIE )
      return FALSE;

   beginRemoveRows( parent, iRow, iRow );  // begin removal
   pParentIE->removeChild( iRow );
   endRemoveRows();                        // end removal
   
   return TRUE;
}
/**
 * @brief ProjectManagerTreeModel::removeRows Remove rows from this model.
 * @param row Row number where we start removing items.
 * @param count How many items we want to remove.
 * @param parent Parent of items we want to remove.
 * @return True if we removed items, false otherwise.
 */
bool ProjectManagerTreeModel::removeRows(int row, int count, const QModelIndex &parent)
{
    beginRemoveRows(parent, row, row+count);

    if(insertType == ProjectTreeItem::PROJECT)
    {
        ProjectTreeItem* item = root->getChild(row);

        delete item;
    }
    else if(insertType == ProjectTreeItem::SHADER)
    {
        ProjectTreeItem* parentItem = static_cast<ProjectTreeItem*>(parent.internalPointer());
        ProjectTreeItem* item = parentItem->getChild(row);

        delete item;
    }

    endRemoveRows();

    return true;
}
bool RKVarEditModel::removeRows (int row, int count, const QModelIndex& parent) {
	RK_TRACE (EDITOR);

	int lastrow = row+count - 1;
	if (edit_blocks || parent.isValid () || objects.isEmpty () || (lastrow >= (apparentRows ()))) {
		RK_ASSERT (false);
		return false;
	}
	if (lastrow >= objects[0]->getLength ()) lastrow = objects[0]->getLength () - 1;
	RK_ASSERT (row >= 0);
	RK_ASSERT (lastrow >= row);

	beginRemoveRows (QModelIndex (), row, lastrow);
	doRemoveRowsInBackend (row, lastrow - row + 1);
	for (int i=0; i < objects.size (); ++i) {
// TODO: this does not emit any data change notifications to other editors
		objects[i]->removeRows (row, lastrow);
	}
	endRemoveRows ();

	return true;
}
Esempio n. 8
0
//update the choices of the variable, called on UI thread
void VLCVarChoiceModel::onListUpdated(const vlc_object_t* object, int action, QVariant newvalue)
{
    if (object != m_object->get())
        return;

    switch (action) {
    case VLC_VAR_ADDCHOICE:
        beginInsertRows( QModelIndex{}, m_values.count(), m_values.count() );
        m_values.append( newvalue );
        //we should probably rather get the whole choices list to get the associated text
        m_titles.append( newvalue.toString() );
        endInsertRows();
        break;
    case VLC_VAR_DELCHOICE:
    {
        int i = 0;
        for (i = 0; i < m_values.count(); i++)
            if (newvalue == m_values[i])
                break;
        if (i != m_values.count())
        {
            beginRemoveRows( QModelIndex{}, i, i);
            m_values.removeAt(i);
            m_titles.removeAt(i);
            endRemoveRows();
        }
        break;
    }
    case VLC_VAR_CLEARCHOICES:
        beginResetModel();
        m_values.clear();
        m_titles.clear();
        endResetModel();
        break;
    default:
        //N/A
        break;
    }
}
Esempio n. 9
0
void
CollectionInfoModel::set_data (const QList < QHash < QString, QVariant > > &data)
{
	/* Clear the model */
	beginRemoveRows (QModelIndex (), 0, rowCount ());
    clear ();
	endRemoveRows ();
	
    /* take the headers and add the columns */
    QStringList s = data[0].keys ();
    setColumnCount (s.size ());
    
    for (int i = 0; i < s.size (); i ++) {
        /* capitilize this string later */
        QStandardItem *m = new QStandardItem (s.value (i));
        m->setEditable (false);
        setHorizontalHeaderItem (i, m);
    }
    
    /* run through them */
    if (m_all_field) {
        QStandardItem *item = new QStandardItem (tr ("[ All ]"));
        item->setEditable (false);
        appendRow (item);
    }

	for (int i = 0; i < data.size (); i ++) {
        QList<QStandardItem *> l;

		QHash<QString, QVariant> hash = data[i];
        for (int i = 0; i < s.size (); i ++) {
            QStandardItem *item = new QStandardItem (hash[s.value (i)].toString ());
            item->setEditable (false);
            l.append (item);
        }
        appendRow (l);
	}
	
}
Esempio n. 10
0
void DivePlannerPointsModel::setDropStoneMode(bool value)
{
	auto planner = SettingsObjectWrapper::instance()->planner_settings;
	planner->setDropStoneMode(value);
	if (prefs.drop_stone_mode) {
	/* Remove the first entry if we enable drop_stone_mode */
		if (rowCount() >= 2) {
			beginRemoveRows(QModelIndex(), 0, 0);
			divepoints.remove(0);
			endRemoveRows();
		}
	} else {
		/* Add a first entry if we disable drop_stone_mode */
		beginInsertRows(QModelIndex(), 0, 0);
		/* Copy the first current point */
		divedatapoint p = divepoints.at(0);
		p.time = p.depth.mm / prefs.descrate;
		divepoints.push_front(p);
		endInsertRows();
	}
	emitDataChanged();
}
bool RecentRequestsTableModel::removeRows(int row, int count, const QModelIndex &parent)
{
    Q_UNUSED(parent);

    if(count > 0 && row >= 0 && (row+count) <= list.size())
    {
        const RecentRequestEntry *rec;
        for (int i = 0; i < count; ++i)
        {
            rec = &list[row+i];
            if (!walletModel->saveReceiveRequest(rec->recipient.address.toStdString(), rec->id, ""))
                return false;
        }

        beginRemoveRows(parent, row, row + count - 1);
        list.erase(list.begin() + row, list.begin() + row + count);
        endRemoveRows();
        return true;
    } else {
        return false;
    }
}
bool TreeModel::removeRows(int position, int rows, const QModelIndex &parent)
{
    TreeItem *parentItem;

    if (!parent.isValid())
        parentItem = rootItem;
    else
        parentItem = static_cast<TreeItem*>(parent.internalPointer());

    if (position < 0 || position > parentItem->childCount())
        return false;

    beginRemoveRows(parent, position, position + rows - 1);

    for (int row = 0; row < rows; ++row) {
        if (!parentItem->removeChild(position))
            break;
    }

    endRemoveRows();
    return true;
}
Esempio n. 13
0
bool CDocumentModel::removeRows( int row, int count, const QModelIndex &parent )
{
	if( parent.isValid() || d->isEncryptedWarning() )
		return false;

	if( !d->d->doc || row >= d->d->doc->nDataFiles || !d->d->doc->pDataFiles[row] )
	{
		d->setLastError( tr("Internal error") );
		return false;
	}

	beginRemoveRows( parent, row, row + count );
	for( int i = row + count - 1; i >= row; --i )
	{
		int err = DataFile_delete( d->d->doc, d->d->doc->pDataFiles[i]->szId );
		if( err != ERR_OK )
			d->setLastError( tr("Failed to remove file"), err );
		m_data.removeAt( i );
	}
	endRemoveRows();
	return true;
}
Esempio n. 14
0
void EventsModel::clearServerEvents(DVRServer *server)
{
    if (!server && !(server = qobject_cast<DVRServer*>(sender())))
    {
        ServerRequestManager *srm = qobject_cast<ServerRequestManager*>(sender());
        if (srm)
            server = srm->server;
        else
        {
            Q_ASSERT_X(false, "clearServerEvents", "No server and no appropriate sender");
            return;
        }
    }

    /* Group contiguous removed rows together; provides a significant boost in performance */
    int removeFirst = -1;
    for (int i = 0; ; ++i)
    {
        if (i < items.size() && items[i]->server() == server)
        {
            if (removeFirst < 0)
                removeFirst = i;
        }
        else if (removeFirst >= 0)
        {
            beginRemoveRows(QModelIndex(), removeFirst, i-1);
            items.erase(items.begin()+removeFirst, items.begin()+i);
            i = removeFirst;
            removeFirst = -1;
            endRemoveRows();
        }

        if (i == items.size())
            break;
    }

    cachedEvents.remove(server);
}
Esempio n. 15
0
void SensorBrowserModel::removeSensor(HostInfo *hostInfo, int parentId, const QString &sensorName) {
    //sensorName is the full version.  e.g.  mem/free
    QList<int> children = mTreeMap.value(parentId);
    int idCount = -1;
    int index;
    for(index=0; index<children.size(); index++)
        if(mSensorInfoMap.contains(children[index])) {
            Q_ASSERT(mSensorInfoMap.value(children[index]));
            if(mSensorInfoMap.value(children[index])->name() == sensorName) {
                idCount = children[index];
                break;
            }
        }
    if(idCount == -1) {
        kDebug(1215) << "removeSensor called for sensor that doesn't exist in the tree: " << sensorName ;
        return;
    }
    QModelIndex parentModelIndex;
    int parentsParentId = -1;
    if(hostInfo->id() == parentId) {
        parentModelIndex = createIndex(mHostInfoMap.keys().indexOf(parentId), 0 , parentId);
    } else {
        parentsParentId = mParentsTreeMap.value(parentId);
        parentModelIndex = createIndex(mTreeMap.value(parentsParentId).indexOf(parentId), 0, parentId);
    }
    Q_ASSERT(parentModelIndex.isValid());
    QList<int> &parentTreemap = mTreeMap[parentId];
    beginRemoveRows( parentModelIndex, index, index );
    parentTreemap.removeAll(idCount);
    mParentsTreeMap.remove(idCount);
    SensorInfo *sensorInfo = mSensorInfoMap.take(idCount);
    delete sensorInfo;
    mHostSensorsMap[hostInfo->id()].remove(sensorName);
    endRemoveRows();

    if(parentsParentId != -1)
        removeEmptyParentTreeBranches(hostInfo->id(), parentId, parentsParentId);
}
Esempio n. 16
0
bool CQUnitDM::removeRows(int position, int rows)
{
  if (rows <= 0)
    return true;

  std::vector< std::string > DeletedKeys;
  DeletedKeys.resize(rows);

  std::vector< std::string >::iterator itDeletedKey;
  std::vector< std::string >::iterator endDeletedKey = DeletedKeys.end();

  CCopasiVector< CUnitDefinition >::const_iterator itRow =
    CCopasiRootContainer::getUnitList()->begin() + position;
  int row = 0;

  for (itDeletedKey = DeletedKeys.begin(), row = 0; itDeletedKey != endDeletedKey; ++itDeletedKey, ++itRow, ++row)
    {
      *itDeletedKey = itRow->getKey();
    }

  beginRemoveRows(QModelIndex(), position, position + row - 1);

  for (itDeletedKey = DeletedKeys.begin(), row = 0; itDeletedKey != endDeletedKey; ++itDeletedKey, ++row)
    {
      if (*itDeletedKey != "")
        {
          CCopasiObject * pUnitDef = CCopasiRootContainer::getKeyFactory()->get(*itDeletedKey);

          if (pUnitDef != NULL) delete pUnitDef;

          emit notifyGUI(ListViews::UNIT, ListViews::DELETE, *itDeletedKey);
        }
    }

  endRemoveRows();

  return true;
}
Esempio n. 17
0
void MashStepTableModel::setMash( Mash* m )
{
   int i;
   if( mashObs && steps.size() > 0)
   {
      beginRemoveRows( QModelIndex(), 0, steps.size()-1 );
      // Remove mashObs and all steps.
      disconnect( mashObs, 0, this, 0 );
      for( i = 0; i < steps.size(); ++i )
         disconnect( steps[i], 0, this, 0 );
      steps.clear();
      endRemoveRows();
   }

   mashObs = m;
   if( mashObs )
   {
      // This has to happen outside of the if{} block to make sure the mash
      // signal is connected. Otherwise, empty mashes will never be not empty.
      connect( mashObs, SIGNAL(mashStepsChanged()), this, SLOT(mashChanged()) );

      QList<MashStep*> tmpSteps = mashObs->mashSteps();
      if(tmpSteps.size() > 0){
         beginInsertRows( QModelIndex(), 0, tmpSteps.size()-1 );
         //connect( mashObs, SIGNAL(changed(QMetaProperty,QVariant)), this, SLOT(mashChanged(QMetaProperty,QVariant)) );
         steps = tmpSteps;
         for( i = 0; i < steps.size(); ++i )
            connect( steps[i], SIGNAL(changed(QMetaProperty,QVariant)), this, SLOT(mashStepChanged(QMetaProperty,QVariant)) );
         endInsertRows();
     }
   }

   if( parentTableWidget )
   {
      parentTableWidget->resizeColumnsToContents();
      parentTableWidget->resizeRowsToContents();
   }
}
Esempio n. 18
0
bool Drive::recalculate(QList<Tag *> tags) {
    if(this->results_.size() > 0) {
        beginRemoveRows(QModelIndex(), 0, this->results_.size()-1);
        this->results_ = QFileInfoList();
        endRemoveRows();
    }

    QFileInfoList newResults;
    if(tags.size() == 0) {
        this->parent_->setExpressionLabel(tr("All Files"));
        newResults = this->directory_->entryInfoList(QDir::Files);
    } else {
        QString expressionLabel = "";
        QSet<QString> fileNames = tags[0]->allFiles();
        for (int i = 0; i < tags.size(); i += TAG_TREE_COLUMNS) {
            expressionLabel.append(tags[i]->data(0).toString());
            fileNames = fileNames.intersect(tags[i]->allFiles());

             if  (i < tags.size() - TAG_TREE_COLUMNS)
                 expressionLabel.append(tr(" &#x2229; "));
        }
        this->parent_->setExpressionLabel(expressionLabel);

        for(auto i = fileNames.begin(); i != fileNames.end(); ++i) {
            newResults.append(QFileInfo(*i));
        }
    }

    if(newResults.size() > 0) {
        beginInsertRows(QModelIndex(), 0, newResults.size()-1);
        this->results_ = newResults;
        endInsertRows();
    }

    this->sort(this->sortColumn_,this->sortOrder_);
    emit(doneCalculating());
    return true;
}
/**
 * @brief Deletes a dialog.
 *
 * The index of multiple dialogs may change, since they are sorted alphabetically.
 * Emits rowsAboutToBeRemoved(), removes the dialog
 * and then emits rowsRemoved(), as required by QAbstractItemModel.
 *
 * Then, emits dialog_deleted().
 *
 * Except for the deleted dialog, the existing selection is preserved,
 * though the index of many dialogs can change.
 * The selection is cleared before the operations and restored after,
 * updated with the new indexes.
 *
 * @param id Id of the dialog to delete.
 * @throws EditorException in case of error.
 */
void DialogsModel::delete_dialog(const QString& id) {

  // Make some checks first.
  if (!dialog_exists(id)) {
    throw EditorException(tr("Invalid dialog id: %1").arg(id));
  }

  // Save and clear the selection since a lot of indexes may change.
  QString old_selection = get_selected_id();
  clear_selection();

  // Delete from the strings file
  resources.remove_dialog(id.toStdString());

  // Remove from the indexed tree.
  QString parent_id;
  int index;
  if (dialog_tree.can_remove_key(id, parent_id, index)) {

    // Call beginRemoveRows() as requested by QAbstractItemModel.
    beginRemoveRows(id_to_index(parent_id), index, index);

    dialog_tree.remove_key(id);

    // Notify people before restoring the selection, so that they have a
    // chance to know new indexes before receiving selection signals.
    endRemoveRows();
  } else if (dialog_tree.remove_key(id)) {
    QModelIndex model_index = id_to_index(id);
    dataChanged(model_index, model_index);
  }

  // Notify people.
  emit dialog_deleted(id);

  // Restore the selection.
  set_selected_id(old_selection);
}
void QxtScheduleViewHeaderModel::viewModeChanged(const int viewMode)
{
    Q_UNUSED(viewMode);

    if (this->m_dataSource)
    {
        beginRemoveRows(QModelIndex(), 0, m_rowCountBuffer);
        m_rowCountBuffer = 0;
        endRemoveRows();

        beginInsertRows(QModelIndex(), 0, m_dataSource->rows());
        m_rowCountBuffer = m_dataSource->rows();
        endInsertRows();

        beginRemoveColumns(QModelIndex(), 0, m_colCountBuffer);
        m_colCountBuffer = 0;
        endRemoveColumns();

        beginInsertColumns(QModelIndex(), 0, m_dataSource->cols());
        m_colCountBuffer = m_dataSource->cols();
        endInsertColumns();
    }
}
Esempio n. 21
0
// removes an AMScan from this model. Does not delete the scan.  Call this before deleting a scan that has been added to the model.
bool AMScanSetModel::removeScan(AMScan* removeMe) {

	int index = scans_.indexOf(removeMe);

	if(index != -1) {
		disconnect(removeMe, 0, this, 0);

		emit layoutAboutToBeChanged();
		beginRemoveRows(QModelIndex(), index, index);
		scans_.removeAt(index);
		sourcePlotSettings_.removeAt(index);
		endRemoveRows();

		removeMe->release(this);	// remove our interest in this scan.

		emit scanRemoved();
		/// \todo hack: should not be needed... But we do to keep QTreeViews from getting messed up. Why?
		emit layoutChanged();
		return true;
	}
	else
		return false;
}
Esempio n. 22
0
bool SpectraOutputCatalog::removeRows(int row, int count, const QModelIndex &parent)
{
    if (!count)
        return false;
    emit beginRemoveRows(parent, row, row+count-1);

    for (int i = 0; i < count; ++i) {
        AbstractLocationOutput* alo = m_outputs.takeAt(row);

        if (alo->needsFreq()) {
            // Check if remaining outputs needs frequencies
            bool needsFreq = false;
            foreach (AbstractLocationOutput* _alo, m_outputs) {
                if (_alo->needsFreq()) {
                    needsFreq = true;
                    break;
                }
            }

            if (!needsFreq)
                emit frequencyIsNeededChanged(needsFreq);

        } else if (alo->needsPeriod()) {
void DeclarativeTabModel::removeTab(int tabId, const QString &thumbnail, int index)
{
#if DEBUG_LOGS
    qDebug() << "index:" << index << tabId;
#endif
    removeTab(tabId);
    QFile f(thumbnail);
    if (f.exists()) {
        f.remove();
    }

    if (index >= 0) {
        if (activeTabIndex() == index) {
            m_activeTab.setTabId(0);
        }
        beginRemoveRows(QModelIndex(), index, index);
        m_tabs.removeAt(index);
        endRemoveRows();
    }

    emit countChanged();
    emit tabClosed(tabId);
}
Esempio n. 24
0
void ChapterModel::dissolveLastChapter()
{
  if( rowCount(QModelIndex()) < 2 ) {
    return;
  }

  const int dissolveRow = rowCount(QModelIndex())-2;

  beginRemoveRows(QModelIndex(), dissolveRow, dissolveRow);
  ChapterNode *node = dynamic_cast<ChapterNode*>(_root->childItem(dissolveRow));
  const QStringList dissolvedFiles = node->files(node->rowCount());

  ChapterRoot *root = dynamic_cast<ChapterRoot*>(_root);
  root->removeAt(dissolveRow);
  endRemoveRows();

  const QModelIndex sourcesIndex =
      index(rowCount(QModelIndex())-1, 0, QModelIndex());
  beginInsertRows(sourcesIndex, 0, dissolvedFiles.size()-1);
  ChapterNode *sources = dynamic_cast<ChapterNode*>(priv::treeItem(sourcesIndex));
  sources->insertFiles(dissolvedFiles);
  endInsertRows();
}
 bool Project_ItemModel::removeRows(int position, int rows, const QModelIndex &parent){
	 if(!parent.isValid()) return false;
	 beginRemoveRows(parent, position, position+rows-1);
	 GsTL_item* item = static_cast<GsTL_item*>(parent.internalPointer());
	 GsTL_root_item* root_item = dynamic_cast<GsTL_root_item*>(item);
	 if(root_item) {
		 GsTL_grid_item* grid_item =  dynamic_cast<GsTL_grid_item*>(root_item->child(position));
		 grid_item->delete_grid();
/*
		std::string obj_name = grid_item->gridName().toStdString();
		bool ok = Root::instance()->delete_interface(gridModels_manager + "/" + obj_name);
		if (ok)
		{
			SmartPtr<Named_interface> ni = Root::instance()->interface(projects_manager + "/" + "project");
			GsTL_project* proj = dynamic_cast<GsTL_project*> (ni.raw_ptr());
			proj->deleted_object(obj_name);
		}
		*/
	 }
	 endRemoveRows();
	 return true;

 }
Esempio n. 26
0
void TabsModel::remove(int pos)
{
    if (pos < 0 || pos >= m_list.size())
        return;

    beginRemoveRows(QModelIndex(), pos, pos);
    QPointer<QObject> item = m_list.takeAt(pos);
    endRemoveRows();
    delete item;
    QModelIndex start = createIndex(pos, 0), end = createIndex(m_list.size() - 1, 0);
    emit dataChanged(start, end);
    if (currentWebViewIndex() < 0)
        return;

    if (m_list.empty())
        setCurrentWebViewIndex(-1);
    else {
        if (pos > 0)
            setCurrentWebViewIndex(pos - 1);
        else
            emit currentWebViewChanged();
    }
}
void RKModificationTracker::moveObject (RContainerObject *parent, RObject* child, int old_index, int new_index) {
	RK_TRACE (OBJECTS);

	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);
	}
}
Esempio n. 28
0
bool KNMusicModel::removeRows(int position, int rows, const QModelIndex &index)
{
    Q_UNUSED(index);
    //As the documentation said, called this function first.
    beginRemoveRows(QModelIndex(), position, position+rows-1);
    //Check whether the playing index row is in the the position.
    if(m_playingIndex.isValid() &&
            (m_playingIndex.row() >= position &&
             m_playingIndex.row() < rows+position))
    {
        //We have to tell the now playing to reset the current playing.
        emit playingItemRemoved();
    }
    //Check whether it is removing all the items.
    if(rows==m_detailInfos.size())
    {
        //Clear all the detail infos.
        m_detailInfos=QList<KNMusicDetailInfo>();
        //Reset the total duration.
        m_totalDuration=0;
    }
    else
    {
        //Remove those datas from the list.
        while(rows--)
        {
            //Take away the detail info, and remove the duration.
            m_totalDuration-=m_detailInfos.takeAt(position).duration;
        }
    }
    //As the documentation said, called this after remove rows.
    endRemoveRows();
    //Because this operation change the row count, the row count changed signal
    //will be emitted.
    emit rowCountChanged();
    return true;
}
Esempio n. 29
0
bool
PlaylistModel::handle_list (const Xmms::List< unsigned int > &list)
#endif
{
	beginRemoveRows (QModelIndex (), 0, m_plist.size ());
	m_plist.clear ();
	endRemoveRows ();

	int i = 0;
#if HAVE_XMMSV
	for (Xmms::List< int >::const_iterator iter = list.begin();
	     iter != list.end(); ++iter) {
		i++;
	}
#else
	for (list.first (); list.isValid (); ++list) {
		i ++;
	}
#endif
	beginInsertRows (QModelIndex (), 0, i);
#if HAVE_XMMSV
	for (Xmms::List< int >::const_iterator iter = list.begin();
	     iter != list.end(); ++iter) {
		m_plist.append (*iter);
	}
#else
	for (list.first (); list.isValid (); ++list) {
		m_plist.append (*list);
	}
#endif

	endInsertRows ();

	emitTotalPlaytime  ();

	return true;
}
void PendingUploadsModel::setData(const QStringList &data)
{
    Q_D(PendingUploadsModel);

    QStringList newData(data);

    for (int i = 0; i != d->contents.size(); ++i) {
        int index = newData.indexOf(d->contents.at(i).filePath);
        if (index == -1) {
            beginRemoveRows(QModelIndex(), i, i);
            d->contents.removeAt(i--);
            endRemoveRows();
        } else {
            // We already have that item.
            newData.removeAt(index);
        }
    }

    if (newData.isEmpty()) {
        return;
    }

    // Append new items.
    beginInsertRows(QModelIndex(),
                    d->contents.size(), d->contents.size() + newData.size() - 1);
    foreach (const QString &filePath, newData) {
        QStringList info(CReporterUtils::parseCrashInfoFromFilename(filePath));

        PendingUploadsModelPrivate::Item item;
        item.applicationName = info[0];
        item.pid = info[3].toInt();
        item.signal = strsignal(info[2].toInt());
        item.filePath = filePath;
        item.dateCreated = QFileInfo(filePath).created();

        d->contents.append(item);
    }