void AnnotationState::deleteAnnotation(int id) { int idx = findById(id); if(idx<0) { qWarning("Cannot remove annotation: ID %d not found!", id); return; } m_annotations.removeAt(idx); emit annotationDeleted(id); }
/** * This prepares the canvas for new drawing commands. * @param myid the context id of the local user */ void CanvasScene::initCanvas(net::Client *client) { delete _image; delete _statetracker; _image = new CanvasItem(); _statetracker = new StateTracker(_image->image(), client->layerlist(), client->myId(), this); connect(_statetracker, &StateTracker::myAnnotationCreated, [this](int id) { emit myAnnotationCreated(getAnnotationItem(id)); }); connect(_statetracker, SIGNAL(layerAutoselectRequest(int)), this, SIGNAL(layerAutoselectRequest(int))); connect(_statetracker, SIGNAL(userMarkerAttribs(int,QColor,QString)), this, SLOT(setUserMarkerAttribs(int,QColor,QString))); connect(_statetracker, SIGNAL(userMarkerMove(int,QPointF,int)), this, SLOT(moveUserMarker(int,QPointF,int))); connect(_statetracker, SIGNAL(userMarkerHide(int)), this, SLOT(hideUserMarker(int))); connect(_image->image(), SIGNAL(resized(int,int,QSize)), this, SLOT(handleCanvasResize(int,int,QSize))); connect(_image->image(), SIGNAL(annotationChanged(int)), this, SLOT(handleAnnotationChange(int))); connect(client, SIGNAL(layerVisibilityChange(int,bool)), _image->image(), SLOT(setLayerHidden(int,bool))); addItem(_image); // Clear out any old annotation items foreach(QGraphicsItem *item, items()) { if(item->type() == AnnotationItem::Type) { emit annotationDeleted(static_cast<AnnotationItem*>(item)->id()); delete item; } } foreach(UserMarkerItem *i, _usermarkers) delete i; _usermarkers.clear(); QList<QRectF> regions; regions.append(sceneRect()); emit canvasInitialized(); emit changed(regions); }