Merge pull request #351 from plc-user/master

FIX copy-and-paste in element-editor: set paste-position to meaningful values
This commit is contained in:
Laurent Trinques 2025-02-11 06:41:40 +01:00 committed by GitHub
commit 3a43fbfa61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 26 deletions

View File

@ -517,11 +517,11 @@ QRectF ElementScene::boundingRectFromXml(const QDomDocument &xml_document)
ElementContent loaded_content = loadContent(xml_document); ElementContent loaded_content = loadContent(xml_document);
if (loaded_content.isEmpty()) return(QRectF()); if (loaded_content.isEmpty()) return(QRectF());
// calcule the boundingRect // calculate the boundingRect
// calcule le boundingRect // calcule le boundingRect
QRectF bounding_rect = elementContentBoundingRect(loaded_content); QRectF bounding_rect = elementContentBoundingRect(loaded_content);
// destroy charged parties // destroy loaded parts
// detruit les parties chargees // detruit les parties chargees
qDeleteAll(loaded_content); qDeleteAll(loaded_content);

View File

@ -307,10 +307,12 @@ ElementContent ElementView::pasteAreaDefined(const QRectF &target_rect) {
@param pos Coin superieur gauche du rectangle cible @param pos Coin superieur gauche du rectangle cible
*/ */
ElementContent ElementView::paste(const QDomDocument &xml_document, const QPointF &pos) { 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 // objet pour recuperer le contenu ajoute au schema par le coller
ElementContent content_pasted; ElementContent content_pasted;
m_scene -> fromXml(xml_document, pos, false, &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 // si quelque chose a effectivement ete ajoute au schema, on cree un objet d'annulation
if (content_pasted.count()) { if (content_pasted.count()) {
m_scene -> clearSelection(); m_scene -> clearSelection();
@ -321,10 +323,12 @@ 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 Colle le document XML xml_document a la position pos
@param xml_document Document XML a coller @param xml_document Document XML a coller
*/ */
ElementContent ElementView::pasteWithOffset(const QDomDocument &xml_document) { 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 // objet pour recuperer le contenu ajoute au schema par le coller
ElementContent content_pasted; ElementContent content_pasted;
@ -332,32 +336,25 @@ ElementContent ElementView::pasteWithOffset(const QDomDocument &xml_document) {
QRectF pasted_content_bounding_rect = m_scene -> boundingRectFromXml(xml_document); QRectF pasted_content_bounding_rect = m_scene -> boundingRectFromXml(xml_document);
if (pasted_content_bounding_rect.isEmpty()) return(content_pasted); if (pasted_content_bounding_rect.isEmpty()) return(content_pasted);
// ok ... there is something to do for us!
int initialOffsetX = 10 + (qRound((pasted_content_bounding_rect.width())/10) * 10);
// paste copied parts with offset
// copier/coller avec decalage // copier/coller avec decalage
QRectF final_pasted_content_bounding_rect; QRectF final_pasted_content_bounding_rect;
++ offset_paste_count_; QPointF offset(initialOffsetX, 0);
if (!offset_paste_count_) { ++ offset_paste_count_; // == 0 when selection was cut to clipboard
// the pasted content was cut // place pasted parts right from copied selection or already pasted parts
start_top_left_corner_ = pasted_content_bounding_rect.topLeft(); offset.setX(initialOffsetX * offset_paste_count_);
final_pasted_content_bounding_rect = pasted_content_bounding_rect; offset.setY(0);
} final_pasted_content_bounding_rect = pasted_content_bounding_rect.translated(offset);
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_);
}
// on applique le decalage qui convient start_top_left_corner_ = pasted_content_bounding_rect.topLeft();
final_pasted_content_bounding_rect = applyMovement(
pasted_content_bounding_rect,
QETElementEditor::pasteOffset()
);
}
QPointF old_start_top_left_corner = start_top_left_corner_; QPointF old_start_top_left_corner = start_top_left_corner_;
start_top_left_corner_ = final_pasted_content_bounding_rect.topLeft(); start_top_left_corner_ = final_pasted_content_bounding_rect.topLeft();
m_scene -> fromXml(xml_document, start_top_left_corner_, false, &content_pasted); 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 // si quelque chose a effectivement ete ajoute au schema, on cree un objet d'annulation
if (content_pasted.count()) { if (content_pasted.count()) {
m_scene -> clearSelection(); m_scene -> clearSelection();
@ -591,10 +588,12 @@ void ElementView::drawBackground(QPainter *p, const QRectF &r) {
@return @return
*/ */
QRectF ElementView::applyMovement(const QRectF &start, const QPointF &offset) { 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 // calcule le decalage a appliquer a partir de l'offset
QPointF final_offset; QPointF final_offset;
final_offset.rx() = start.width() + offset.x(); final_offset.rx() = start.width() + offset.x();
// applies the calculated offset
// applique le decalage ainsi calcule // applique le decalage ainsi calcule
return(start.translated(final_offset)); return(start.translated(final_offset));
} }

View File

@ -274,7 +274,7 @@ void QetGraphicsTableItem::paint(
offset += m_header_item->sectionSize(i); 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(); auto row_count = m_model->rowCount();
if (m_previous_table) //Remove the number of row already displayed by previous tables if (m_previous_table) //Remove the number of row already displayed by previous tables
@ -516,7 +516,7 @@ int QetGraphicsTableItem::displayedRowCount() const
return 0; return 0;
} }
//Calcule the number of rows to display. //calculate the number of rows to display.
auto row_count = m_model->rowCount(); auto row_count = m_model->rowCount();
if (m_previous_table) //Remove the number of row already displayed by previous tables if (m_previous_table) //Remove the number of row already displayed by previous tables
@ -858,7 +858,7 @@ void QetGraphicsTableItem::modelReseted()
/** /**
@brief QetGraphicsTableItem::setUpColumnAndRowMinimumSize @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. this function doesn't change the geometry of the table.
*/ */
void QetGraphicsTableItem::setUpColumnAndRowMinimumSize() void QetGraphicsTableItem::setUpColumnAndRowMinimumSize()