Beispiel #1
0
void TwoDModelScene::deleteSelectedItems()
{
	QStringList worldItemsToDelete;
	QList<QPair<model::RobotModel *, kitBase::robotModel::PortInfo>> sensorsToDelete;
	for (QGraphicsItem * const item : selectedItems()) {
		SensorItem * const sensor = dynamic_cast<SensorItem *>(item);
		items::WallItem * const wall = dynamic_cast<items::WallItem *>(item);
		items::ColorFieldItem * const colorField = dynamic_cast<items::ColorFieldItem *>(item);
		items::ImageItem * const image = dynamic_cast<items::ImageItem *>(item);

		if (sensor && !mSensorsReadOnly) {
			for (RobotItem * const robotItem : mRobots.values()) {
				const kitBase::robotModel::PortInfo port = robotItem->sensors().key(sensor);
				if (port.isValid()) {
					sensorsToDelete << qMakePair(&robotItem->robotModel(), port);
				}
			}
		} else if (wall && !mWorldReadOnly) {
			worldItemsToDelete << wall->id();
			mCurrentWall = nullptr;
		} else if (colorField && !mWorldReadOnly) {
			worldItemsToDelete << colorField->id();
			mCurrentLine = nullptr;
			mCurrentStylus = nullptr;
			mCurrentEllipse = nullptr;
			mCurrentRectangle = nullptr;
			mCurrentCurve = nullptr;
		} else if (image && !mWorldReadOnly) {
			mModel.worldModel().removeImage(image);
		}
	}

	deleteWithCommand(worldItemsToDelete, sensorsToDelete, {});
}
Beispiel #2
0
void TwoDModelScene::deleteItem(QGraphicsItem *item)
{
	if (!items().contains(item)) {
		return;
	}

	if (SensorItem * const sensor = dynamic_cast<SensorItem *>(item)) {
		for (RobotItem * const robotItem : mRobots.values()) {
			const kitBase::robotModel::PortInfo port = robotItem->sensors().key(sensor);
			if (port.isValid()) {
				deviceConfigurationChanged(robotItem->robotModel().info().robotId()
						, port, kitBase::robotModel::DeviceInfo(), Reason::userAction);
			}
		}
	} else if (items::WallItem * const wall = dynamic_cast<items::WallItem *>(item)) {
		mModel.worldModel().removeWall(wall);
		mCurrentWall = nullptr;
	} else if (items::ColorFieldItem *colorField = dynamic_cast<items::ColorFieldItem *>(item)) {
		mModel.worldModel().removeColorField(colorField);
		mCurrentLine = nullptr;
		mCurrentStylus = nullptr;
		mCurrentEllipse = nullptr;
	}
}