Element texts group can be renamed

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5191 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2017-12-18 20:05:00 +00:00
parent fd2a53bdd2
commit 94d52880a7
7 changed files with 80 additions and 37 deletions

View File

@@ -195,6 +195,7 @@ void ElementTextItemGroup::setVerticalAdjustment(int v)
void ElementTextItemGroup::setName(QString name) void ElementTextItemGroup::setName(QString name)
{ {
m_name = name; m_name = name;
emit nameChanged(m_name);
} }
/** /**

View File

@@ -39,12 +39,14 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged) Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
Q_PROPERTY(int verticalAdjustment READ verticalAdjustment WRITE setVerticalAdjustment NOTIFY verticalAdjustmentChanged) Q_PROPERTY(int verticalAdjustment READ verticalAdjustment WRITE setVerticalAdjustment NOTIFY verticalAdjustmentChanged)
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
public: public:
signals: signals:
void rotationChanged(qreal); void rotationChanged(qreal);
void verticalAdjustmentChanged(int); void verticalAdjustmentChanged(int);
void alignmentChanged(Qt::Alignment); void alignmentChanged(Qt::Alignment);
void nameChanged(QString);
public: public:
ElementTextItemGroup(const QString &name, Element *parent); ElementTextItemGroup(const QString &name, Element *parent);

View File

@@ -36,18 +36,13 @@ DynamicElementTextItemEditor::DynamicElementTextItemEditor(Element *element, QWi
{ {
ui->setupUi(this); ui->setupUi(this);
m_tree_view = new QTreeView(this); ui->m_tree_view->setItemDelegate(new DynamicTextItemDelegate(ui->m_tree_view));
m_tree_view->header()->setDefaultSectionSize(150); ui->m_tree_view->installEventFilter(this);
m_tree_view->setItemDelegate(new DynamicTextItemDelegate(m_tree_view));
m_tree_view->setAlternatingRowColors(true);
m_tree_view->setEditTriggers(QAbstractItemView::CurrentChanged);
m_tree_view->installEventFilter(this);
m_tree_view->setDragDropMode(QAbstractItemView::InternalMove);
ui->verticalLayout->addWidget(m_tree_view);
connect(m_tree_view, &QTreeView::clicked, this, &DynamicElementTextItemEditor::treeViewClicked);
ui->m_remove_selection->setDisabled(true); ui->m_remove_selection->setDisabled(true);
ui->m_export_pb->hide();
ui->m_import_pb->hide();
setElement(element); setElement(element);
} }
@@ -64,9 +59,9 @@ void DynamicElementTextItemEditor::setElement(Element *element)
m_element = element; m_element = element;
DynamicElementTextModel *old_model = m_model; DynamicElementTextModel *old_model = m_model;
m_model = new DynamicElementTextModel(element, m_tree_view); m_model = new DynamicElementTextModel(element, ui->m_tree_view);
connect(m_model, &DynamicElementTextModel::dataChanged, this, &DynamicElementTextItemEditor::dataEdited); connect(m_model, &DynamicElementTextModel::dataChanged, this, &DynamicElementTextItemEditor::dataEdited);
m_tree_view->setModel(m_model); ui->m_tree_view->setModel(m_model);
if(old_model) if(old_model)
delete old_model; delete old_model;
@@ -153,9 +148,9 @@ void DynamicElementTextItemEditor::setCurrentText(DynamicElementTextItem *text)
if(!index.isValid()) if(!index.isValid())
return; return;
m_tree_view->expand(index); ui->m_tree_view->expand(index);
m_tree_view->expand(index.child(0,0)); ui->m_tree_view->expand(index.child(0,0));
m_tree_view->setCurrentIndex(index); ui->m_tree_view->setCurrentIndex(index);
ui->m_remove_selection->setEnabled(true); ui->m_remove_selection->setEnabled(true);
} }
@@ -170,8 +165,8 @@ void DynamicElementTextItemEditor::setCurrentGroup(ElementTextItemGroup *group)
if(!index.isValid()) if(!index.isValid())
return; return;
m_tree_view->expand(index); ui->m_tree_view->expand(index);
m_tree_view->setCurrentIndex(index); ui->m_tree_view->setCurrentIndex(index);
ui->m_remove_selection->setEnabled(true); ui->m_remove_selection->setEnabled(true);
} }
@@ -197,14 +192,6 @@ void DynamicElementTextItemEditor::dataEdited()
apply(); apply();
} }
void DynamicElementTextItemEditor::treeViewClicked(const QModelIndex &index)
{
if(m_model->indexIsText(index) || m_model->indexIsGroup(index))
ui->m_remove_selection->setEnabled(true);
else
ui->m_remove_selection->setDisabled(true);
}
/** /**
* @brief DynamicElementTextItemEditor::on_m_add_text_clicked * @brief DynamicElementTextItemEditor::on_m_add_text_clicked
* Add a new dynamic text * Add a new dynamic text
@@ -232,7 +219,7 @@ void DynamicElementTextItemEditor::on_m_add_text_clicked()
*/ */
void DynamicElementTextItemEditor::on_m_remove_selection_clicked() void DynamicElementTextItemEditor::on_m_remove_selection_clicked()
{ {
DynamicElementTextItem *deti = m_model->textFromIndex(m_tree_view->currentIndex()); DynamicElementTextItem *deti = m_model->textFromIndex(ui->m_tree_view->currentIndex());
if(deti) if(deti)
{ {
if(m_element->diagram()) if(m_element->diagram())
@@ -243,7 +230,7 @@ void DynamicElementTextItemEditor::on_m_remove_selection_clicked()
} }
return; return;
} }
ElementTextItemGroup *group = m_model->groupFromIndex(m_tree_view->currentIndex()); ElementTextItemGroup *group = m_model->groupFromIndex(ui->m_tree_view->currentIndex());
if(group && m_element.data()->diagram()) if(group && m_element.data()->diagram())
m_element.data()->diagram()->undoStack().push(new RemoveTextsGroupCommand(m_element.data(), group)); m_element.data()->diagram()->undoStack().push(new RemoveTextsGroupCommand(m_element.data(), group));
} }
@@ -261,3 +248,11 @@ void DynamicElementTextItemEditor::on_m_add_group_clicked()
else if (m_element.data()->diagram()) else if (m_element.data()->diagram())
m_element.data()->diagram()->undoStack().push(new AddTextsGroupCommand(m_element, name)); m_element.data()->diagram()->undoStack().push(new AddTextsGroupCommand(m_element, name));
} }
void DynamicElementTextItemEditor::on_m_tree_view_clicked(const QModelIndex &index)
{
if(m_model->indexIsText(index) || m_model->indexIsGroup(index))
ui->m_remove_selection->setEnabled(true);
else
ui->m_remove_selection->setDisabled(true);
}

View File

@@ -22,7 +22,6 @@
class DynamicElementTextItem; class DynamicElementTextItem;
class DynamicElementTextModel; class DynamicElementTextModel;
class QTreeView;
class QStandardItem; class QStandardItem;
class ElementTextItemGroup; class ElementTextItemGroup;
@@ -48,16 +47,15 @@ class DynamicElementTextItemEditor : public AbstractElementPropertiesEditorWidge
private: private:
void dataEdited(); void dataEdited();
void treeViewClicked(const QModelIndex &index);
private slots: private slots:
void on_m_add_text_clicked(); void on_m_add_text_clicked();
void on_m_remove_selection_clicked(); void on_m_remove_selection_clicked();
void on_m_add_group_clicked(); void on_m_add_group_clicked();
void on_m_tree_view_clicked(const QModelIndex &index);
private: private:
Ui::DynamicElementTextItemEditor *ui; Ui::DynamicElementTextItemEditor *ui;
QTreeView *m_tree_view = nullptr;
DynamicElementTextModel *m_model = nullptr; DynamicElementTextModel *m_model = nullptr;
}; };

View File

@@ -73,6 +73,43 @@
</item> </item>
</layout> </layout>
</item> </item>
<item>
<widget class="QTreeView" name="m_tree_view">
<property name="editTriggers">
<set>QAbstractItemView::CurrentChanged|QAbstractItemView::SelectedClicked</set>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="animated">
<bool>true</bool>
</property>
<attribute name="headerDefaultSectionSize">
<number>150</number>
</attribute>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="m_im_exp_layout">
<item>
<widget class="QPushButton" name="m_export_pb">
<property name="text">
<string>Exporter</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="m_import_pb">
<property name="text">
<string>Importer</string>
</property>
</widget>
</item>
</layout>
</item>
</layout> </layout>
</widget> </widget>
<resources> <resources>

View File

@@ -520,6 +520,11 @@ QUndoCommand *DynamicElementTextModel::undoForEditedGroup(ElementTextItemGroup *
if(group->verticalAdjustment() != v_adjustment) if(group->verticalAdjustment() != v_adjustment)
new QPropertyUndoCommand(group, "verticalAdjustment", QVariant(group->verticalAdjustment()), QVariant(v_adjustment), undo); new QPropertyUndoCommand(group, "verticalAdjustment", QVariant(group->verticalAdjustment()), QVariant(v_adjustment), undo);
QString name = group_qsi->data(Qt::DisplayRole).toString();
if(group->name() != name)
new QPropertyUndoCommand(group, "name", QVariant(group->name()), QVariant(name), undo);
return undo; return undo;
} }
@@ -535,7 +540,7 @@ void DynamicElementTextModel::addGroup(ElementTextItemGroup *group)
//Group //Group
QStandardItem *grp = new QStandardItem(group->name()); QStandardItem *grp = new QStandardItem(group->name());
grp->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); grp->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsEditable);
grp->setIcon(QET::Icons::textGroup); grp->setIcon(QET::Icons::textGroup);
QStandardItem *empty_qsi = new QStandardItem(0); QStandardItem *empty_qsi = new QStandardItem(0);
@@ -836,7 +841,7 @@ bool DynamicElementTextModel::dropMimeData(const QMimeData *data, Qt::DropAction
if(group && deti) //Text successfully added in a group if(group && deti) //Text successfully added in a group
{ {
m_element.data()->diagram()->undoStack().push(new AddTextToGroupCommand(deti, group)); m_element.data()->diagram()->undoStack().push(new AddTextToGroupCommand(deti, group));
return false; return true;
} }
} }
} }
@@ -860,7 +865,7 @@ bool DynamicElementTextModel::dropMimeData(const QMimeData *data, Qt::DropAction
stack.push(new AddTextToGroupCommand(deti, group)); stack.push(new AddTextToGroupCommand(deti, group));
stack.endMacro(); stack.endMacro();
return false; return true;
} }
} }
} }
@@ -889,7 +894,7 @@ bool DynamicElementTextModel::dropMimeData(const QMimeData *data, Qt::DropAction
if(deti && group) //Text successfully removed from group if(deti && group) //Text successfully removed from group
{ {
m_element.data()->diagram()->undoStack().push((new RemoveTextFromGroupCommand(deti, group))); m_element.data()->diagram()->undoStack().push((new RemoveTextFromGroupCommand(deti, group)));
return false; return true;
} }
return false; return false;
@@ -1020,8 +1025,8 @@ 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 //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 //the first column is use only for display the title of the property, except for the name of texts group
if(qsi->column() == 1 && !m_block_dataChanged) if((m_groups_list.values().contains(qsi) || qsi->column() == 1) && !m_block_dataChanged)
emit dataChanged(); emit dataChanged();
} }
@@ -1083,6 +1088,7 @@ void DynamicElementTextModel::setConnection(ElementTextItemGroup *group, bool se
connection_list << connect(group, &ElementTextItemGroup::alignmentChanged, [group, this]() {this->updateDataFromGroup(group, grp_alignment);}); connection_list << connect(group, &ElementTextItemGroup::alignmentChanged, [group, this]() {this->updateDataFromGroup(group, grp_alignment);});
connection_list << connect(group, &ElementTextItemGroup::rotationChanged, [group, this]() {this->updateDataFromGroup(group, grp_rotation);}); connection_list << connect(group, &ElementTextItemGroup::rotationChanged, [group, this]() {this->updateDataFromGroup(group, grp_rotation);});
connection_list << connect(group, &ElementTextItemGroup::verticalAdjustmentChanged, [group, this]() {this->updateDataFromGroup(group, grp_v_adjust);}); connection_list << connect(group, &ElementTextItemGroup::verticalAdjustmentChanged, [group, this]() {this->updateDataFromGroup(group, grp_v_adjust);});
connection_list << connect(group, &ElementTextItemGroup::verticalAdjustmentChanged, [group, this]() {this->updateDataFromGroup(group, grp_name);});
m_hash_group_connect.insert(group, connection_list); m_hash_group_connect.insert(group, connection_list);
} }
@@ -1203,6 +1209,9 @@ void DynamicElementTextModel::updateDataFromGroup(ElementTextItemGroup *group, D
case grp_v_adjust: case grp_v_adjust:
qsi->child(adjust_grp_row,1)->setData(group->verticalAdjustment(), Qt::EditRole); qsi->child(adjust_grp_row,1)->setData(group->verticalAdjustment(), Qt::EditRole);
break; break;
case grp_name:
qsi->setData(group->name(), Qt::DisplayRole);
break;
} }
m_block_dataChanged = false; m_block_dataChanged = false;

View File

@@ -49,7 +49,8 @@ class DynamicElementTextModel : public QStandardItemModel
rotation, rotation,
grp_alignment, grp_alignment,
grp_rotation, grp_rotation,
grp_v_adjust grp_v_adjust,
grp_name
}; };
DynamicElementTextModel(Element *element, QObject *parent = nullptr); DynamicElementTextModel(Element *element, QObject *parent = nullptr);