mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
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:
commit
3a43fbfa61
@ -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);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
|
||||||
// copier/coller avec decalage
|
// ok ... there is something to do for us!
|
||||||
QRectF final_pasted_content_bounding_rect;
|
int initialOffsetX = 10 + (qRound((pasted_content_bounding_rect.width())/10) * 10);
|
||||||
++ 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_);
|
|
||||||
}
|
|
||||||
|
|
||||||
// on applique le decalage qui convient
|
// paste copied parts with offset
|
||||||
final_pasted_content_bounding_rect = applyMovement(
|
// copier/coller avec decalage
|
||||||
pasted_content_bounding_rect,
|
QRectF final_pasted_content_bounding_rect;
|
||||||
QETElementEditor::pasteOffset()
|
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_;
|
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));
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user