[PD] make sections sortable

- allow to sort loft sections by dragging: https://forum.freecadweb.org/viewtopic.php?f=19&t=50222

- fix bug of uninitialized options: https://forum.freecadweb.org/viewtopic.php?f=19&t=50221

- use better code for the context menu of the listWidget (the same we use in other placed of PD)

- add missing tooltip for mirror feature
This commit is contained in:
donovaly
2020-09-15 00:28:20 +02:00
committed by wwmayer
parent e8b5cfced7
commit 03c2c76963
4 changed files with 46 additions and 2 deletions

View File

@@ -77,12 +77,20 @@ TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView,bool /*newObj*
connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)),
this, SLOT(onUpdateView(bool)));
// Create context menu
QAction* remove = new QAction(tr("Remove"), this);
remove->setShortcut(QString::fromLatin1("Del"));
remove->setShortcut(QKeySequence::Delete);
#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
// display shortcut behind the context menu entry
remove->setShortcutVisibleInContextMenu(true);
#endif
ui->listWidgetReferences->addAction(remove);
ui->listWidgetReferences->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(remove, SIGNAL(triggered()), this, SLOT(onDeleteSection()));
connect(ui->listWidgetReferences->model(),
SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)), this, SLOT(indexesMoved()));
this->groupLayout()->addWidget(proxy);
// Temporarily prevent unnecessary feature recomputes
@@ -109,6 +117,10 @@ TaskLoftParameters::TaskLoftParameters(ViewProviderLoft *LoftView,bool /*newObj*
ui->listWidgetReferences->addItem(item);
}
// get options
ui->checkBoxRuled->setChecked(loft->Ruled.getValue());
ui->checkBoxClosed->setChecked(loft->Closed.getValue());
if (!loft->Sections.getValues().empty()) {
LoftView->makeTemporaryVisible(true);
}
@@ -250,6 +262,27 @@ void TaskLoftParameters::onDeleteSection()
}
}
void TaskLoftParameters::indexesMoved()
{
QAbstractItemModel* model = qobject_cast<QAbstractItemModel*>(sender());
if (!model)
return;
PartDesign::Loft* loft = static_cast<PartDesign::Loft*>(vp->getObject());
std::vector<App::DocumentObject*> originals = loft->Sections.getValues();
QByteArray name;
int rows = model->rowCount();
for (int i = 0; i < rows; i++) {
QModelIndex index = model->index(i, 0);
name = index.data(Qt::UserRole).toByteArray().constData();
originals[i] = loft->getDocument()->getObject(name.constData());
}
loft->Sections.setValues(originals);
recomputeFeature();
}
void TaskLoftParameters::clearButtons() {
ui->buttonRefAdd->setChecked(false);