Preferences: Workbench: Change the QListWidgetDragBug name to ListWidgetDragBug. Move the wbList setXxx() to ctor. Fix the 'Currently, your...'

This commit is contained in:
Paddle
2023-03-26 14:16:55 +02:00
parent 7eb3386894
commit 9871aa2b53
5 changed files with 67 additions and 67 deletions

View File

@@ -526,7 +526,7 @@ SET(Dialog_Customize_CPP_SRCS
DlgKeyboardImp.cpp
DlgToolbarsImp.cpp
QListWidgetCustom.cpp
QListWidgetDragBugFix.cpp
ListWidgetDragBugFix.cpp
)
SET(Dialog_Customize_HPP_SRCS
DlgActionsImp.h
@@ -537,7 +537,7 @@ SET(Dialog_Customize_HPP_SRCS
DlgKeyboardImp.h
DlgToolbarsImp.h
QListWidgetCustom.h
QListWidgetDragBugFix.h
ListWidgetDragBugFix.h
)
SET(Dialog_Customize_SRCS
${Dialog_Customize_CPP_SRCS}

View File

@@ -30,7 +30,7 @@
</property>
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;You can enable, disable and reorder workbenches (requires restart). Additional workbenches can be installed through the addon manager.&lt;/p&gt;&lt;p&gt;
Your currently system has the following workbenches:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
Currently, your system has the following workbenches:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
@@ -38,7 +38,7 @@ Your currently system has the following workbenches:&lt;/p&gt;&lt;/body&gt;&lt;/
</widget>
</item>
<item row="1" column="0">
<widget class="QListWidgetDragBugFix" name="wbList"/>
<widget class="ListWidgetDragBugFix" name="wbList"/>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout">
@@ -116,9 +116,9 @@ after FreeCAD launches</string>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>QListWidgetDragBugFix</class>
<class>ListWidgetDragBugFix</class>
<extends>QListWidget</extends>
<header>QListWidgetDragBugFix.h</header>
<header>ListWidgetDragBugFix.h</header>
</customwidget>
</customwidgets>
<resources/>

View File

@@ -54,6 +54,14 @@ DlgSettingsWorkbenchesImp::DlgSettingsWorkbenchesImp( QWidget* parent )
, ui(new Ui_DlgSettingsWorkbenches)
{
ui->setupUi(this);
ui->wbList->setDragDropMode(QAbstractItemView::InternalMove);
ui->wbList->setSelectionMode(QAbstractItemView::SingleSelection);
ui->wbList->viewport()->setAcceptDrops(true);
ui->wbList->setDropIndicatorShown(true);
ui->wbList->setDragEnabled(true);
ui->wbList->setDefaultDropAction(Qt::MoveAction);
connect(ui->AutoloadModuleCombo, QOverload<int>::of(&QComboBox::activated), this, [this](int index) { onStartWbChangedClicked(index); });
}
@@ -207,13 +215,6 @@ void DlgSettingsWorkbenchesImp::buildWorkbenchList()
QStringList enabledWbs = getEnabledWorkbenches();
QStringList disabledWbs = getDisabledWorkbenches();
ui->wbList->setDragDropMode(QAbstractItemView::InternalMove);
ui->wbList->setSelectionMode(QAbstractItemView::SingleSelection);
ui->wbList->viewport()->setAcceptDrops(true);
ui->wbList->setDropIndicatorShown(true);
ui->wbList->setDragEnabled(true);
ui->wbList->setDefaultDropAction(Qt::MoveAction);
//First we add the enabled wbs in their saved order.
for (const auto& wbName : enabledWbs) {
if (workbenches.contains(wbName)) {

View File

@@ -20,23 +20,31 @@
* *
***************************************************************************/
#ifndef QLISTWIDGETDRAGBUGFIX_HPP
#define QLISTWIDGETDRAGBUGFIX_HPP
#include <QDragMoveEvent>
#include <QListWidget>
class QListWidgetDragBugFix : public QListWidget
{
Q_OBJECT
public:
QListWidgetDragBugFix(QWidget *parent);
~QListWidgetDragBugFix() override;
protected:
void dragMoveEvent(QDragMoveEvent *e) override;
};
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QDragMoveEvent>
#endif
#include "ListWidgetDragBugFix.h"
ListWidgetDragBugFix::ListWidgetDragBugFix(QWidget * parent)
: QListWidget(parent)
{
}
ListWidgetDragBugFix::~ListWidgetDragBugFix()
{
}
void ListWidgetDragBugFix::dragMoveEvent(QDragMoveEvent *e)
{
if ((row(itemAt(e->pos())) == currentRow() + 1)
|| (currentRow() == count() - 1 && row(itemAt(e->pos())) == -1)) {
e->ignore();
return;
}
QListWidget::dragMoveEvent(e);
}
#include "moc_ListWidgetDragBugFix.cpp"

View File

@@ -20,39 +20,30 @@
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QDragMoveEvent>
#ifndef QLISTWIDGETDRAGBUGFIX_HPP
#define QLISTWIDGETDRAGBUGFIX_HPP
#include <QDragMoveEvent>
#include <QListWidget>
/* Qt has a recent bug (2023, https://bugreports.qt.io/browse/QTBUG-100128)
* where the items disappears in certain conditions when drag and dropping.
* Here we prevent the situation where this happens.
* 1 - If the item is dropped on the item below such that the item doesn't move (ie superior half of the below item)
* 2 - The item is the last one and user drop it on the empty space below.
* In both those cases the item widget was lost.
* When Qt solve this bug, this class should not be required anymore.
*/
class ListWidgetDragBugFix : public QListWidget
{
Q_OBJECT
public:
explicit ListWidgetDragBugFix(QWidget *parent);
~ListWidgetDragBugFix() override;
protected:
void dragMoveEvent(QDragMoveEvent *e) override;
};
#endif
#include "QListWidgetDragBugFix.h"
QListWidgetDragBugFix::QListWidgetDragBugFix(QWidget * parent)
: QListWidget(parent)
{
}
QListWidgetDragBugFix::~QListWidgetDragBugFix()
{
}
/* Qt has a recent bug (2023, https://bugreports.qt.io/browse/QTBUG-100128)
* where the items disappears in certain conditions when drag and dropping.
* Here we prevent the situation where this happens.
* 1 - If the item is dropped on the item below such that the item doesn't move (ie superior half of the below item)
* 2 - The item is the last one and user drop it on the empty space below.
* In both those cases the item widget was lost.
*/
void QListWidgetDragBugFix::dragMoveEvent(QDragMoveEvent *e)
{
if ((row(itemAt(e->pos())) == currentRow() + 1)
|| (currentRow() == count() - 1 && row(itemAt(e->pos())) == -1)) {
e->ignore();
}
else {
QListWidget::dragMoveEvent(e);
}
}
#include "moc_QListWidgetDragBugFix.cpp"