예제 #1
0
// private slot
void FilesWidget::removeDocument(Document *document)
{
    Q_ASSERT(document != NULL);

    disconnect(document, &Document::modificationChanged, this, &FilesWidget::updateModificationMarkerOfSender);
    disconnect(document, &Document::locationChanged, this, &FilesWidget::updateLocationOfSender);

    QStandardItem *child = m_children.value(document, NULL);

    Q_ASSERT(child != NULL);
    Q_ASSERT(child != m_currentChild);

    QStandardItem *parent = child->parent();

    Q_ASSERT(parent != NULL);

    parent->removeRow(child->row());

    if (parent->rowCount() > 0) {
        updateParentItemMarkers(parent);
    } else {
        m_model.removeRow(parent->row());
    }

    m_children.remove(document);

    if (m_currentChild != NULL) {
        m_treeFiles->selectionModel()->select(m_currentChild->index(), QItemSelectionModel::ClearAndSelect);
    }
}
예제 #2
0
void ItemViewWidget::removeRow()
{
	if (!m_model)
	{
		return;
	}

	const int row = currentIndex().row();
	QStandardItem *parent = m_model->itemFromIndex(currentIndex().parent());

	if (row >= 0)
	{
		if (parent)
		{
			parent->removeRow(row);
		}
		else
		{
			m_model->removeRow(row);
		}

		m_isModified = true;

		emit modified();
	}
}
예제 #3
0
   void PropertyTree::removeItem(ItemID id)
   {
      QStandardItem * parent = id->parent();
      // due to a Qt Bug or (feature?!) parent is null when it should be invisibleRootItem
      if ( ! parent )
         parent = model_->invisibleRootItem();

      parent->removeRow(id->row() );
   }
예제 #4
0
void PlaylistListContainer::RemovePlaylist(int id) {
  QStandardItem* item = model_->PlaylistById(id);
  if (item) {
    QStandardItem* parent = item->parent();
    if (!parent) {
      parent = model_->invisibleRootItem();
    }
    parent->removeRow(item->row());
  }
}
예제 #5
0
bool DebuggerItemModel::removeDebuggerStandardItem(const QVariant &id)
{
    QStandardItem *sitem = findStandardItemById(id);
    QTC_ASSERT(sitem, return false);
    QStandardItem *parent = sitem->parent();
    QTC_ASSERT(parent, return false);
    // This will trigger a change of m_currentDebugger via changing the
    // view selection.
    parent->removeRow(sitem->row());
    return true;
}
예제 #6
0
void CSceneExplorer::removeStandardItem(QStandardItem *item)
{
	QStandardItem *parent;

	if(item)
	{
		parent = item->parent();

		if(parent)
		{
			parent->removeRow(item->row());
		}
	}
}
void AbstractCameraManager::removeGroup(QModelIndex index) {
    QStandardItem * item = getModel()->itemFromIndex( index );
    if( !item->isEditable() ) return;

    QStandardItem * parent = item->parent();
    if( parent == NULL ) parent = item->model()->invisibleRootItem();

    for(int i=item->rowCount(); i>0; i--) {
        newCameraList.insertRow(0, item->takeRow(0));
    }

    parent->removeRow( item->row() );
    detectNewCamerasAndExpand();
}
예제 #8
0
void EngineExplorer::dataUpdated(const QString& source, const Plasma::DataEngine::Data& data)
{
    QList<QStandardItem*> items = m_dataModel->findItems(source, 0);

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

    QStandardItem* parent = items.first();

    int rows = showData(parent, data);

    while (parent->rowCount() > rows) {
        parent->removeRow(rows);
    }
}
예제 #9
0
	void RoomConfigWidget::on_ModifyPerm__released ()
	{
		QStandardItem *stdItem = GetCurrentItem ();
		if (!stdItem)
			return;

		QStandardItem *parent = stdItem->parent ();
		if (!Aff2Cat_.values ().contains (parent))
		{
			qWarning () << Q_FUNC_INFO
					<< "bad parent"
					<< parent
					<< "for"
					<< stdItem;
			return;
		}

		const QXmppMucItem::Affiliation aff = Aff2Cat_.key (parent);
		const QString& jid = stdItem->text ();

		std::unique_ptr<AffiliationSelectorDialog> dia (new AffiliationSelectorDialog (this));
		dia->SetJID (jid);
		dia->SetAffiliation (aff);
		dia->SetReason (stdItem->data (ItemRoles::Reason).toString ());
		if (dia->exec () != QDialog::Accepted)
			return;

		const QString& newJid = dia->GetJID ();
		if (newJid.isEmpty ())
			return;

		parent->removeRow (stdItem->row ());

		QXmppMucItem item;
		item.setJid (newJid);
		item.setAffiliation (dia->GetAffiliation ());
		item.setReason (dia->GetReason ());
		SendItem (item);

		if (item.affiliation () != QXmppMucItem::NoAffiliation)
			handlePermsReceived ({ item });
	}
void DayAvailabilityModel::removeAvailability(const QModelIndex &index)
{
    if (d->m_UserCalendar) {
        if (index.parent()==QModelIndex()) {
            // delete all availabilities for a specific weekDay
            QStandardItem *item = itemFromIndex(index);
            int weekDay = item->data(WeekDayRole).toInt();
            d->m_UserCalendar->removeAvailabilitiesForWeekDay(weekDay);
            invisibleRootItem()->removeRow(index.row());
        } else {
            // delete a specific time range
            QStandardItem *parent = itemFromIndex(index.parent());
            int weekDay = parent->data(WeekDayRole).toInt();
            const QTime &from = itemFromIndex(index)->data(HourFromRole).toTime();
            const QTime &to = itemFromIndex(index)->data(HourToRole).toTime();
            d->m_UserCalendar->removeAvailabilitiesTimeRange(weekDay, from, to);
            parent->removeRow(index.row());
        }
    }
}
예제 #11
0
	void RoomConfigWidget::on_RemovePerm__released ()
	{
		QStandardItem *stdItem = GetCurrentItem ();
		if (!stdItem)
			return;

		const QString& jid = stdItem->text ();
		if (jid.isEmpty ())
			return;

		QStandardItem *parent = stdItem->parent ();
		if (!parent)
			return;

		parent->removeRow (stdItem->row ());

		QXmppMucItem item;
		item.setJid (jid);
		item.setAffiliation (QXmppMucItem::NoAffiliation);
		SendItem (item);
	}
void CookiesContentsWidget::removeCookie(const QNetworkCookie &cookie)
{
	const QString domain = (cookie.domain().startsWith('.') ? cookie.domain().mid(1) : cookie.domain());
	QStandardItem *domainItem = findDomain(domain);

	if (domainItem)
	{
		QPoint point;

		for (int j = 0; j < domainItem->rowCount(); ++j)
		{
			if (domainItem->child(j, 0)->text() == cookie.name() && domainItem->child(j, 0)->data(Qt::UserRole).toString() == cookie.path())
			{
				point = m_ui->cookiesView->visualRect(domainItem->child(j, 0)->index()).center();

				domainItem->removeRow(j);

				break;
			}
		}

		if (domainItem->rowCount() == 0)
		{
			m_model->invisibleRootItem()->removeRow(domainItem->row());
		}
		else
		{
			domainItem->setText(QStringLiteral("%1 (%2)").arg(domain).arg(domainItem->rowCount()));
		}

		if (!point.isNull())
		{
			const QModelIndex index = m_ui->cookiesView->indexAt(point);

			m_ui->cookiesView->setCurrentIndex(index);
			m_ui->cookiesView->selectionModel()->select(index, QItemSelectionModel::Select);
		}
	}
}
예제 #13
0
void Project::removeFile(const QString &fileName)
{
    if (fileName.isEmpty())
        return;
    if (!_files.contains(fileName)) {
        qDebug() << "Internal error: file " << fileName << " not in project";
        return;
    }
    setModified(true, true);
    QModelIndex index = _files[fileName];
    _files.remove(fileName);
    QStandardItem* cur = itemFromIndex(index);
    while (cur->parent() != NULL && cur->parent() != invisibleRootItem() && !cur->hasChildren()) {
        int row = cur->row();
        cur = cur->parent();
        cur->removeRow(row);
    }
    QFileInfo fi(fileName);
    if (fi.fileName()=="_coursera") {
        delete _courseraProject;
        _courseraProject = NULL;
        ui->actionSubmit_to_Coursera->setVisible(false);
    }
}
void DayAvailabilityModel::addAvailability(const DayAvailability &availability)
{
    Q_ASSERT(d->m_UserCalendar);
    Q_ASSERT(IN_RANGE(availability.weekDay(), Qt::Monday, Qt::Sunday));

    d->m_UserCalendar->addAvailabilities(availability);

    // find the day item
    QStandardItem *dayItem = 0;
    for(int i = 0; i < invisibleRootItem()->rowCount(); ++i) {
        if (invisibleRootItem()->child(i)->data(WeekDayRole).toInt() == availability.weekDay()) {
            dayItem = invisibleRootItem()->child(i);
            break;
        }
    }

    // at this point there MUST be a valid dayItem. If not, something really bad happened.
    Q_ASSERT(dayItem);

    // delete the placeholder item, if exists
    if (dayItem->hasChildren() && dayItem->child(0)->data(AvailIdRole).toInt() == -1)
        dayItem->removeRow(0);

    // Insert the TimeRanges
    for(int i = 0; i < availability.timeRangeCount(); ++i) {
        TimeRange range = availability.timeRangeAt(i);
        QStandardItem *timeItem = new QStandardItem(tkTr(Trans::Constants::FROM_1_TO_2).arg(range.from.toString()).arg(range.to.toString()));
        timeItem->setData(availability.weekDay(), WeekDayRole);
        timeItem->setData(range.from, HourFromRole);
        timeItem->setData(range.to, HourToRole);
        timeItem->setToolTip(timeItem->text());
        dayItem->appendRow(timeItem);
    }
    dayItem->sortChildren(0);

}
예제 #15
0
void Sidebar::removeCategorie(SidebarChildCategorie *categorie)
{
    QStandardItem *parentItem = categorie->QStandardItem::parent();
    parentItem->removeRow(categorie->row());
}
예제 #16
0
		foreach(QStandardItem * item, mItemsToBeRemoved)
		{
			QStandardItem *  pitem = item->parent();
			Q_ASSERT(pitem);
			pitem->removeRow(item->index().row());
		}
예제 #17
0
void FileOrganiserWidget::moveItem(QStandardItem *pItem,
                                   QStandardItem *pDropItem,
                                   const QAbstractItemView::DropIndicatorPosition &pDropPosition)
{
    if (!pDropItem)
        // pDropItem is not valid, so...

        return;

    // Move pItem above/on/below pDropItem, depending on the drop position, but
    // first, determine the item that will own pItem

    QStandardItem *crtParentItem = pItem->parent()?
                                       pItem->parent():
                                       mModel->invisibleRootItem();
    QStandardItem *newParentItem = parentItem(pDropItem, pDropPosition);

    // Second, check whether the (file) item points to a file which is already
    // owned by newParentItem

    bool fileAlreadyOwned = false;

    if (!pItem->data(Item::Folder).toBool())
        // The current item is a file item, so retrieve its file name and check
        // whether it's already owned by newParentItem

        fileAlreadyOwned = ownedBy(pItem->data(Item::Path).toString(), newParentItem);

    // Third, move pItem to newParentItem and this to the right place, depending
    // on the value of pDropPosition and only if the destination doesn't already
    // have that item (should it be a file item, since folder items are always
    // moved)

    if (!fileAlreadyOwned || (crtParentItem == newParentItem)) {
        // Either newParentItem doesn't already own an item which points to the
        // same file as pItem or pItem's current parent is the same as
        // newParentItem in which case it means that we want to move the item
        // within its current location

        // First, check whether the item is a folder and, if so, whether it's
        // expanded (and the same with any (in)direct child folder it may
        // contain)

        backupExpandedInformation(pItem);

        // Second, move the item (and any of its children)

        dropItems(pDropItem, pDropPosition, newParentItem,
                  crtParentItem->takeRow(pItem->row()));

        // Third, re-expand folders, if necessary

        restoreExpandedInformation(pItem);

        // Fourth, resize the widget, just in case the new location of the
        // item(s) requires more space than is visible

        resizeToContents();
    } else {
        // A (file) item pointing to the same file is already owned by
        // newParentItem, so just remove the item rather than move it

        crtParentItem->removeRow(pItem->row());
    }
}
예제 #18
0
void Model::apply(std::shared_ptr<Core::MutationInfo> mutation) noexcept
{
	emit documentMutated(&mutation->prev, &mutation->cur);

	// Update the pointers stored in the model items
	using NodeOrProperty = eggs::variant<NodePtr, PropertyPtr>;
	std::unordered_map<NodeOrProperty, NodeOrProperty> mutated;
	auto updatePointers = [&](auto& changes)
	{
		for (auto&& mut: changes)
		{
			if (mut.type != ChangeType::Mutated) continue;

			findItem(mut.prev)->update(mut.cur);
			mutated.insert({ mut.prev, mut.cur });
		}
	};
	updatePointers(mutation->nodes);
	updatePointers(mutation->properties);

	auto resolve = [&](auto item) -> decltype(item)
	{
		if (!item) return item;

		auto it = mutated.find(item);
#ifdef _MSC_VER
		if (it != cend(mutated)) return *it->second.target<decltype(item)>();
#else
		if (it != cend(mutated)) return *it->second.template target<decltype(item)>();
#endif
		return item;
	};

	enum class RowType { Node, Property };

	auto setRow = [&](QStandardItem* parent, size_t row, QList<QStandardItem*> items, RowType rowType)
	{
		if (rowType == RowType::Property)
		{
			// Properties are indexed from 0, but they should always go below the node children of the parent
			// So increase the row offset by the number of children the parent has
			row += mutation->cur.childCount(*ModelItem::node(parent));
		}

		// When inserting a new item, make sure we above any items that have a higher index in the actual document
		// If we are inserting a node, also make sure we stay above any properties
		auto maxRow = row;
		for (row = 0; row < maxRow; row++)
		{
			if (row == static_cast<size_t>(parent->rowCount())) break;

			auto child = parent->child(row);

			// Encountered a property, so stop
			if (rowType == RowType::Node && ModelItem::prop(child)) break;

			size_t index;

			// Encountered a property that has a higher index than this item, so stop
			auto prop = ModelItem::prop(child);
			if (prop)
			{
				auto propNode = mutation->cur.parent(*prop);
				// add node childCount because the properties start BELOW the child nodes
				index = mutation->cur.childIndex(*prop) + mutation->cur.childCount(*propNode);
				if (index > maxRow) break;
			}

			// Encountered a node that has a higher index than this item, so stop
			auto node = ModelItem::node(child);
			if (node)
			{
				index = mutation->cur.childIndex(*node);
				if (index > maxRow) break;
			}
		}

		//LOG->debug("row: {}, rowCount: {}", row, parent->rowCount());
		if (row <= static_cast<size_t>(parent->rowCount())) parent->insertRow(row, items);
		else parent->appendRow(items);
	};

	auto applyMutations = [&](auto& changes, RowType rowType, auto createItems, bool onlyRemove)
	{
		for (auto&& mut : changes)
		{
			QStandardItem* prevParentNode = findItem(resolve(mut.prevParent));
			if (!prevParentNode && rowType == RowType::Node) prevParentNode = invisibleRootItem();
			QStandardItem* curParentNode = findItem(resolve(mut.curParent));
			if (!curParentNode && rowType == RowType::Node) curParentNode = invisibleRootItem();

			switch (mut.type)
			{
			case ChangeType::Added:
			{
				if (onlyRemove) continue;
				LOG->debug("Adding at position {}: {}", mut.curIndex, *mut.cur);
				setRow(curParentNode, mut.curIndex, createItems(mut.cur), rowType);
				break;
			}
			case ChangeType::Removed:
			{
				if (!onlyRemove) continue;
				auto item = findItem(mut.prev);
				if (!item) continue; // maybe was already deleted when parent was removed
				auto childIndex = findChildIndex(prevParentNode, item);
				if (childIndex != -1) prevParentNode->removeRow(childIndex);
				LOG->debug("Removed at position {}: {}", childIndex, *mut.prev);
				break;
			}
			case ChangeType::Mutated:
			{
				if (onlyRemove) continue;
				assert(prevParentNode && curParentNode);

				LOG->debug("Mutating from position {} to position {}: {}", mut.prevIndex, mut.curIndex, *mut.cur);
				auto nodeOrProperty = resolve(mut.prev);
				auto item = findItem(nodeOrProperty);
				assert(item);
				auto prevIndex = findChildIndex(prevParentNode, item);
				assert(prevIndex != -1);

				if (prevIndex != mut.curIndex || prevParentNode != curParentNode)
				{
					// Move the row
					auto itemRowItems = prevParentNode->takeRow(prevIndex);
					setRow(curParentNode, mut.curIndex, itemRowItems, rowType);
				}

				break;
			}
			}
		}
	};

	auto createNodeItems = [&](NodePtr node)
	{
		QList<QStandardItem*> items;
		items << new ModelItem(this, node) << nullptr;
		return items;
	};
	auto createPropertyItems = [&](PropertyPtr prop)
	{
		QList<QStandardItem*> items;
		auto modelItem = new ModelItem(this, prop);
		items << modelItem << modelItem->propertyValueItem();
		return items;
	};

	applyMutations(mutation->nodes, RowType::Node, createNodeItems, false);
	applyMutations(mutation->properties, RowType::Property, createPropertyItems, false);
	applyMutations(mutation->nodes, RowType::Node, createNodeItems, true);
	applyMutations(mutation->properties, RowType::Property, createPropertyItems, true);
}