Sketcher: Fix hide/show operations on Constraint Widget taking too long

=======================================================================

Fixes delay reported here:
https://forum.freecadweb.org/viewtopic.php?f=17&t=60569#p519685
This commit is contained in:
Abdullah Tahiri
2021-09-22 14:49:04 +02:00
parent 6343836689
commit f3a5217468
2 changed files with 45 additions and 13 deletions

View File

@@ -541,20 +541,12 @@ void ConstraintView::updateActiveStatus()
void ConstraintView::showConstraints()
{
QList<QListWidgetItem *> items = selectedItems();
for (auto it : items) {
if (it->checkState() != Qt::Checked)
it->setCheckState(Qt::Checked);
}
Q_EMIT emitShowSelection3DVisibility();
}
void ConstraintView::hideConstraints()
{
QList<QListWidgetItem *> items = selectedItems();
for (auto it : items) {
if (it->checkState() != Qt::Unchecked)
it->setCheckState(Qt::Unchecked);
}
Q_EMIT emitHideSelection3DVisibility();
}
void ConstraintView::modifyCurrentItem()
@@ -687,6 +679,14 @@ TaskSketcherConstrains::TaskSketcherConstrains(ViewProviderSketch *sketchView) :
ui->hideAllButton, SIGNAL(clicked(bool)),
this , SLOT (on_hideAllButton_clicked(bool))
);
QObject::connect(
ui->listWidgetConstraints, SIGNAL(emitHideSelection3DVisibility()),
this , SLOT (on_listWidgetConstraints_emitHideSelection3DVisibility())
);
QObject::connect(
ui->listWidgetConstraints, SIGNAL(emitShowSelection3DVisibility()),
this , SLOT (on_listWidgetConstraints_emitShowSelection3DVisibility())
);
connectionConstraintsChanged = sketchView->signalConstraintsChanged.connect(
boost::bind(&SketcherGui::TaskSketcherConstrains::slotConstraintsChanged, this));
@@ -706,20 +706,32 @@ TaskSketcherConstrains::~TaskSketcherConstrains()
connectionConstraintsChanged.disconnect();
}
void TaskSketcherConstrains::changeFilteredVisibility(bool show)
void TaskSketcherConstrains::changeFilteredVisibility(bool show, ActionTarget target)
{
assert(sketchView);
const Sketcher::SketchObject * sketch = sketchView->getSketchObject();
bool doCommit = false;
auto selecteditems = ui->listWidgetConstraints->selectedItems();
Gui::Command::openCommand(QT_TRANSLATE_NOOP("Command", "Update constraint's virtual space"));
for(int i = 0; i < ui->listWidgetConstraints->count(); ++i)
{
QListWidgetItem* item = ui->listWidgetConstraints->item(i);
if(!item->isHidden()) { // The item is shown in the filtered list
bool processItem = false;
if(target == ActionTarget::All) {
processItem = !item->isHidden();
}
else if(target == ActionTarget::Selected) {
if(std::find(selecteditems.begin(), selecteditems.end(), item) != selecteditems.end())
processItem = true;
}
if(processItem) { // The item is shown in the filtered list
const ConstraintItem *it = dynamic_cast<const ConstraintItem*>(item);
if (!it)
@@ -757,11 +769,22 @@ void TaskSketcherConstrains::on_showAllButton_clicked(bool)
{
changeFilteredVisibility(true);
}
void TaskSketcherConstrains::on_hideAllButton_clicked(bool)
{
changeFilteredVisibility(false);
}
void TaskSketcherConstrains::on_listWidgetConstraints_emitHideSelection3DVisibility()
{
changeFilteredVisibility(false, ActionTarget::Selected);
}
void TaskSketcherConstrains::on_listWidgetConstraints_emitShowSelection3DVisibility()
{
changeFilteredVisibility(true, ActionTarget::Selected);
}
void TaskSketcherConstrains::onSelectionChanged(const Gui::SelectionChanges& msg)
{
std::string temp;

View File

@@ -53,6 +53,8 @@ Q_SIGNALS:
void onUpdateDrivingStatus(QListWidgetItem *item, bool status);
void onUpdateActiveStatus(QListWidgetItem *item, bool status);
void emitCenterSelectedItems();
void emitHideSelection3DVisibility();
void emitShowSelection3DVisibility();
protected Q_SLOTS:
void modifyCurrentItem();
@@ -98,6 +100,11 @@ class TaskSketcherConstrains : public Gui::TaskView::TaskBox, public Gui::Select
InternalAlignment = 23
};
enum class ActionTarget {
All,
Selected
};
public:
TaskSketcherConstrains(ViewProviderSketch *sketchView);
~TaskSketcherConstrains();
@@ -109,7 +116,7 @@ private:
void slotConstraintsChanged(void);
bool isConstraintFiltered(QListWidgetItem * item);
void change3DViewVisibilityToTrackFilter();
void changeFilteredVisibility(bool show);
void changeFilteredVisibility(bool show, ActionTarget target = ActionTarget::All);
public Q_SLOTS:
void on_comboBoxFilter_currentIndexChanged(int);
@@ -123,6 +130,8 @@ public Q_SLOTS:
void on_extendedInformation_stateChanged(int state);
void on_showAllButton_clicked(bool);
void on_hideAllButton_clicked(bool);
void on_listWidgetConstraints_emitShowSelection3DVisibility();
void on_listWidgetConstraints_emitHideSelection3DVisibility();
protected:
void changeEvent(QEvent *e);