mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 12:40:35 +01:00
Dynamic element text editor : improve the gui
git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@5129 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
@@ -42,9 +42,11 @@ DynamicElementTextItemEditor::DynamicElementTextItemEditor(Element *element, QWi
|
|||||||
m_tree_view->setAlternatingRowColors(true);
|
m_tree_view->setAlternatingRowColors(true);
|
||||||
m_tree_view->setEditTriggers(QAbstractItemView::CurrentChanged);
|
m_tree_view->setEditTriggers(QAbstractItemView::CurrentChanged);
|
||||||
m_tree_view->installEventFilter(this);
|
m_tree_view->installEventFilter(this);
|
||||||
|
m_tree_view->setDragDropMode(QAbstractItemView::InternalMove);
|
||||||
ui->verticalLayout->addWidget(m_tree_view);
|
ui->verticalLayout->addWidget(m_tree_view);
|
||||||
|
|
||||||
setUpAction();
|
connect(m_tree_view, &QTreeView::clicked, this, &DynamicElementTextItemEditor::treeViewClicked);
|
||||||
|
ui->m_remove_selection->setDisabled(true);
|
||||||
|
|
||||||
setElement(element);
|
setElement(element);
|
||||||
}
|
}
|
||||||
@@ -135,6 +137,7 @@ void DynamicElementTextItemEditor::setCurrentText(DynamicElementTextItem *text)
|
|||||||
m_tree_view->expand(index);
|
m_tree_view->expand(index);
|
||||||
m_tree_view->expand(index.child(0,0));
|
m_tree_view->expand(index.child(0,0));
|
||||||
m_tree_view->setCurrentIndex(index);
|
m_tree_view->setCurrentIndex(index);
|
||||||
|
ui->m_remove_selection->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,6 +153,7 @@ void DynamicElementTextItemEditor::setCurrentGroup(ElementTextItemGroup *group)
|
|||||||
|
|
||||||
m_tree_view->expand(index);
|
m_tree_view->expand(index);
|
||||||
m_tree_view->setCurrentIndex(index);
|
m_tree_view->setCurrentIndex(index);
|
||||||
|
ui->m_remove_selection->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
QUndoCommand *DynamicElementTextItemEditor::associatedUndo() const
|
QUndoCommand *DynamicElementTextItemEditor::associatedUndo() const
|
||||||
@@ -168,164 +172,6 @@ QUndoCommand *DynamicElementTextItemEditor::associatedUndo() const
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief DynamicElementTextItemEditor::eventFilter
|
|
||||||
* Reimplemented for intercept the context menu event of the tree view
|
|
||||||
* @param watched
|
|
||||||
* @param event
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
bool DynamicElementTextItemEditor::eventFilter(QObject *watched, QEvent *event)
|
|
||||||
{
|
|
||||||
if(watched == m_tree_view && event->type() == QEvent::ContextMenu)
|
|
||||||
{
|
|
||||||
QContextMenuEvent *qcme = static_cast<QContextMenuEvent *>(event);
|
|
||||||
QModelIndex index = m_tree_view->currentIndex();
|
|
||||||
|
|
||||||
if(index.isValid())
|
|
||||||
{
|
|
||||||
for(QAction *action : m_actions_list)
|
|
||||||
m_context_menu->removeAction(action);
|
|
||||||
m_add_to_group->menu()->clear();
|
|
||||||
|
|
||||||
//Pop up a context menu for a group or a text in a group
|
|
||||||
if(m_model->indexIsInGroup(index))
|
|
||||||
{
|
|
||||||
QStandardItem *item = m_model->itemFromIndex(index);
|
|
||||||
if(item)
|
|
||||||
{
|
|
||||||
if(m_model->textFromItem(item)) //User click on a text or a child item of a text
|
|
||||||
{
|
|
||||||
m_context_menu->addAction(m_remove_text_from_group);
|
|
||||||
m_context_menu->addAction(m_remove_current_text);
|
|
||||||
}
|
|
||||||
else//User click on a group item
|
|
||||||
m_context_menu->addAction(m_remove_current_group);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else //Popup a context menu for a text not owned by a group
|
|
||||||
{
|
|
||||||
if(m_element.data()->textGroups().isEmpty())
|
|
||||||
m_context_menu->addAction(m_new_group);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_context_menu->addAction(m_add_to_group);
|
|
||||||
m_context_menu->addAction(m_new_group);
|
|
||||||
m_context_menu->addAction(m_remove_current_text);
|
|
||||||
|
|
||||||
for(ElementTextItemGroup *grp : m_element.data()->textGroups())
|
|
||||||
{
|
|
||||||
QAction *action = m_add_to_group->menu()->addAction(grp->name());
|
|
||||||
connect(action, &QAction::triggered, m_signal_mapper, static_cast<void (QSignalMapper::*)()>(&QSignalMapper::map));
|
|
||||||
m_signal_mapper->setMapping(action, grp->name());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_context_menu->popup(qcme->globalPos());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return AbstractElementPropertiesEditorWidget::eventFilter(watched, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicElementTextItemEditor::setUpAction()
|
|
||||||
{
|
|
||||||
m_context_menu = new QMenu(this);
|
|
||||||
|
|
||||||
//Action add text to a group
|
|
||||||
m_add_to_group = new QAction(tr("Ajouter au groupe"), m_context_menu);
|
|
||||||
m_add_to_group->setMenu(new QMenu(m_context_menu));
|
|
||||||
|
|
||||||
m_signal_mapper = new QSignalMapper(this);
|
|
||||||
connect(m_signal_mapper, static_cast<void (QSignalMapper::*)(const QString &)>(&QSignalMapper::mapped), this, &DynamicElementTextItemEditor::addCurrentTextToGroup);
|
|
||||||
|
|
||||||
//Action remove text from a group
|
|
||||||
m_remove_text_from_group = new QAction(tr("Supprimer le texte de ce groupe"), m_context_menu);
|
|
||||||
connect(m_remove_text_from_group, &QAction::triggered, [this]()
|
|
||||||
{
|
|
||||||
QAbstractItemModel *m = this->m_tree_view->model();
|
|
||||||
if(m == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DynamicElementTextModel *model = static_cast<DynamicElementTextModel *>(m);
|
|
||||||
if(model->indexIsInGroup(m_tree_view->currentIndex()))
|
|
||||||
{
|
|
||||||
DynamicElementTextItem *deti = m_model->textFromIndex(m_tree_view->currentIndex());
|
|
||||||
if(deti && deti->parentGroup())
|
|
||||||
m_element.data()->removeTextFromGroup(deti, deti->parentGroup());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Action create new group and the connection for open a dialog to edit the name
|
|
||||||
//of the new group
|
|
||||||
m_new_group = new QAction(tr("Nouveau groupe"), m_context_menu);
|
|
||||||
connect(m_new_group, &QAction::triggered, [this]()
|
|
||||||
{
|
|
||||||
QAbstractItemModel *m = this->m_tree_view->model();
|
|
||||||
if(m == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DynamicElementTextModel *model = static_cast<DynamicElementTextModel *>(m);
|
|
||||||
if(model->indexIsInGroup(m_tree_view->currentIndex()))
|
|
||||||
return;
|
|
||||||
|
|
||||||
DynamicElementTextItem *deti = model->textFromIndex(m_tree_view->currentIndex());
|
|
||||||
if(deti)
|
|
||||||
{
|
|
||||||
Element *element = deti->parentElement();
|
|
||||||
QString name = QInputDialog::getText(this, tr("Nom du groupe"), tr("Entrer le nom du nouveau groupe"));
|
|
||||||
|
|
||||||
if(name.isEmpty())
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
element->addTextGroup(name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Action remove the selected text
|
|
||||||
m_remove_current_text = new QAction(tr("Supprimer le texte"), m_context_menu);
|
|
||||||
connect(m_remove_current_text, &QAction::triggered, [this]()
|
|
||||||
{
|
|
||||||
QAbstractItemModel *m = this->m_tree_view->model();
|
|
||||||
if(m == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DynamicElementTextModel *model = static_cast<DynamicElementTextModel *>(m);
|
|
||||||
if(DynamicElementTextItem *deti = model->textFromIndex(m_tree_view->currentIndex()))
|
|
||||||
{
|
|
||||||
if(m_element.data()->diagram() && m_element.data()->diagram()->project())
|
|
||||||
{
|
|
||||||
QUndoStack *us =m_element.data()->diagram()->project()->undoStack();
|
|
||||||
DiagramContent dc;
|
|
||||||
dc.m_element_texts << deti;
|
|
||||||
us->push((new DeleteQGraphicsItemCommand(m_element.data()->diagram(), dc)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//Action remove the selected group
|
|
||||||
m_remove_current_group = new QAction(tr("Supprimer le groupe"), m_context_menu);
|
|
||||||
connect(m_remove_current_group, &QAction::triggered, [this]()
|
|
||||||
{
|
|
||||||
QAbstractItemModel *m = this->m_tree_view->model();
|
|
||||||
if(m == nullptr)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DynamicElementTextModel *model = static_cast<DynamicElementTextModel *>(m);
|
|
||||||
QModelIndex index = m_tree_view->currentIndex();
|
|
||||||
if(model->indexIsInGroup(index) && !model->textFromIndex(index)) //Item is in group and is not a text, so item is the group
|
|
||||||
m_element.data()->removeTextGroup(model->groupFromIndex(index));
|
|
||||||
});
|
|
||||||
|
|
||||||
m_actions_list << m_add_to_group \
|
|
||||||
<< m_remove_text_from_group \
|
|
||||||
<< m_new_group \
|
|
||||||
<< m_remove_current_text \
|
|
||||||
<< m_remove_current_group;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void DynamicElementTextItemEditor::dataEdited(DynamicElementTextItem *deti)
|
void DynamicElementTextItemEditor::dataEdited(DynamicElementTextItem *deti)
|
||||||
{
|
{
|
||||||
Q_UNUSED(deti)
|
Q_UNUSED(deti)
|
||||||
@@ -333,28 +179,12 @@ void DynamicElementTextItemEditor::dataEdited(DynamicElementTextItem *deti)
|
|||||||
apply();
|
apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
void DynamicElementTextItemEditor::treeViewClicked(const QModelIndex &index)
|
||||||
* @brief DynamicElementTextItemEditor::addCurrentTextToGroup
|
|
||||||
* Add the current selected text to the group named @name
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
void DynamicElementTextItemEditor::addCurrentTextToGroup(QString name)
|
|
||||||
{
|
{
|
||||||
QModelIndex index = m_tree_view->currentIndex();
|
if(m_model->indexIsText(index) || m_model->indexIsGroup(index))
|
||||||
DynamicElementTextModel *model = static_cast<DynamicElementTextModel *>(m_tree_view->model());
|
ui->m_remove_selection->setEnabled(true);
|
||||||
|
else
|
||||||
DynamicElementTextItem *deti = model->textFromIndex(index);
|
ui->m_remove_selection->setDisabled(true);
|
||||||
ElementTextItemGroup *group = m_element.data()->textGroup(name);
|
|
||||||
|
|
||||||
if(deti && group)
|
|
||||||
{
|
|
||||||
if(deti->isSelected())
|
|
||||||
{
|
|
||||||
deti->setSelected(false);
|
|
||||||
group->setSelected(true);
|
|
||||||
}
|
|
||||||
m_element.data()->addTextToGroup(deti, group);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -379,10 +209,10 @@ void DynamicElementTextItemEditor::on_m_add_text_clicked()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DynamicElementTextItemEditor::on_m_remove_text_clicked
|
* @brief DynamicElementTextItemEditor::on_m_remove_selection_clicked
|
||||||
* Remove the selected text field
|
* Remove the selected item
|
||||||
*/
|
*/
|
||||||
void DynamicElementTextItemEditor::on_m_remove_text_clicked()
|
void DynamicElementTextItemEditor::on_m_remove_selection_clicked()
|
||||||
{
|
{
|
||||||
DynamicElementTextItem *deti = m_model->textFromIndex(m_tree_view->currentIndex());
|
DynamicElementTextItem *deti = m_model->textFromIndex(m_tree_view->currentIndex());
|
||||||
if(deti)
|
if(deti)
|
||||||
@@ -396,8 +226,20 @@ void DynamicElementTextItemEditor::on_m_remove_text_clicked()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ElementTextItemGroup *group = m_model->groupFromIndex(m_tree_view->currentIndex());
|
ElementTextItemGroup *group = m_model->groupFromIndex(m_tree_view->currentIndex());
|
||||||
if(group)
|
if(group && m_element.data()->diagram())
|
||||||
{
|
m_element.data()->diagram()->undoStack().push(new RemoveTextsGroupCommand(m_element.data(), group));
|
||||||
m_element.data()->removeTextGroup(group);
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextItemEditor::on_m_add_group_clicked
|
||||||
|
* Add a new group
|
||||||
|
*/
|
||||||
|
void DynamicElementTextItemEditor::on_m_add_group_clicked()
|
||||||
|
{
|
||||||
|
QString name = QInputDialog::getText(this, tr("Nom du groupe"), tr("Entrer le nom du nouveau groupe"));
|
||||||
|
|
||||||
|
if(name.isEmpty())
|
||||||
|
return;
|
||||||
|
else if (m_element.data()->diagram())
|
||||||
|
m_element.data()->diagram()->undoStack().push(new AddTextsGroupCommand(m_element, name));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ class DynamicElementTextItem;
|
|||||||
class DynamicElementTextModel;
|
class DynamicElementTextModel;
|
||||||
class QTreeView;
|
class QTreeView;
|
||||||
class QStandardItem;
|
class QStandardItem;
|
||||||
class QMenu;
|
|
||||||
class QSignalMapper;
|
|
||||||
class ElementTextItemGroup;
|
class ElementTextItemGroup;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
@@ -47,29 +45,20 @@ class DynamicElementTextItemEditor : public AbstractElementPropertiesEditorWidge
|
|||||||
void setCurrentText(DynamicElementTextItem *text);
|
void setCurrentText(DynamicElementTextItem *text);
|
||||||
void setCurrentGroup(ElementTextItemGroup *group);
|
void setCurrentGroup(ElementTextItemGroup *group);
|
||||||
QUndoCommand *associatedUndo() const override;
|
QUndoCommand *associatedUndo() const override;
|
||||||
bool eventFilter(QObject *watched, QEvent *event) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setUpAction();
|
|
||||||
void dataEdited(DynamicElementTextItem *deti);
|
void dataEdited(DynamicElementTextItem *deti);
|
||||||
void addCurrentTextToGroup(QString name);
|
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_text_clicked();
|
void on_m_remove_selection_clicked();
|
||||||
|
void on_m_add_group_clicked();
|
||||||
private:
|
|
||||||
|
private:
|
||||||
Ui::DynamicElementTextItemEditor *ui;
|
Ui::DynamicElementTextItemEditor *ui;
|
||||||
QTreeView *m_tree_view = nullptr;
|
QTreeView *m_tree_view = nullptr;
|
||||||
DynamicElementTextModel *m_model = nullptr;
|
DynamicElementTextModel *m_model = nullptr;
|
||||||
QMenu *m_context_menu = nullptr;
|
|
||||||
QSignalMapper *m_signal_mapper = nullptr;
|
|
||||||
QAction *m_add_to_group = nullptr,
|
|
||||||
*m_remove_text_from_group = nullptr,
|
|
||||||
*m_new_group = nullptr,
|
|
||||||
*m_remove_current_text = nullptr,
|
|
||||||
*m_remove_current_group = nullptr;
|
|
||||||
QList<QAction *> m_actions_list;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // DYNAMICELEMENTTEXTITEMEDITOR_H
|
#endif // DYNAMICELEMENTTEXTITEMEDITOR_H
|
||||||
|
|||||||
@@ -35,7 +35,7 @@
|
|||||||
<string>Ajouter un texte</string>
|
<string>Ajouter un texte</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string>Texte</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset resource="../../qelectrotech.qrc">
|
<iconset resource="../../qelectrotech.qrc">
|
||||||
@@ -44,7 +44,21 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="m_remove_text">
|
<widget class="QPushButton" name="m_add_group">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Ajouter un groupe de textes</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Groupe</string>
|
||||||
|
</property>
|
||||||
|
<property name="icon">
|
||||||
|
<iconset resource="../../qelectrotech.qrc">
|
||||||
|
<normaloff>:/ico/16x16/list-add.png</normaloff>:/ico/16x16/list-add.png</iconset>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="m_remove_selection">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
<string>Supprimer la sélection</string>
|
<string>Supprimer la sélection</string>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
#include "conductor.h"
|
#include "conductor.h"
|
||||||
#include "elementtextitemgroup.h"
|
#include "elementtextitemgroup.h"
|
||||||
#include "qeticons.h"
|
#include "qeticons.h"
|
||||||
|
#include "diagram.h"
|
||||||
|
#include "addelementtextcommand.h"
|
||||||
|
|
||||||
DynamicElementTextModel::DynamicElementTextModel(Element *element, QObject *parent) :
|
DynamicElementTextModel::DynamicElementTextModel(Element *element, QObject *parent) :
|
||||||
QStandardItemModel(parent),
|
QStandardItemModel(parent),
|
||||||
@@ -100,7 +102,7 @@ QList<QStandardItem *> DynamicElementTextModel::itemsForText(DynamicElementTextI
|
|||||||
return qsi_list;
|
return qsi_list;
|
||||||
|
|
||||||
QStandardItem *qsi = new QStandardItem(deti->toPlainText());
|
QStandardItem *qsi = new QStandardItem(deti->toPlainText());
|
||||||
qsi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
qsi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled |Qt::ItemIsDragEnabled);
|
||||||
qsi->setIcon(QET::Icons::PartText);
|
qsi->setIcon(QET::Icons::PartText);
|
||||||
|
|
||||||
|
|
||||||
@@ -299,8 +301,8 @@ void DynamicElementTextModel::removeText(DynamicElementTextItem *deti)
|
|||||||
/**
|
/**
|
||||||
* @brief DynamicElementTextModel::textFromIndex
|
* @brief DynamicElementTextModel::textFromIndex
|
||||||
* @param index
|
* @param index
|
||||||
* @return the text associated with @index. Return value can be nullptr
|
* @return the text associated with @index. Returned value can be nullptr
|
||||||
* @Index can be a child of an index associated with a text
|
* @Index can be a child of an index associated with a text and can be the column 0 or 1.
|
||||||
*/
|
*/
|
||||||
DynamicElementTextItem *DynamicElementTextModel::textFromIndex(const QModelIndex &index) const
|
DynamicElementTextItem *DynamicElementTextModel::textFromIndex(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
@@ -317,11 +319,19 @@ DynamicElementTextItem *DynamicElementTextModel::textFromIndex(const QModelIndex
|
|||||||
* @brief DynamicElementTextModel::textFromItem
|
* @brief DynamicElementTextModel::textFromItem
|
||||||
* @param item
|
* @param item
|
||||||
* @return the text associated with @item. Return value can be nullptr
|
* @return the text associated with @item. Return value can be nullptr
|
||||||
* @item can be a child of an item associated with a text
|
* @item can be a child of an item associated with a text and can be the column 0 or 1.
|
||||||
* Note can return nullptr
|
* Note can return nullptr
|
||||||
*/
|
*/
|
||||||
DynamicElementTextItem *DynamicElementTextModel::textFromItem(QStandardItem *item) const
|
DynamicElementTextItem *DynamicElementTextModel::textFromItem(QStandardItem *item) const
|
||||||
{
|
{
|
||||||
|
//Get the item of the column 0
|
||||||
|
if(item->column() == 1)
|
||||||
|
{
|
||||||
|
if(item->parent())
|
||||||
|
item = item->parent()->child(item->row(), 0);
|
||||||
|
else
|
||||||
|
item = itemFromIndex(index(item->row(),0));
|
||||||
|
}
|
||||||
//Item haven't got parent, so they can be only a text or a group
|
//Item haven't got parent, so they can be only a text or a group
|
||||||
if(!item->parent())
|
if(!item->parent())
|
||||||
{
|
{
|
||||||
@@ -486,7 +496,7 @@ void DynamicElementTextModel::addGroup(ElementTextItemGroup *group)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
QStandardItem *grp = new QStandardItem(group->name());
|
QStandardItem *grp = new QStandardItem(group->name());
|
||||||
grp->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
grp->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
|
||||||
grp->setIcon(QET::Icons::textGroup);
|
grp->setIcon(QET::Icons::textGroup);
|
||||||
|
|
||||||
QStandardItem *empty_qsi = new QStandardItem(0);
|
QStandardItem *empty_qsi = new QStandardItem(0);
|
||||||
@@ -550,7 +560,7 @@ void DynamicElementTextModel::removeTextFromGroup(DynamicElementTextItem *deti,
|
|||||||
* @brief DynamicElementTextModel::groupFromIndex
|
* @brief DynamicElementTextModel::groupFromIndex
|
||||||
* @param index
|
* @param index
|
||||||
* @return the group associated with @index. Return value can be nullptr
|
* @return the group associated with @index. Return value can be nullptr
|
||||||
* @Index can be a child of an index associated with a group
|
* @Index can be a child of an index associated with a group and can be the column 0 or 1.
|
||||||
*/
|
*/
|
||||||
ElementTextItemGroup *DynamicElementTextModel::groupFromIndex(const QModelIndex &index) const
|
ElementTextItemGroup *DynamicElementTextModel::groupFromIndex(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
@@ -567,17 +577,24 @@ ElementTextItemGroup *DynamicElementTextModel::groupFromIndex(const QModelIndex
|
|||||||
* @brief DynamicElementTextModel::groupFromItem
|
* @brief DynamicElementTextModel::groupFromItem
|
||||||
* @param item
|
* @param item
|
||||||
* @return the group associated with @item. Return value can be nullptr
|
* @return the group associated with @item. Return value can be nullptr
|
||||||
* @item can be a child of an item associated with a group
|
* @item can be a child of an item associated with a group and can be the column 0 or 1.
|
||||||
*/
|
*/
|
||||||
ElementTextItemGroup *DynamicElementTextModel::groupFromItem(QStandardItem *item) const
|
ElementTextItemGroup *DynamicElementTextModel::groupFromItem(QStandardItem *item) const
|
||||||
{
|
{
|
||||||
QStandardItem *group_item = item;
|
//Get the item of the column 0
|
||||||
|
if(item->column() == 1)
|
||||||
|
{
|
||||||
|
if(item->parent())
|
||||||
|
item = item->parent()->child(item->row(), 0);
|
||||||
|
else
|
||||||
|
item = itemFromIndex(index(item->row(),0));
|
||||||
|
}
|
||||||
|
|
||||||
while (group_item->parent())
|
while (item->parent())
|
||||||
group_item = group_item->parent();
|
item = item->parent();
|
||||||
|
|
||||||
if(m_groups_list.values().contains(group_item))
|
if(m_groups_list.values().contains(item))
|
||||||
return m_groups_list.key(group_item);
|
return m_groups_list.key(item);
|
||||||
else
|
else
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -596,6 +613,241 @@ QModelIndex DynamicElementTextModel::indexFromGroup(ElementTextItemGroup *group)
|
|||||||
return QModelIndex();
|
return QModelIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextModel::indexIsText
|
||||||
|
* @param index
|
||||||
|
* @return True if @index represente a text, both for the column 0 and 1.
|
||||||
|
* Return false if @index is a child of an index associated to a text.
|
||||||
|
*/
|
||||||
|
bool DynamicElementTextModel::indexIsText(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
QStandardItem *item = nullptr;
|
||||||
|
|
||||||
|
//The item represent the second column
|
||||||
|
if(index.column() == 1)
|
||||||
|
{
|
||||||
|
if(index.parent().isValid())
|
||||||
|
item = itemFromIndex(index.parent().child(index.row(),0));
|
||||||
|
else
|
||||||
|
item = itemFromIndex(this->index(index.row(),0));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
item = itemFromIndex(index);
|
||||||
|
|
||||||
|
if(item && m_texts_list.values().contains(item))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextModel::indexIsGroup
|
||||||
|
* @param index
|
||||||
|
* @return True if @index represente a group, both for the column 0 and 1.
|
||||||
|
* Return false if @index is a child of an index associated to a group.
|
||||||
|
*/
|
||||||
|
bool DynamicElementTextModel::indexIsGroup(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
QStandardItem *item = nullptr;
|
||||||
|
|
||||||
|
//The item represent the second column
|
||||||
|
if(index.column() == 1)
|
||||||
|
{
|
||||||
|
if(index.parent().isValid())
|
||||||
|
item = itemFromIndex(index.parent().child(index.row(),0));
|
||||||
|
else
|
||||||
|
item = itemFromIndex(this->index(index.row(),0));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
item = itemFromIndex(index);
|
||||||
|
|
||||||
|
if(item && m_groups_list.values().contains(item))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DynamicElementTextModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(action);
|
||||||
|
|
||||||
|
if(data->hasFormat("application/x-qet-element-text-uuid"))
|
||||||
|
{
|
||||||
|
QModelIndex index;
|
||||||
|
if(parent.isValid() && row != -1 && column !=1) //Insert in child of parent
|
||||||
|
index = parent.child(row, column);
|
||||||
|
else if (parent.isValid() && row == -1 && column == -1) //Drop in parent
|
||||||
|
index = parent;
|
||||||
|
|
||||||
|
QUuid uuid(data->text());
|
||||||
|
|
||||||
|
//The data is drop in a group
|
||||||
|
if(indexIsInGroup(index))
|
||||||
|
{
|
||||||
|
//Data is dragged from a text direct child of element
|
||||||
|
for(DynamicElementTextItem *text : m_element.data()->dynamicTextItems())
|
||||||
|
if(text->uuid() == uuid)
|
||||||
|
return true;
|
||||||
|
//Data is dragged from a text in a group
|
||||||
|
for(ElementTextItemGroup *group : m_element.data()->textGroups())
|
||||||
|
{
|
||||||
|
for(DynamicElementTextItem *text : group->texts())
|
||||||
|
if(text->uuid() == uuid)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
else //The data is not drop in a group, then the action must be a drag of text from a group to the element
|
||||||
|
{
|
||||||
|
for(ElementTextItemGroup *group : m_element.data()->textGroups())
|
||||||
|
{
|
||||||
|
for(DynamicElementTextItem *text : group->texts())
|
||||||
|
if(text->uuid() == uuid)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextModel::dropMimeData
|
||||||
|
* @param data
|
||||||
|
* @param action
|
||||||
|
* @param row
|
||||||
|
* @param column
|
||||||
|
* @param parent
|
||||||
|
* @return In any case return false, for overwrite the default behavior of model.
|
||||||
|
*/
|
||||||
|
bool DynamicElementTextModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
|
||||||
|
{
|
||||||
|
Q_UNUSED(action)
|
||||||
|
|
||||||
|
if(data->hasFormat("application/x-qet-element-text-uuid"))
|
||||||
|
{
|
||||||
|
QUuid uuid(data->text());
|
||||||
|
DynamicElementTextItem *deti = nullptr;
|
||||||
|
ElementTextItemGroup *group = nullptr;
|
||||||
|
|
||||||
|
QModelIndex index;
|
||||||
|
if(parent.isValid() && row != -1 && column !=1) //Insert in child of parent
|
||||||
|
index = parent.child(row, column);
|
||||||
|
else if (parent.isValid() && row == -1 && column == -1) //Drop in parent
|
||||||
|
index = parent;
|
||||||
|
|
||||||
|
//Darg and drop in a group of text
|
||||||
|
if(indexIsInGroup(index))
|
||||||
|
{
|
||||||
|
//The dragged text is a direct child of element
|
||||||
|
for(DynamicElementTextItem *text : m_element.data()->dynamicTextItems())
|
||||||
|
{
|
||||||
|
if(text->uuid() == uuid)
|
||||||
|
{
|
||||||
|
deti = text;
|
||||||
|
group = groupFromIndex(index);
|
||||||
|
|
||||||
|
if(group && deti) //Text successfully added in a group
|
||||||
|
{
|
||||||
|
m_element.data()->diagram()->undoStack().push(new AddTextToGroupCommand(deti, group));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//The dragged text is in a group
|
||||||
|
for(ElementTextItemGroup *grp : m_element.data()->textGroups())
|
||||||
|
{
|
||||||
|
for(DynamicElementTextItem *text : grp->texts())
|
||||||
|
{
|
||||||
|
if(text->uuid() == uuid)
|
||||||
|
{
|
||||||
|
deti = text;
|
||||||
|
group = groupFromIndex(index);
|
||||||
|
|
||||||
|
//Text successfully moved from a group to another group
|
||||||
|
if(group && deti)
|
||||||
|
{
|
||||||
|
QUndoStack &stack = m_element.data()->diagram()->undoStack();
|
||||||
|
stack.beginMacro(tr("Déplacer un texte dans un autre groupe"));
|
||||||
|
stack.push(new RemoveTextFromGroupCommand(deti, grp));
|
||||||
|
stack.push(new AddTextToGroupCommand(deti, group));
|
||||||
|
stack.endMacro();
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else //Drag and drop in anaother place
|
||||||
|
{
|
||||||
|
//Get the dropped text
|
||||||
|
for(ElementTextItemGroup *grp : m_element.data()->textGroups())
|
||||||
|
{
|
||||||
|
for(DynamicElementTextItem *text : grp->texts())
|
||||||
|
{
|
||||||
|
if(text->uuid() == uuid)
|
||||||
|
{
|
||||||
|
deti = text;
|
||||||
|
group = grp;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(deti)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(deti && group) //Text successfully removed from group
|
||||||
|
{
|
||||||
|
m_element.data()->diagram()->undoStack().push((new RemoveTextFromGroupCommand(deti, group)));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMimeData *DynamicElementTextModel::mimeData(const QModelIndexList &indexes) const
|
||||||
|
{
|
||||||
|
QModelIndex index = indexes.first();
|
||||||
|
if (index.isValid())
|
||||||
|
{
|
||||||
|
QStandardItem *item = itemFromIndex(index);
|
||||||
|
if(item)
|
||||||
|
{
|
||||||
|
DynamicElementTextItem *deti = m_texts_list.key(item);
|
||||||
|
if(deti)
|
||||||
|
{
|
||||||
|
QMimeData *mime_data = new QMimeData();
|
||||||
|
mime_data->setText(deti->uuid().toString());
|
||||||
|
mime_data->setData("application/x-qet-element-text-uuid", deti->uuid().toString().toLatin1());
|
||||||
|
return mime_data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return new QMimeData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief DynamicElementTextModel::mimeTypes
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
QStringList DynamicElementTextModel::mimeTypes() const
|
||||||
|
{
|
||||||
|
QStringList mime_list = QAbstractItemModel::mimeTypes();
|
||||||
|
mime_list << "application/x-qet-element-text-uuid";
|
||||||
|
return mime_list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief DynamicElementTextModel::enableSourceText
|
* @brief DynamicElementTextModel::enableSourceText
|
||||||
* Enable the good field, according to the current source of text, for the edited text @deti
|
* Enable the good field, according to the current source of text, for the edited text @deti
|
||||||
|
|||||||
@@ -62,6 +62,13 @@ class DynamicElementTextModel : public QStandardItemModel
|
|||||||
ElementTextItemGroup *groupFromIndex(const QModelIndex &index) const;
|
ElementTextItemGroup *groupFromIndex(const QModelIndex &index) const;
|
||||||
ElementTextItemGroup *groupFromItem(QStandardItem *item) const;
|
ElementTextItemGroup *groupFromItem(QStandardItem *item) const;
|
||||||
QModelIndex indexFromGroup(ElementTextItemGroup *group) const;
|
QModelIndex indexFromGroup(ElementTextItemGroup *group) const;
|
||||||
|
bool indexIsText(const QModelIndex &index) const;
|
||||||
|
bool indexIsGroup(const QModelIndex &index) const;
|
||||||
|
|
||||||
|
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
|
||||||
|
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
|
||||||
|
QMimeData *mimeData(const QModelIndexList &indexes) const override;
|
||||||
|
QStringList mimeTypes() const override;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void dataForTextChanged(DynamicElementTextItem *text);
|
void dataForTextChanged(DynamicElementTextItem *text);
|
||||||
|
|||||||
@@ -118,6 +118,9 @@ RemoveTextsGroupCommand::RemoveTextsGroupCommand(Element *element, ElementTextIt
|
|||||||
m_group(group)
|
m_group(group)
|
||||||
{
|
{
|
||||||
setText(QObject::tr("Supprimer un groupe de textes d'élément"));
|
setText(QObject::tr("Supprimer un groupe de textes d'élément"));
|
||||||
|
|
||||||
|
for(DynamicElementTextItem *deti : group->texts())
|
||||||
|
m_text_list.append(deti);
|
||||||
}
|
}
|
||||||
|
|
||||||
RemoveTextsGroupCommand::~RemoveTextsGroupCommand()
|
RemoveTextsGroupCommand::~RemoveTextsGroupCommand()
|
||||||
@@ -126,13 +129,25 @@ RemoveTextsGroupCommand::~RemoveTextsGroupCommand()
|
|||||||
void RemoveTextsGroupCommand::undo()
|
void RemoveTextsGroupCommand::undo()
|
||||||
{
|
{
|
||||||
if(m_element && m_group)
|
if(m_element && m_group)
|
||||||
|
{
|
||||||
m_element.data()->addTextGroup(m_group.data());
|
m_element.data()->addTextGroup(m_group.data());
|
||||||
|
|
||||||
|
for(QPointer<DynamicElementTextItem> p : m_text_list)
|
||||||
|
if(p)
|
||||||
|
m_element.data()->addTextToGroup(p.data(), m_group.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoveTextsGroupCommand::redo()
|
void RemoveTextsGroupCommand::redo()
|
||||||
{
|
{
|
||||||
if(m_element && m_group)
|
if(m_element && m_group)
|
||||||
|
{
|
||||||
|
for(QPointer<DynamicElementTextItem> p : m_text_list)
|
||||||
|
if(p)
|
||||||
|
m_element.data()->removeTextFromGroup(p.data(), m_group.data());
|
||||||
|
|
||||||
m_element.data()->removeTextGroup(m_group.data());
|
m_element.data()->removeTextGroup(m_group.data());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -177,7 +192,14 @@ void AddTextToGroupCommand::undo()
|
|||||||
void AddTextToGroupCommand::redo()
|
void AddTextToGroupCommand::redo()
|
||||||
{
|
{
|
||||||
if(m_element && m_group && m_text)
|
if(m_element && m_group && m_text)
|
||||||
|
{
|
||||||
|
if(m_text.data()->isSelected())
|
||||||
|
{
|
||||||
|
m_text.data()->setSelected(false);
|
||||||
|
m_group.data()->setSelected(true);
|
||||||
|
}
|
||||||
m_element.data()->addTextToGroup(m_text, m_group);
|
m_element.data()->addTextToGroup(m_text, m_group);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************
|
/*****************************
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ class RemoveTextsGroupCommand : public QUndoCommand
|
|||||||
private:
|
private:
|
||||||
QPointer<Element> m_element;
|
QPointer<Element> m_element;
|
||||||
QPointer<ElementTextItemGroup> m_group;
|
QPointer<ElementTextItemGroup> m_group;
|
||||||
|
QList<QPointer<DynamicElementTextItem>> m_text_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AddTextToGroupCommand : public QUndoCommand
|
class AddTextToGroupCommand : public QUndoCommand
|
||||||
|
|||||||
Reference in New Issue
Block a user