mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
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:
@@ -195,6 +195,7 @@ void ElementTextItemGroup::setVerticalAdjustment(int v)
|
||||
void ElementTextItemGroup::setName(QString name)
|
||||
{
|
||||
m_name = name;
|
||||
emit nameChanged(m_name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,12 +39,14 @@ class ElementTextItemGroup : public QObject, public QGraphicsItemGroup
|
||||
Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
|
||||
Q_PROPERTY(int verticalAdjustment READ verticalAdjustment WRITE setVerticalAdjustment NOTIFY verticalAdjustmentChanged)
|
||||
Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
|
||||
Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
|
||||
|
||||
public:
|
||||
signals:
|
||||
void rotationChanged(qreal);
|
||||
void verticalAdjustmentChanged(int);
|
||||
void alignmentChanged(Qt::Alignment);
|
||||
void nameChanged(QString);
|
||||
|
||||
public:
|
||||
ElementTextItemGroup(const QString &name, Element *parent);
|
||||
|
||||
@@ -36,18 +36,13 @@ DynamicElementTextItemEditor::DynamicElementTextItemEditor(Element *element, QWi
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
m_tree_view = new QTreeView(this);
|
||||
m_tree_view->header()->setDefaultSectionSize(150);
|
||||
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_tree_view->setItemDelegate(new DynamicTextItemDelegate(ui->m_tree_view));
|
||||
ui->m_tree_view->installEventFilter(this);
|
||||
ui->m_remove_selection->setDisabled(true);
|
||||
|
||||
ui->m_export_pb->hide();
|
||||
ui->m_import_pb->hide();
|
||||
|
||||
setElement(element);
|
||||
}
|
||||
|
||||
@@ -64,9 +59,9 @@ void DynamicElementTextItemEditor::setElement(Element *element)
|
||||
m_element = element;
|
||||
|
||||
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);
|
||||
m_tree_view->setModel(m_model);
|
||||
ui->m_tree_view->setModel(m_model);
|
||||
|
||||
if(old_model)
|
||||
delete old_model;
|
||||
@@ -153,9 +148,9 @@ void DynamicElementTextItemEditor::setCurrentText(DynamicElementTextItem *text)
|
||||
if(!index.isValid())
|
||||
return;
|
||||
|
||||
m_tree_view->expand(index);
|
||||
m_tree_view->expand(index.child(0,0));
|
||||
m_tree_view->setCurrentIndex(index);
|
||||
ui->m_tree_view->expand(index);
|
||||
ui->m_tree_view->expand(index.child(0,0));
|
||||
ui->m_tree_view->setCurrentIndex(index);
|
||||
ui->m_remove_selection->setEnabled(true);
|
||||
}
|
||||
|
||||
@@ -170,8 +165,8 @@ void DynamicElementTextItemEditor::setCurrentGroup(ElementTextItemGroup *group)
|
||||
if(!index.isValid())
|
||||
return;
|
||||
|
||||
m_tree_view->expand(index);
|
||||
m_tree_view->setCurrentIndex(index);
|
||||
ui->m_tree_view->expand(index);
|
||||
ui->m_tree_view->setCurrentIndex(index);
|
||||
ui->m_remove_selection->setEnabled(true);
|
||||
}
|
||||
|
||||
@@ -197,14 +192,6 @@ void DynamicElementTextItemEditor::dataEdited()
|
||||
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
|
||||
* Add a new dynamic text
|
||||
@@ -232,7 +219,7 @@ void DynamicElementTextItemEditor::on_m_add_text_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(m_element->diagram())
|
||||
@@ -243,7 +230,7 @@ void DynamicElementTextItemEditor::on_m_remove_selection_clicked()
|
||||
}
|
||||
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())
|
||||
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())
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
class DynamicElementTextItem;
|
||||
class DynamicElementTextModel;
|
||||
class QTreeView;
|
||||
class QStandardItem;
|
||||
class ElementTextItemGroup;
|
||||
|
||||
@@ -48,16 +47,15 @@ class DynamicElementTextItemEditor : public AbstractElementPropertiesEditorWidge
|
||||
|
||||
private:
|
||||
void dataEdited();
|
||||
void treeViewClicked(const QModelIndex &index);
|
||||
|
||||
private slots:
|
||||
void on_m_add_text_clicked();
|
||||
void on_m_remove_selection_clicked();
|
||||
void on_m_add_group_clicked();
|
||||
void on_m_tree_view_clicked(const QModelIndex &index);
|
||||
|
||||
private:
|
||||
Ui::DynamicElementTextItemEditor *ui;
|
||||
QTreeView *m_tree_view = nullptr;
|
||||
DynamicElementTextModel *m_model = nullptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -73,6 +73,43 @@
|
||||
</item>
|
||||
</layout>
|
||||
</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>
|
||||
</widget>
|
||||
<resources>
|
||||
|
||||
@@ -520,6 +520,11 @@ QUndoCommand *DynamicElementTextModel::undoForEditedGroup(ElementTextItemGroup *
|
||||
if(group->verticalAdjustment() != v_adjustment)
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -535,7 +540,7 @@ void DynamicElementTextModel::addGroup(ElementTextItemGroup *group)
|
||||
|
||||
//Group
|
||||
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);
|
||||
|
||||
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
|
||||
{
|
||||
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.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
|
||||
{
|
||||
m_element.data()->diagram()->undoStack().push((new RemoveTextFromGroupCommand(deti, group)));
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
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
|
||||
//the first column is use only for display the title of the property
|
||||
if(qsi->column() == 1 && !m_block_dataChanged)
|
||||
//the first column is use only for display the title of the property, except for the name of texts group
|
||||
if((m_groups_list.values().contains(qsi) || qsi->column() == 1) && !m_block_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::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_name);});
|
||||
|
||||
m_hash_group_connect.insert(group, connection_list);
|
||||
}
|
||||
@@ -1203,6 +1209,9 @@ void DynamicElementTextModel::updateDataFromGroup(ElementTextItemGroup *group, D
|
||||
case grp_v_adjust:
|
||||
qsi->child(adjust_grp_row,1)->setData(group->verticalAdjustment(), Qt::EditRole);
|
||||
break;
|
||||
case grp_name:
|
||||
qsi->setData(group->name(), Qt::DisplayRole);
|
||||
break;
|
||||
}
|
||||
|
||||
m_block_dataChanged = false;
|
||||
|
||||
@@ -49,7 +49,8 @@ class DynamicElementTextModel : public QStandardItemModel
|
||||
rotation,
|
||||
grp_alignment,
|
||||
grp_rotation,
|
||||
grp_v_adjust
|
||||
grp_v_adjust,
|
||||
grp_name
|
||||
};
|
||||
|
||||
DynamicElementTextModel(Element *element, QObject *parent = nullptr);
|
||||
|
||||
Reference in New Issue
Block a user