Skip to content

Commit

Permalink
Merge pull request #351 from plc-user/master
Browse files Browse the repository at this point in the history
FIX copy-and-paste in element-editor: set paste-position to meaningful values
  • Loading branch information
scorpio810 authored Feb 11, 2025
2 parents 610f4d6 + 29aee8e commit 3a43fbf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
4 changes: 2 additions & 2 deletions sources/editor/elementscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,11 +517,11 @@ QRectF ElementScene::boundingRectFromXml(const QDomDocument &xml_document)
ElementContent loaded_content = loadContent(xml_document);
if (loaded_content.isEmpty()) return(QRectF());

// calcule the boundingRect
// calculate the boundingRect
// calcule le boundingRect
QRectF bounding_rect = elementContentBoundingRect(loaded_content);

// destroy charged parties
// destroy loaded parts
// detruit les parties chargees
qDeleteAll(loaded_content);

Expand Down
41 changes: 20 additions & 21 deletions sources/editor/elementview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,12 @@ ElementContent ElementView::pasteAreaDefined(const QRectF &target_rect) {
@param pos Coin superieur gauche du rectangle cible
*/
ElementContent ElementView::paste(const QDomDocument &xml_document, const QPointF &pos) {
// object to retrieve content added to the scheme by pasting
// objet pour recuperer le contenu ajoute au schema par le coller
ElementContent content_pasted;
m_scene -> fromXml(xml_document, pos, false, &content_pasted);

// if something has actually been added to the scheme, an undo object is created
// si quelque chose a effectivement ete ajoute au schema, on cree un objet d'annulation
if (content_pasted.count()) {
m_scene -> clearSelection();
Expand All @@ -321,43 +323,38 @@ ElementContent ElementView::paste(const QDomDocument &xml_document, const QPoint
}

/**
Paste the XML document "xml_document" at position pos
Colle le document XML xml_document a la position pos
@param xml_document Document XML a coller
*/
ElementContent ElementView::pasteWithOffset(const QDomDocument &xml_document) {
// object to retrieve content added to the scheme by pasting
// objet pour recuperer le contenu ajoute au schema par le coller
ElementContent content_pasted;

// rectangle source
QRectF pasted_content_bounding_rect = m_scene -> boundingRectFromXml(xml_document);
if (pasted_content_bounding_rect.isEmpty()) return(content_pasted);

// copier/coller avec decalage
QRectF final_pasted_content_bounding_rect;
++ offset_paste_count_;
if (!offset_paste_count_) {
// the pasted content was cut
start_top_left_corner_ = pasted_content_bounding_rect.topLeft();
final_pasted_content_bounding_rect = pasted_content_bounding_rect;
}
else {
// the pasted content was copied
if (offset_paste_count_ == 1) {
start_top_left_corner_ = pasted_content_bounding_rect.topLeft();
} else {
pasted_content_bounding_rect.moveTopLeft(start_top_left_corner_);
}
// ok ... there is something to do for us!
int initialOffsetX = 10 + (qRound((pasted_content_bounding_rect.width())/10) * 10);

// on applique le decalage qui convient
final_pasted_content_bounding_rect = applyMovement(
pasted_content_bounding_rect,
QETElementEditor::pasteOffset()
);
}
// paste copied parts with offset
// copier/coller avec decalage
QRectF final_pasted_content_bounding_rect;
QPointF offset(initialOffsetX, 0);
++ offset_paste_count_; // == 0 when selection was cut to clipboard
// place pasted parts right from copied selection or already pasted parts
offset.setX(initialOffsetX * offset_paste_count_);
offset.setY(0);
final_pasted_content_bounding_rect = pasted_content_bounding_rect.translated(offset);

start_top_left_corner_ = pasted_content_bounding_rect.topLeft();
QPointF old_start_top_left_corner = start_top_left_corner_;
start_top_left_corner_ = final_pasted_content_bounding_rect.topLeft();
m_scene -> fromXml(xml_document, start_top_left_corner_, false, &content_pasted);

// if something has actually been added to the scheme, a cancel object is created
// si quelque chose a effectivement ete ajoute au schema, on cree un objet d'annulation
if (content_pasted.count()) {
m_scene -> clearSelection();
Expand Down Expand Up @@ -591,10 +588,12 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) {
@return
*/
QRectF ElementView::applyMovement(const QRectF &start, const QPointF &offset) {
// calculates the offset to be applied from the offset
// calcule le decalage a appliquer a partir de l'offset
QPointF final_offset;
final_offset.rx() = start.width() + offset.x();

// applies the calculated offset
// applique le decalage ainsi calcule
return(start.translated(final_offset));
}
6 changes: 3 additions & 3 deletions sources/qetgraphicsitem/ViewItem/qetgraphicstableitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ void QetGraphicsTableItem::paint(
offset += m_header_item->sectionSize(i);
}

//Calcule the number of rows to display.
//calculate the number of rows to display.
auto row_count = m_model->rowCount();

if (m_previous_table) //Remove the number of row already displayed by previous tables
Expand Down Expand Up @@ -516,7 +516,7 @@ int QetGraphicsTableItem::displayedRowCount() const
return 0;
}

//Calcule the number of rows to display.
//calculate the number of rows to display.
auto row_count = m_model->rowCount();

if (m_previous_table) //Remove the number of row already displayed by previous tables
Expand Down Expand Up @@ -858,7 +858,7 @@ void QetGraphicsTableItem::modelReseted()

/**
@brief QetGraphicsTableItem::setUpColumnAndRowMinimumSize
Calcule the minimum row height and the minimum column width for each columns
Calculate the minimum row height and the minimum column width for each columns
this function doesn't change the geometry of the table.
*/
void QetGraphicsTableItem::setUpColumnAndRowMinimumSize()
Expand Down

0 comments on commit 3a43fbf

Please sign in to comment.