mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-21 16:50:53 +01:00
part text and part text field : use QPropertyUndoCommand instead of ChangePartCommand
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4070 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -17,10 +17,10 @@
|
||||
*/
|
||||
#include "parttext.h"
|
||||
#include "texteditor.h"
|
||||
#include "editorcommands.h"
|
||||
#include "elementprimitivedecorator.h"
|
||||
#include "elementscene.h"
|
||||
#include "qetapp.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@@ -35,16 +35,11 @@ PartText::PartText(QETElementEditor *editor, QGraphicsItem *parent, ElementScene
|
||||
decorator_(0)
|
||||
{
|
||||
Q_UNUSED(scene)
|
||||
#if QT_VERSION >= 0x040500
|
||||
document() -> setDocumentMargin(1.0);
|
||||
#endif
|
||||
setDefaultTextColor(Qt::black);
|
||||
setFont(QETApp::diagramTextsFont());
|
||||
real_font_size_ = font().pointSize();
|
||||
setFlags(QGraphicsItem::ItemIsSelectable);
|
||||
#if QT_VERSION >= 0x040600
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
#endif
|
||||
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
|
||||
setAcceptHoverEvents(true);
|
||||
setDefaultTextColor(Qt::black);
|
||||
setPlainText(QObject::tr("T", "default text when adding a text in the element editor"));
|
||||
@@ -432,29 +427,26 @@ void PartText::startEdition() {
|
||||
End text edition, potentially generating a ChangePartCommand if the text
|
||||
has changed.
|
||||
*/
|
||||
void PartText::endEdition() {
|
||||
if (!previous_text.isNull()) {
|
||||
// the text was being edited
|
||||
void PartText::endEdition()
|
||||
{
|
||||
if (!previous_text.isNull())
|
||||
{
|
||||
// the text was being edited
|
||||
QString new_text = toPlainText();
|
||||
if (previous_text != new_text) {
|
||||
// the text was changed
|
||||
ChangePartCommand *text_change = new ChangePartCommand(
|
||||
TextEditor::tr("contenu") + " " + name(),
|
||||
this,
|
||||
"text",
|
||||
previous_text,
|
||||
new_text
|
||||
);
|
||||
if (previous_text != new_text)
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "text", previous_text, new_text);
|
||||
undo->setText(tr("Modifier un champ texte"));
|
||||
undoStack().push(undo);
|
||||
previous_text = QString();
|
||||
undoStack().push(text_change);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// deselectionne le texte
|
||||
QTextCursor qtc = textCursor();
|
||||
qtc.clearSelection();
|
||||
setTextCursor(qtc);
|
||||
|
||||
|
||||
setEditable(false);
|
||||
if (decorator_) {
|
||||
decorator_ -> setFocus();
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
*/
|
||||
#include "parttextfield.h"
|
||||
#include "textfieldeditor.h"
|
||||
#include "editorcommands.h"
|
||||
#include "elementprimitivedecorator.h"
|
||||
#include "qetapp.h"
|
||||
#include "QPropertyUndoCommand/qpropertyundocommand.h"
|
||||
|
||||
/**
|
||||
Constructeur
|
||||
@@ -39,10 +39,7 @@ PartTextField::PartTextField(QETElementEditor *editor, QGraphicsItem *parent, QG
|
||||
setDefaultTextColor(Qt::black);
|
||||
setFont(QETApp::diagramTextsFont());
|
||||
real_font_size_ = font().pointSize();
|
||||
setFlags(QGraphicsItem::ItemIsSelectable);
|
||||
#if QT_VERSION >= 0x040600
|
||||
setFlag(QGraphicsItem::ItemSendsGeometryChanges, true);
|
||||
#endif
|
||||
setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
|
||||
setAcceptHoverEvents(true);
|
||||
setPlainText(QObject::tr("_", "default text when adding a textfield in the element editor"));
|
||||
|
||||
@@ -416,21 +413,18 @@ void PartTextField::startEdition() {
|
||||
End text edition, potentially generating a ChangePartCommand if the text
|
||||
has changed.
|
||||
*/
|
||||
void PartTextField::endEdition() {
|
||||
if (!previous_text.isNull()) {
|
||||
// the text was being edited
|
||||
void PartTextField::endEdition()
|
||||
{
|
||||
if (!previous_text.isNull())
|
||||
{
|
||||
// the text was being edited
|
||||
QString new_text = toPlainText();
|
||||
if (previous_text != new_text) {
|
||||
// the text was changed
|
||||
ChangePartCommand *text_change = new ChangePartCommand(
|
||||
TextFieldEditor::tr("contenu") + " " + name(),
|
||||
this,
|
||||
"text",
|
||||
previous_text,
|
||||
new_text
|
||||
);
|
||||
if (previous_text != new_text)
|
||||
{
|
||||
QPropertyUndoCommand *undo = new QPropertyUndoCommand(this, "text", previous_text, new_text);
|
||||
undo->setText(tr("Modifier un champ texte"));
|
||||
undoStack().push(undo);
|
||||
previous_text = QString();
|
||||
undoStack().push(text_change);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user