[PD] allow to change feature order in patterns

As discussed here: https://forum.freecadweb.org/viewtopic.php?f=27&t=48998#p420352
The pattern dialogs need a feature to change the order of the features to be patterned
This commit is contained in:
donovaly
2020-07-31 03:02:42 +02:00
committed by wwmayer
parent 3600ccae8d
commit d5787f9bda
11 changed files with 92 additions and 3 deletions

View File

@@ -121,13 +121,15 @@ void TaskLinearPatternParameters::setupUI()
ui->listWidgetFeatures->addAction(action);
connect(action, SIGNAL(triggered()), this, SLOT(onFeatureDeleted()));
ui->listWidgetFeatures->setContextMenuPolicy(Qt::ActionsContextMenu);
connect(ui->listWidgetFeatures->model(),
SIGNAL(rowsMoved(QModelIndex, int, int, QModelIndex, int)), this, SLOT(indexesMoved()));
updateViewTimer = new QTimer(this);
updateViewTimer->setSingleShot(true);
updateViewTimer->setInterval(getUpdateViewTimeout());
connect(updateViewTimer, SIGNAL(timeout()),
this, SLOT(onUpdateViewTimer()));
connect(ui->comboDirection, SIGNAL(activated(int)),
this, SLOT(onDirectionChanged(int)));
connect(ui->checkReverse, SIGNAL(toggled(bool)),
@@ -220,6 +222,22 @@ void TaskLinearPatternParameters::updateUI()
blockUpdate = false;
}
void TaskLinearPatternParameters::indexesMoved()
{
PartDesign::Transformed* pcTransformed = getObject();
std::vector<App::DocumentObject*> originals = pcTransformed->Originals.getValues();
// the number of items has not been changed, they have just been reordered
// so we read every list item to recreate the originals vector
std::string name;
for (unsigned i = 0; i < ui->listWidgetFeatures->count(); i++) {
name = ui->listWidgetFeatures->item(i)->data(Qt::UserRole).toByteArray().constData();
originals[i] = pcTransformed->getDocument()->getObject(name.c_str());
}
setupTransaction();
pcTransformed->Originals.setValues(originals);
recomputeFeature();
}
void TaskLinearPatternParameters::onUpdateViewTimer()
{
setupTransaction();