void Datapicker::addNewPoint(const QPointF& pos, AbstractAspect* parentAspect) { QList<DatapickerPoint*> childPoints = parentAspect->children<DatapickerPoint>(AbstractAspect::IncludeHidden); if (childPoints.isEmpty()) beginMacro(i18n("%1: add new point", parentAspect->name())); else beginMacro(i18n("%1: add new point %2", parentAspect->name(), childPoints.count())); DatapickerPoint* newPoint = new DatapickerPoint(i18n("%1 Point", parentAspect->name())); newPoint->setPosition(pos); newPoint->setHidden(true); parentAspect->addChild(newPoint); newPoint->retransform(); DatapickerCurve* datapickerCurve = dynamic_cast<DatapickerCurve*>(parentAspect); if (m_image == parentAspect) { DatapickerImage::ReferencePoints points = m_image->axisPoints(); points.scenePos[childPoints.count()].setX(pos.x()); points.scenePos[childPoints.count()].setY(pos.y()); m_image->setAxisPoints(points); } else if (datapickerCurve) { newPoint->initErrorBar(datapickerCurve->curveErrorTypes()); datapickerCurve->updateData(newPoint); } endMacro(); emit requestUpdateActions(); }
void TextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { QGraphicsItem::mouseReleaseEvent(event); if (isSelected() && (flags() & QGraphicsItem::ItemIsMovable) && positionChanged) { InsertData insertData = meta.value(); qreal topLeft[2] = { sceneBoundingRect().left(), sceneBoundingRect().top() }; qreal size[2] = { sceneBoundingRect().width(), sceneBoundingRect().height() }; PlacementData pld; pld.placement = TopLeft; pld.justification = Center; pld.relativeTo = PageType; pld.preposition = Inside; calcOffsets(pld,insertData.offsets,topLeft,size); QStringList list = toPlainText().split("\n"); insertData.text = list.join("\\n"); meta.setValue(insertData); beginMacro(QString("MoveText")); changeInsertOffset(&meta); endMacro(); } }
void DatapickerImage::setFileName(const QString& fileName) { if (fileName!= d->fileName) { beginMacro(i18n("%1: upload new image", name())); exec(new DatapickerImageSetFileNameCmd(d, fileName, i18n("%1: upload image"))); endMacro(); } }
void AbstractAspect::removeAllChildAspects() { beginMacro(tr("%1: remove all children.").arg(name())); for (int i=childCount()-1; i >= 0; i--) removeChild(i); endMacro(); }
void AbstractAspect::removeChild(AbstractAspect* child, bool detach) { Q_ASSERT(indexOfChild(child) != -1); beginMacro(tr("%1: remove %2.").arg(name()).arg(child->name())); prepareAspectRemoval(child); exec(new AspectChildRemoveCmd(d_aspect_private, child, detach)); endMacro(); }
//############################################################################## //###### SLOTs for changes triggered via QActions in the context menu ######## //############################################################################## void DatapickerCurve::updateDatasheet() { beginMacro(i18n("%1: update datasheet", name())); foreach (DatapickerPoint* point, children<DatapickerPoint>(IncludeHidden)) updateData(point); endMacro(); }
void WorksheetElementContainer::setVisible(bool on){ Q_D(WorksheetElementContainer); //take care of proper ordering on the undo-stack, //when making the container and all its children visible/invisible. //if visible is set true, change the visibility of the container first if (on) { beginMacro( i18n("%1: set visible", name()) ); exec( new WorksheetElementContainerSetVisibleCmd(d, on, i18n("%1: set visible")) ); } else { beginMacro( i18n("%1: set invisible", name()) ); } //change the visibility of all children QList<WorksheetElement *> childList = children<WorksheetElement>(AbstractAspect::IncludeHidden | AbstractAspect::Compress); foreach(WorksheetElement *elem, childList){ elem->setVisible(on); }
void UndoStack::overwrite(qint64 pos, int len, const QByteArray &ba) { if ((pos >= 0) && (pos < _chunks->size())) { QString txt = QString(tr("Overwrite %1 chars")).arg(len); beginMacro(txt); removeAt(pos, len); insert(pos, ba); endMacro(); } }
void UndoStack::insert(qint64 pos, const QByteArray &ba) { if ((pos >= 0) && (pos <= _chunks->size())) { QString txt = QString(tr("Inserting %1 bytes")).arg(ba.size()); beginMacro(txt); for (int idx=0; idx < ba.size(); idx++) { QUndoCommand *cc = new CharCommand(_chunks, CharCommand::insert, pos + idx, ba.at(idx)); this->push(cc); } endMacro(); } }
void AbstractAspect::addChild(AbstractAspect* child) { Q_CHECK_PTR(child); QString new_name = d_aspect_private->uniqueNameFor(child->name()); beginMacro(tr("%1: add %2.").arg(name()).arg(new_name)); if (new_name != child->name()) { info(tr("Renaming \"%1\" to \"%2\" in order to avoid name collision.").arg(child->name()).arg(new_name)); child->setName(new_name); } exec(new AspectChildAddCmd(d_aspect_private, child, d_aspect_private->childCount())); completeAspectInsertion(child, d_aspect_private->childCount()-1); endMacro(); }
void AbstractAspect::insertChild(AbstractAspect* child, int index) { Q_CHECK_PTR(child); QString new_name = d_aspect_private->uniqueNameFor(child->name()); beginMacro(tr("%1: insert %2 at position %3.").arg(name()).arg(new_name).arg(index+1)); if (new_name != child->name()) { info(tr("Renaming \"%1\" to \"%2\" in order to avoid name collision.").arg(child->name()).arg(new_name)); child->setName(new_name); } exec(new AspectChildAddCmd(d_aspect_private, child, index)); completeAspectInsertion(child, index); endMacro(); }
void TextItem::focusOutEvent(QFocusEvent *event) { QGraphicsTextItem::focusOutEvent(event); // change meta if (textChanged) { InsertData insertData = meta.value(); QStringList list = toPlainText().split("\n"); insertData.text = list.join("\\n"); meta.setValue(insertData); beginMacro(QString("Edit")); changeInsertOffset(&meta); endMacro(); } }
void AbstractAspect::reparentChild(AbstractAspect *new_parent, AbstractAspect *child, int new_index) { Q_ASSERT(indexOfChild(child) != -1); Q_ASSERT(new_index > 0 && new_index <= new_parent->childCount()); Q_ASSERT(new_parent != NULL); QString new_name = new_parent->d_aspect_private->uniqueNameFor(child->name()); beginMacro(tr("%1: move %2 to %3.").arg(name()).arg(child->name()).arg(new_parent->name())); if (new_name != child->name()) { info(tr("Renaming \"%1\" to \"%2\" in order to avoid name collision.").arg(child->name()).arg(new_name)); child->setName(new_name); } prepareAspectRemoval(child); exec(new AspectChildReparentCmd(d_aspect_private, new_parent->d_aspect_private, child, new_index)); new_parent->completeAspectInsertion(child, new_index); endMacro(); }
void UndoStack::removeAt(qint64 pos, qint64 len) { if ((pos >= 0) && (pos < _chunks->size())) { if (len==1) { QUndoCommand *cc = new CharCommand(_chunks, CharCommand::removeAt, pos, char(0)); this->push(cc); } else { QString txt = QString(tr("Delete %1 chars")).arg(len); beginMacro(txt); for (qint64 cnt=0; cnt<len; cnt++) { QUndoCommand *cc = new CharCommand(_chunks, CharCommand::removeAt, pos, char(0)); push(cc); } endMacro(); } } }
/** * \brief Set the column mode * * This sets the column mode and, if * necessary, converts it to another datatype. */ void Column::setColumnMode(AbstractColumn::ColumnMode mode) { if(mode == columnMode()) return; beginMacro(i18n("%1: change column type", name())); AbstractSimpleFilter * old_input_filter = m_column_private->inputFilter(); AbstractSimpleFilter * old_output_filter = m_column_private->outputFilter(); exec(new ColumnSetModeCmd(m_column_private, mode)); if (m_column_private->inputFilter() != old_input_filter) { removeChild(old_input_filter); addChild(m_column_private->inputFilter()); m_column_private->inputFilter()->input(0,m_string_io); } if (m_column_private->outputFilter() != old_output_filter) { removeChild(old_output_filter); addChild(m_column_private->outputFilter()); m_column_private->outputFilter()->input(0, this); } endMacro(); }
void DatapickerImage::setPlotPointsType(const PointsType pointsType) { d->plotPointsType = pointsType; if (pointsType == DatapickerImage::AxisPoints) { //clear image int childCount = this->childCount<DatapickerPoint>(AbstractAspect::IncludeHidden); if (childCount) { beginMacro(i18n("%1: remove all axis points", name())); QList<DatapickerPoint*> childrenPoints = children<DatapickerPoint>(AbstractAspect::IncludeHidden); foreach(DatapickerPoint* point, childrenPoints) point->remove(); endMacro(); } m_segments->setSegmentsVisible(false); } else if (pointsType==DatapickerImage::CurvePoints) { m_segments->setSegmentsVisible(false); } else if (pointsType==DatapickerImage::SegmentPoints) { d->makeSegments(); m_segments->setSegmentsVisible(true); } }
void DatapickerCurve::setCurveErrorTypes(const DatapickerCurve::Errors errors) { Q_D(DatapickerCurve); if (d->curveErrorTypes.x != errors.x || d->curveErrorTypes.y != errors.y) { beginMacro(i18n("%1: set xy-error type", name())); exec(new DatapickerCurveSetCurveErrorTypesCmd(d, errors, i18n("%1: set xy-error type"))); if ( errors.x != NoError && !d->plusDeltaXColumn ) { setPlusDeltaXColumn(appendColumn(i18n("+delta_x"))); } else if ( d->plusDeltaXColumn && errors.x == NoError ) { d->plusDeltaXColumn->remove(); d->plusDeltaXColumn = 0; } if ( errors.x == AsymmetricError && !d->minusDeltaXColumn ) { setMinusDeltaXColumn(appendColumn(i18n("-delta_x"))); } else if ( d->minusDeltaXColumn && errors.x != AsymmetricError ) { d->minusDeltaXColumn->remove(); d->minusDeltaXColumn = 0; } if ( errors.y != NoError && !d->plusDeltaYColumn ) { setPlusDeltaYColumn(appendColumn(i18n("+delta_y"))); } else if ( d->plusDeltaYColumn && errors.y == NoError ) { d->plusDeltaYColumn->remove(); d->plusDeltaYColumn = 0; } if ( errors.y == AsymmetricError && !d->minusDeltaYColumn ) { setMinusDeltaYColumn(appendColumn(i18n("-delta_y"))); } else if ( d->minusDeltaYColumn && errors.y != AsymmetricError ) { d->minusDeltaYColumn->remove(); d->minusDeltaYColumn = 0; } endMacro(); } }
void UndoManager::push(QUndoCommand *cmd, int affectedSystem) { beginMacro(cmd->actionText()); auto onUndo = new SignalOnUndo(); if (affectedSystem >= 0) { connect(onUndo, &SignalOnUndo::triggered, [=]() { onSystemChanged(affectedSystem); }); } else { connect(onUndo, &SignalOnUndo::triggered, this, &UndoManager::fullRedrawNeeded); } push(onUndo); push(cmd); auto onRedo = new SignalOnRedo(); if (affectedSystem >= 0) { connect(onRedo, &SignalOnRedo::triggered, [=]() { onSystemChanged(affectedSystem); }); } else { connect(onRedo, &SignalOnRedo::triggered, this, &UndoManager::fullRedrawNeeded); } push(onRedo); endMacro(); }
void TextItem::contextMenuEvent( QGraphicsSceneContextMenuEvent *event) { QMenu menu; QAction *editFontAction = menu.addAction("Edit Font"); editFontAction->setWhatsThis("Edit this text's font"); QAction *editColorAction = menu.addAction("Edit Color"); editColorAction->setWhatsThis("Edit this text's color"); QAction *deleteTextAction = menu.addAction("Delete This Text"); deleteTextAction->setWhatsThis("Delete this text"); QAction *selectedAction = menu.exec(event->screenPos()); if (selectedAction == NULL) { return; } if (selectedAction == editFontAction) { InsertData data = meta.value(); QFont font(data.textFont); bool ok; font = QFontDialog::getFont(&ok,font); if (ok) { data.textFont = font.toString(); meta.setValue(data); beginMacro("UpdateFont"); replaceMeta(meta.here(),meta.format(false,false)); endMacro(); } else { gui->displayPage(); } } else if (selectedAction == editColorAction) { InsertData data = meta.value(); QColor color(data.textColor); color = QColorDialog::getColor(color); data.textColor = color.name(); meta.setValue(data); beginMacro("UpdateColor"); replaceMeta(meta.here(),meta.format(false,false)); endMacro(); } else if (selectedAction == deleteTextAction) { Where here = meta.here(); beginMacro("DeleteText"); deleteMeta(here); endMacro(); } }