From 9871aa2b53545591bbe26299ec81685af427722e Mon Sep 17 00:00:00 2001 From: Paddle Date: Sun, 26 Mar 2023 14:16:55 +0200 Subject: [PATCH] Preferences: Workbench: Change the QListWidgetDragBug name to ListWidgetDragBug. Move the wbList setXxx() to ctor. Fix the 'Currently, your...' --- src/Gui/CMakeLists.txt | 4 +- src/Gui/DlgSettingsWorkbenches.ui | 8 +-- src/Gui/DlgSettingsWorkbenchesImp.cpp | 15 ++--- ...tDragBugFix.h => ListWidgetDragBugFix.cpp} | 46 ++++++++------ ...tDragBugFix.cpp => ListWidgetDragBugFix.h} | 61 ++++++++----------- 5 files changed, 67 insertions(+), 67 deletions(-) rename src/Gui/{QListWidgetDragBugFix.h => ListWidgetDragBugFix.cpp} (74%) rename src/Gui/{QListWidgetDragBugFix.cpp => ListWidgetDragBugFix.h} (61%) diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index 6442c89e84..76117d2ea5 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -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} diff --git a/src/Gui/DlgSettingsWorkbenches.ui b/src/Gui/DlgSettingsWorkbenches.ui index 47d48642c8..a92c528dda 100644 --- a/src/Gui/DlgSettingsWorkbenches.ui +++ b/src/Gui/DlgSettingsWorkbenches.ui @@ -30,7 +30,7 @@ <html><head/><body><p>You can enable, disable and reorder workbenches (requires restart). Additional workbenches can be installed through the addon manager.</p><p> -Your currently system has the following workbenches:</p></body></html> +Currently, your system has the following workbenches:</p></body></html> true @@ -38,7 +38,7 @@ Your currently system has the following workbenches:</p></body></ - + @@ -116,9 +116,9 @@ after FreeCAD launches - QListWidgetDragBugFix + ListWidgetDragBugFix QListWidget -
QListWidgetDragBugFix.h
+
ListWidgetDragBugFix.h
diff --git a/src/Gui/DlgSettingsWorkbenchesImp.cpp b/src/Gui/DlgSettingsWorkbenchesImp.cpp index f8a1cafb7a..8014bebd26 100644 --- a/src/Gui/DlgSettingsWorkbenchesImp.cpp +++ b/src/Gui/DlgSettingsWorkbenchesImp.cpp @@ -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::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)) { diff --git a/src/Gui/QListWidgetDragBugFix.h b/src/Gui/ListWidgetDragBugFix.cpp similarity index 74% rename from src/Gui/QListWidgetDragBugFix.h rename to src/Gui/ListWidgetDragBugFix.cpp index 6b19195566..23f5a11574 100644 --- a/src/Gui/QListWidgetDragBugFix.h +++ b/src/Gui/ListWidgetDragBugFix.cpp @@ -20,23 +20,31 @@ * * ***************************************************************************/ -#ifndef QLISTWIDGETDRAGBUGFIX_HPP -#define QLISTWIDGETDRAGBUGFIX_HPP - -#include -#include - - -class QListWidgetDragBugFix : public QListWidget -{ - Q_OBJECT - -public: - QListWidgetDragBugFix(QWidget *parent); - ~QListWidgetDragBugFix() override; - -protected: - void dragMoveEvent(QDragMoveEvent *e) override; -}; - +#include "PreCompiled.h" +#ifndef _PreComp_ +# include #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" diff --git a/src/Gui/QListWidgetDragBugFix.cpp b/src/Gui/ListWidgetDragBugFix.h similarity index 61% rename from src/Gui/QListWidgetDragBugFix.cpp rename to src/Gui/ListWidgetDragBugFix.h index 71f864f4e4..2af0b6fb52 100644 --- a/src/Gui/QListWidgetDragBugFix.cpp +++ b/src/Gui/ListWidgetDragBugFix.h @@ -20,39 +20,30 @@ * * ***************************************************************************/ -#include "PreCompiled.h" -#ifndef _PreComp_ -# include +#ifndef QLISTWIDGETDRAGBUGFIX_HPP +#define QLISTWIDGETDRAGBUGFIX_HPP + +#include +#include + + /* 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"