mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-09-13 20:23:04 +02:00
Initial comit to use drag and drop
This commit is contained in:
parent
df07f373d8
commit
d3ad490b84
@ -201,6 +201,9 @@ SOURCES += $$files(sources/*.cpp) \
|
||||
$$files(sources/TerminalStrip/ui/*.cpp) \
|
||||
$$files(sources/TerminalStrip/UndoCommand/*.cpp)
|
||||
|
||||
# Needed for use promote QTreeWidget in terminalstripeditor.ui
|
||||
INCLUDEPATH += sources/TerminalStrip/ui
|
||||
|
||||
# Liste des fichiers qui seront incorpores au binaire en tant que ressources Qt
|
||||
RESOURCES += qelectrotech.qrc
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "../elementprovider.h"
|
||||
#include "../qetgraphicsitem/terminalelement.h"
|
||||
#include "../UndoCommand/addterminalstripcommand.h"
|
||||
#include "terminalstriptreewidget.h"
|
||||
|
||||
#include <QTreeWidgetItem>
|
||||
|
||||
@ -61,10 +62,10 @@ void TerminalStripEditor::buildTree()
|
||||
}
|
||||
|
||||
QStringList strl{title};
|
||||
new QTreeWidgetItem(ui->m_terminal_strip_tw, strl, TerminalStripEditor::Root);
|
||||
new QTreeWidgetItem(ui->m_terminal_strip_tw, strl, TerminalStripTreeWidget::Root);
|
||||
|
||||
QStringList ftstrl(tr("Bornes indépendante"));
|
||||
new QTreeWidgetItem(ui->m_terminal_strip_tw, ftstrl, TerminalStripEditor::FreeTerminal);
|
||||
new QTreeWidgetItem(ui->m_terminal_strip_tw, ftstrl, TerminalStripTreeWidget::FreeTerminalSection);
|
||||
|
||||
auto ts_vector = m_project->terminalStrip();
|
||||
std::sort(ts_vector.begin(), ts_vector.end(), [](TerminalStrip *a, TerminalStrip *b) {
|
||||
@ -105,7 +106,7 @@ QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_s
|
||||
}
|
||||
if (!inst_qtwi) {
|
||||
QStringList inst_strl{installation_str};
|
||||
inst_qtwi = new QTreeWidgetItem(root_item, inst_strl, TerminalStripEditor::Inst);
|
||||
inst_qtwi = new QTreeWidgetItem(root_item, inst_strl, TerminalStripTreeWidget::Inst);
|
||||
}
|
||||
|
||||
//Check if location already exist
|
||||
@ -121,12 +122,12 @@ QTreeWidgetItem* TerminalStripEditor::addTerminalStrip(TerminalStrip *terminal_s
|
||||
}
|
||||
if (!loc_qtwi) {
|
||||
QStringList loc_strl{location_str};
|
||||
loc_qtwi = new QTreeWidgetItem(inst_qtwi, loc_strl, TerminalStripEditor::Loc);
|
||||
loc_qtwi = new QTreeWidgetItem(inst_qtwi, loc_strl, TerminalStripTreeWidget::Loc);
|
||||
}
|
||||
|
||||
//Add the terminal strip
|
||||
QStringList name{terminal_strip->name()};
|
||||
auto item = new QTreeWidgetItem(loc_qtwi, name, TerminalStripEditor::Strip);
|
||||
auto item = new QTreeWidgetItem(loc_qtwi, name, TerminalStripTreeWidget::Strip);
|
||||
m_H_item_strip.insert(item, terminal_strip);
|
||||
return item;
|
||||
}
|
||||
@ -155,7 +156,8 @@ void TerminalStripEditor::addFreeTerminal()
|
||||
for (const auto terminal : qAsConst(vector_))
|
||||
{
|
||||
QStringList strl{terminal->actualLabel()};
|
||||
new QTreeWidgetItem(free_terminal_item, strl, TerminalStripEditor::FreeTerminal);
|
||||
auto item = new QTreeWidgetItem(free_terminal_item, strl, TerminalStripTreeWidget::FreeTerminal);
|
||||
item->setData(0, TerminalStripTreeWidget::UUID_USER_ROLE, terminal->uuid().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,14 +171,14 @@ void TerminalStripEditor::on_m_add_terminal_strip_pb_clicked()
|
||||
|
||||
if (auto item = ui->m_terminal_strip_tw->currentItem())
|
||||
{
|
||||
if (item->type() == TerminalStripEditor::Strip) {
|
||||
if (item->type() == TerminalStripTreeWidget::Strip) {
|
||||
item = item->parent();
|
||||
}
|
||||
if (item->type() == TerminalStripEditor::Loc) {
|
||||
if (item->type() == TerminalStripTreeWidget::Loc) {
|
||||
dialog->setLocation(item->data(0, Qt::DisplayRole).toString());
|
||||
item = item->parent();
|
||||
}
|
||||
if (item->type() == TerminalStripEditor::Inst) {
|
||||
if (item->type() == TerminalStripTreeWidget::Inst) {
|
||||
dialog->setInstallation(item->data(0, Qt::DisplayRole).toString());
|
||||
}
|
||||
}
|
||||
|
@ -38,14 +38,6 @@ class TerminalStripEditor : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
enum TreeWidgetType{
|
||||
Root,
|
||||
FreeTerminal,
|
||||
Inst,
|
||||
Loc,
|
||||
Strip
|
||||
};
|
||||
|
||||
public:
|
||||
explicit TerminalStripEditor(QETProject *project, QWidget *parent = nullptr);
|
||||
~TerminalStripEditor() override;
|
||||
|
@ -32,7 +32,16 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<widget class="QTreeWidget" name="m_terminal_strip_tw">
|
||||
<widget class="TerminalStripTreeWidget" name="m_terminal_strip_tw">
|
||||
<property name="dragEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::InternalMove</enum>
|
||||
</property>
|
||||
<property name="autoExpandDelay">
|
||||
<number>500</number>
|
||||
</property>
|
||||
<property name="animated">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
@ -45,6 +54,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>TerminalStripTreeWidget</class>
|
||||
<extends>QTreeWidget</extends>
|
||||
<header location="global">terminalstriptreewidget.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
78
sources/TerminalStrip/ui/terminalstriptreewidget.cpp
Normal file
78
sources/TerminalStrip/ui/terminalstriptreewidget.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
Copyright 2006-2021 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "terminalstriptreewidget.h"
|
||||
#include "../../qeticons.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDrag>
|
||||
#include <QMimeData>
|
||||
#include <QDragMoveEvent>
|
||||
|
||||
int TerminalStripTreeWidget::UUID_USER_ROLE = Qt::UserRole + 1;
|
||||
|
||||
TerminalStripTreeWidget::TerminalStripTreeWidget(QWidget *parent) :
|
||||
QTreeWidget(parent)
|
||||
{}
|
||||
|
||||
QStringList TerminalStripTreeWidget::mimeTypes() const
|
||||
{
|
||||
QStringList strl(QStringLiteral("application/x-qet-terminal-strip-tree-item"));
|
||||
|
||||
return strl;
|
||||
}
|
||||
|
||||
void TerminalStripTreeWidget::startDrag(Qt::DropActions supportedActions)
|
||||
{
|
||||
Q_UNUSED(supportedActions)
|
||||
|
||||
auto item = currentItem();
|
||||
|
||||
if (!item ||
|
||||
item->type() != TerminalStripTreeWidget::FreeTerminal) {
|
||||
return;
|
||||
}
|
||||
|
||||
QDrag drag(this);
|
||||
auto mime_data = new QMimeData();
|
||||
mime_data->setData("application/x-qet-terminal-strip-tree-item", item->data(0, UUID_USER_ROLE).toString().toLatin1());
|
||||
|
||||
drag.setMimeData(mime_data);
|
||||
drag.setPixmap(QET::Icons::ElementTerminal.pixmap(16,16));
|
||||
drag.exec(Qt::MoveAction);
|
||||
}
|
||||
|
||||
void TerminalStripTreeWidget::dragMoveEvent(QDragMoveEvent *event)
|
||||
{
|
||||
QTreeWidget::dragMoveEvent(event);
|
||||
|
||||
auto item = itemAt(event->pos());
|
||||
|
||||
if (item &&
|
||||
item->type() == TerminalStripTreeWidget::Strip) {
|
||||
event->accept();
|
||||
} else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
void TerminalStripTreeWidget::dropEvent(QDropEvent *event)
|
||||
{}
|
||||
|
||||
Qt::DropActions TerminalStripTreeWidget::supportedDropActions() const {
|
||||
return Qt::MoveAction;
|
||||
}
|
54
sources/TerminalStrip/ui/terminalstriptreewidget.h
Normal file
54
sources/TerminalStrip/ui/terminalstriptreewidget.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
Copyright 2006-2021 The QElectroTech Team
|
||||
This file is part of QElectroTech.
|
||||
|
||||
QElectroTech is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
QElectroTech is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef TERMINALSTRIPTREEWIDGET_H
|
||||
#define TERMINALSTRIPTREEWIDGET_H
|
||||
|
||||
#include <QTreeWidget>
|
||||
|
||||
/**
|
||||
* @brief The TerminalStripTreeWidget class
|
||||
* Derived class use to implement custom drag and drop
|
||||
*/
|
||||
class TerminalStripTreeWidget : public QTreeWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public :
|
||||
enum TreeWidgetType{
|
||||
Root,
|
||||
FreeTerminal,
|
||||
FreeTerminalSection,
|
||||
Inst,
|
||||
Loc,
|
||||
Strip
|
||||
};
|
||||
|
||||
//Role used for data in QTreeWidgetItem
|
||||
static int UUID_USER_ROLE;
|
||||
|
||||
public:
|
||||
TerminalStripTreeWidget(QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
QStringList mimeTypes() const override;
|
||||
void startDrag(Qt::DropActions supportedActions) override;
|
||||
void dragMoveEvent(QDragMoveEvent *event) override;
|
||||
void dropEvent(QDropEvent *event) override;
|
||||
Qt::DropActions supportedDropActions() const override;
|
||||
};
|
||||
|
||||
#endif // TERMINALSTRIPTREEWIDGET_H
|
Loading…
x
Reference in New Issue
Block a user