Skip to content

Commit

Permalink
fixes #2502: Inconsistent selection
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Oct 23, 2016
1 parent d5f02ff commit 9c11349
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/Mod/PartDesign/Gui/TaskFeaturePick.cpp
Expand Up @@ -79,6 +79,7 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
: TaskBox(Gui::BitmapFactory().pixmap("edit-select-box"),
tr("Select feature"), true, parent)
, ui(new Ui_TaskFeaturePick)
, doSelection(false)
{

proxy = new QWidget(this);
Expand All @@ -90,6 +91,7 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
connect(ui->radioIndependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->radioDependent, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->radioXRef, SIGNAL(toggled(bool)), this, SLOT(onUpdate(bool)));
connect(ui->listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onItemSelectionChanged()));

enum { axisBit=0, planeBit = 1};

Expand All @@ -109,6 +111,9 @@ TaskFeaturePick::TaskFeaturePick(std::vector<App::DocumentObject*>& objects,
item->setData(Qt::UserRole, QString::fromLatin1((*objIt)->getNameInDocument()));
ui->listWidget->addItem(item);

App::Document* pDoc = (*objIt)->getDocument();
documentName = pDoc->getName();

//check if we need to set any origin in temporary visibility mode
if (*statusIt != invalidShape && (*objIt)->isDerivedFrom ( App::OriginFeature::getClassTypeId () )) {
App::Origin *origin = static_cast<App::OriginFeature*> (*objIt)->getOrigin ();
Expand Down Expand Up @@ -203,7 +208,7 @@ std::vector<App::DocumentObject*> TaskFeaturePick::getFeatures()
std::vector<App::DocumentObject*> result;

for (std::vector<QString>::const_iterator s = features.begin(); s != features.end(); ++s)
result.push_back(App::GetApplication().getActiveDocument()->getObject(s->toLatin1().data()));
result.push_back(App::GetApplication().getDocument(documentName.c_str())->getObject(s->toLatin1().data()));

return result;
}
Expand All @@ -222,7 +227,7 @@ std::vector<App::DocumentObject*> TaskFeaturePick::buildFeatures()

if (item->isSelected() && !item->isHidden()) {
QString t = item->data(Qt::UserRole).toString();
auto obj = App::GetApplication().getActiveDocument()->getObject(t.toLatin1().data());
auto obj = App::GetApplication().getDocument(documentName.c_str())->getObject(t.toLatin1().data());

//build the dependend copy or reference if wanted by the user
if (*st == otherBody || *st == otherPart || *st == notInBody) {
Expand Down Expand Up @@ -387,16 +392,38 @@ App::DocumentObject* TaskFeaturePick::makeCopy(App::DocumentObject* obj, std::st

void TaskFeaturePick::onSelectionChanged(const Gui::SelectionChanges& /*msg*/)
{
if (doSelection)
return;
doSelection = true;
ui->listWidget->clearSelection();
for (Gui::SelectionSingleton::SelObj obj : Gui::Selection().getSelection()) {
for (int row = 0; row < ui->listWidget->count(); row++) {
QListWidgetItem *item = ui->listWidget->item(row);
QString t = item->data(Qt::UserRole).toString();
if (t.compare(QString::fromLatin1(obj.FeatName))==0) {
ui->listWidget->setItemSelected(item, true);
item->setSelected(true);
}
}
}
doSelection = false;
}

void TaskFeaturePick::onItemSelectionChanged()
{
if (doSelection)
return;
doSelection = true;
ui->listWidget->blockSignals(true);
Gui::Selection().clearSelection();
for (int row = 0; row < ui->listWidget->count(); row++) {
QListWidgetItem *item = ui->listWidget->item(row);
QString t = item->data(Qt::UserRole).toString();
if (item->isSelected()) {
Gui::Selection().addSelection(documentName.c_str(), t.toLatin1());
}
}
ui->listWidget->blockSignals(false);
doSelection = false;
}

void TaskFeaturePick::showExternal(bool val)
Expand Down
3 changes: 3 additions & 0 deletions src/Mod/PartDesign/Gui/TaskFeaturePick.h
Expand Up @@ -67,11 +67,14 @@ class TaskFeaturePick : public Gui::TaskView::TaskBox, public Gui::SelectionObse
protected Q_SLOTS:
void onUpdate(bool);
void onSelectionChanged(const Gui::SelectionChanges& msg);
void onItemSelectionChanged();

private:
Ui_TaskFeaturePick* ui;
QWidget* proxy;
std::vector<Gui::ViewProviderOrigin*> origins;
bool doSelection;
std::string documentName;

std::vector<QString> features;
std::vector<featureStatus> statuses;
Expand Down

0 comments on commit 9c11349

Please sign in to comment.