Diagram editor : add in the tree widget use to edit the property of dynamic text item, two news items for edit the X and Y pos of the text.

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5088 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-10-29 10:43:34 +00:00
parent 5bb0a3f0a3
commit 50fc46e162
4 changed files with 87 additions and 5 deletions

View File

@@ -120,6 +120,22 @@ void DynamicElementTextItemEditor::setCurrentText(DynamicElementTextItem *text)
m_tree_view->setCurrentIndex(index);
}
QUndoCommand *DynamicElementTextItemEditor::associatedUndo() const
{
QUndoCommand *parent_undo = new QUndoCommand(tr("Modifier un texte d'élément"));
for (DynamicElementTextItem *deti : m_element->dynamicTextItems())
m_model->undoForEditedText(deti, parent_undo);
if(parent_undo->childCount() >= 1)
{
if(parent_undo->childCount() >= 2)
parent_undo->setText(tr("Modifier %1 textes d'élément").arg(QString::number(parent_undo->childCount())));
return parent_undo;
}
else
return nullptr;
}
void DynamicElementTextItemEditor::dataEdited(DynamicElementTextItem *deti)
{
Q_UNUSED(deti)

View File

@@ -42,6 +42,7 @@ class DynamicElementTextItemEditor : public AbstractElementPropertiesEditorWidge
bool setLiveEdit(bool live_edit) override;
void apply() override;
void setCurrentText(DynamicElementTextItem *text);
QUndoCommand *associatedUndo() const override;
private:
void dataEdited(DynamicElementTextItem *deti);

View File

@@ -161,6 +161,34 @@ void DynamicElementTextModel::addText(DynamicElementTextItem *deti)
qsi_list << color << colora;
qsi->appendRow(qsi_list);
//X pos
QStandardItem *x_pos = new QStandardItem(tr("Position X"));
x_pos->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QStandardItem *x_pos_a = new QStandardItem;
x_pos_a->setData(deti->pos().x(), Qt::EditRole);
x_pos_a->setData(DynamicElementTextModel::pos, Qt::UserRole+1);
x_pos_a->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
qsi_list.clear();
qsi_list << x_pos << x_pos_a;
qsi->appendRow(qsi_list);
//Y pos
QStandardItem *y_pos = new QStandardItem(tr("Position Y"));
y_pos->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
QStandardItem *y_pos_a = new QStandardItem;
y_pos_a->setData(deti->pos().y(), Qt::EditRole);
y_pos_a->setData(DynamicElementTextModel::pos, Qt::UserRole+1);
y_pos_a->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
qsi_list.clear();
qsi_list << y_pos << y_pos_a;
qsi->appendRow(qsi_list);
qsi_list.clear();
QStandardItem *empty_qsi = new QStandardItem(0);
empty_qsi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
@@ -244,9 +272,14 @@ QModelIndex DynamicElementTextModel::indexFromText(DynamicElementTextItem *text)
* Each change made for @deti is append as a child of the returned QUndoCommand.
* In other word, if the returned QUndoCommand have no child, that mean there is no change.
*/
QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem *deti) const
QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem *deti, QUndoCommand *parent_undo) const
{
QUndoCommand *undo = new QUndoCommand(tr("Éditer un texte d'élément"));
QUndoCommand *undo = nullptr;
if(parent_undo)
undo = parent_undo;
else
undo = new QUndoCommand(tr("Éditer un texte d'élément"));
if (!m_texts_list.contains(deti))
return undo;
@@ -292,6 +325,12 @@ QUndoCommand *DynamicElementTextModel::undoForEditedText(DynamicElementTextItem
if(color != deti->color())
new QPropertyUndoCommand(deti, "color", QVariant(deti->color()), QVariant(color), undo);
QPointF p(text_qsi->child(4,1)->data(Qt::EditRole).toDouble(),
text_qsi->child(5,1)->data(Qt::EditRole).toDouble());
if(p != deti->pos())
new QPropertyUndoCommand(deti, "pos", QVariant(deti->pos()), QVariant(p), undo);
return undo;
}
@@ -381,7 +420,7 @@ void DynamicElementTextModel::itemDataChanged(QStandardItem *qsi)
//We emit the signal only if @qsi is in the second column, because the data are stored on this column
//the first column is use only for display the title of the property
if(qsi->column() == 1)
if(qsi->column() == 1 && !m_block_dataForTextChanged)
emit dataForTextChanged(deti);
}
@@ -406,6 +445,8 @@ void DynamicElementTextModel::setConnection(DynamicElementTextItem *deti, bool s
connection_list << connect(deti, &DynamicElementTextItem::textFromChanged, [deti,this](){this->updateDataFromText(deti, textFrom);});
connection_list << connect(deti, &DynamicElementTextItem::textChanged, [deti,this](){this->updateDataFromText(deti, userText);});
connection_list << connect(deti, &DynamicElementTextItem::infoNameChanged, [deti,this](){this->updateDataFromText(deti, infoText);});
connection_list << connect(deti, &DynamicElementTextItem::xChanged, [deti,this](){this->updateDataFromText(deti, pos);});
connection_list << connect(deti, &DynamicElementTextItem::yChanged, [deti,this](){this->updateDataFromText(deti, pos);});
connection_list << connect(deti, &DynamicElementTextItem::compositeTextChanged, [deti, this]() {this->updateDataFromText(deti, compositeText);});
m_hash_text_connect.insert(deti, connection_list);
@@ -428,6 +469,8 @@ void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, V
if (!qsi)
return;
m_block_dataForTextChanged = true;
switch (type)
{
case textFrom:
@@ -480,7 +523,15 @@ void DynamicElementTextModel::updateDataFromText(DynamicElementTextItem *deti, V
qsi->child(3,1)->setData(deti->color(), Qt::ForegroundRole);
break;
}
case pos:
{
qsi->child(4,1)->setData(deti->pos().x(), Qt::EditRole);
qsi->child(5,1)->setData(deti->pos().y(), Qt::EditRole);
break;
}
}
m_block_dataForTextChanged = false;
}
@@ -553,6 +604,18 @@ QWidget *DynamicTextItemDelegate::createEditor(QWidget *parent, const QStyleOpti
cd->setObjectName("color_dialog");
return cd;
}
case DynamicElementTextModel::pos:
{
QWidget *w = QStyledItemDelegate::createEditor(parent, option, index);
if(QDoubleSpinBox *dsb = dynamic_cast<QDoubleSpinBox *>(w))
{
dsb->setDecimals(0);
dsb->setSuffix(" px");
}
return w;
}
}
return QStyledItemDelegate::createEditor(parent, option, index);
}

View File

@@ -42,7 +42,8 @@ class DynamicElementTextModel : public QStandardItemModel
compositeText,
size,
tagg,
color
color,
pos
};
DynamicElementTextModel(QObject *parent = nullptr);
@@ -53,7 +54,7 @@ class DynamicElementTextModel : public QStandardItemModel
DynamicElementTextItem *textFromIndex(const QModelIndex &index) const;
DynamicElementTextItem *textFromItem(QStandardItem *item) const;
QModelIndex indexFromText(DynamicElementTextItem *text) const;
QUndoCommand *undoForEditedText(DynamicElementTextItem *deti) const;
QUndoCommand *undoForEditedText(DynamicElementTextItem *deti, QUndoCommand *parent_undo = nullptr) const;
signals:
void dataForTextChanged(DynamicElementTextItem *text);
@@ -67,6 +68,7 @@ class DynamicElementTextModel : public QStandardItemModel
private:
QHash <DynamicElementTextItem *, QStandardItem *> m_texts_list;
QHash <DynamicElementTextItem *, QList<QMetaObject::Connection>> m_hash_text_connect;
bool m_block_dataForTextChanged = false;
};
class DynamicTextItemDelegate : public QStyledItemDelegate