Skip to content

Commit

Permalink
+ fixes #1484: Do not sort properties in alphabetical order
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 21, 2014
1 parent 1c9c0d2 commit 2bfb120
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 33 deletions.
90 changes: 64 additions & 26 deletions src/Gui/PropertyView.cpp
Expand Up @@ -29,7 +29,6 @@
#endif

/// Here the FreeCAD includes sorted by Base,App,Gui......

#include <App/PropertyStandard.h>
#include <App/PropertyGeo.h>
#include <App/PropertyLinks.h>
Expand Down Expand Up @@ -78,72 +77,111 @@ PropertyView::~PropertyView()
{
}

struct PropertyView::PropInfo
{
std::string propName;
int propId;
std::vector<App::Property*> propList;
};

struct PropertyView::PropFind {
const PropInfo& item;
PropFind(const PropInfo& item) : item(item) {}
bool operator () (const PropInfo& elem) const
{
return (elem.propId == item.propId) &&
(elem.propName == item.propName);
}
};

void PropertyView::onSelectionChanged(const SelectionChanges& msg)
{
if (msg.Type != SelectionChanges::AddSelection &&
msg.Type != SelectionChanges::RmvSelection &&
msg.Type != SelectionChanges::SetSelection &&
msg.Type != SelectionChanges::ClrSelection)
return;

// group the properties by <name,id>
std::map<std::pair<std::string, int>, std::vector<App::Property*> > propDataMap;
std::map<std::pair<std::string, int>, std::vector<App::Property*> > propViewMap;
std::vector<PropInfo> propDataMap;
std::vector<PropInfo> propViewMap;
std::vector<SelectionSingleton::SelObj> array = Gui::Selection().getCompleteSelection();
for (std::vector<SelectionSingleton::SelObj>::const_iterator it = array.begin(); it != array.end(); ++it) {
App::DocumentObject *ob=0;
ViewProvider *vp=0;

std::map<std::string,App::Property*> dataMap;
std::map<std::string,App::Property*> viewMap;
std::vector<App::Property*> dataList;
std::map<std::string, App::Property*> viewList;
if ((*it).pObject) {
(*it).pObject->getPropertyMap(dataMap);
(*it).pObject->getPropertyList(dataList);
ob = (*it).pObject;

// get also the properties of the associated view provider
Gui::Document* doc = Gui::Application::Instance->getDocument(it->pDoc);
vp = doc->getViewProvider((*it).pObject);
if(!vp) continue;
vp->getPropertyMap(viewMap);
// get the properties as map here because it doesn't matter to have them sorted alphabetically
vp->getPropertyMap(viewList);
}

// store the properties with <name,id> as key in a map
std::map<std::string,App::Property*>::iterator pt;
std::vector<App::Property*>::iterator pt;
if (ob) {
for (pt = dataMap.begin(); pt != dataMap.end(); ++pt) {
std::pair<std::string, int> nameType = std::make_pair
<std::string, int>(pt->first, pt->second->getTypeId().getKey());
if (!ob->isHidden(pt->second) && !pt->second->StatusBits.test(3))
propDataMap[nameType].push_back(pt->second);
for (pt = dataList.begin(); pt != dataList.end(); ++pt) {
PropInfo nameType;
nameType.propName = ob->getName(*pt);
nameType.propId = (*pt)->getTypeId().getKey();

if (!ob->isHidden(*pt) && !(*pt)->StatusBits.test(3)) {
std::vector<PropInfo>::iterator pi = std::find_if(propDataMap.begin(), propDataMap.end(), PropFind(nameType));
if (pi != propDataMap.end()) {
pi->propList.push_back(*pt);
}
else {
nameType.propList.push_back(*pt);
propDataMap.push_back(nameType);
}
}
}
}
// the same for the view properties
if (vp) {
for(pt = viewMap.begin(); pt != viewMap.end(); ++pt) {
std::pair<std::string, int> nameType = std::make_pair
<std::string, int>( pt->first, pt->second->getTypeId().getKey());
if (!vp->isHidden(pt->second) && !pt->second->StatusBits.test(3))
propViewMap[nameType].push_back(pt->second);
std::map<std::string, App::Property*>::iterator pt;
for (pt = viewList.begin(); pt != viewList.end(); ++pt) {
PropInfo nameType;
nameType.propName = pt->first;
nameType.propId = pt->second->getTypeId().getKey();

if (!vp->isHidden(pt->second) && !pt->second->StatusBits.test(3)) {
std::vector<PropInfo>::iterator pi = std::find_if(propViewMap.begin(), propViewMap.end(), PropFind(nameType));
if (pi != propViewMap.end()) {
pi->propList.push_back(pt->second);
}
else {
nameType.propList.push_back(pt->second);
propViewMap.push_back(nameType);
}
}
}
}
}

// the property must be part of each selected object, i.e. the number
// of selected objects is equal to the number of properties with same
// name and id
std::map<std::pair<std::string, int>, std::vector<App::Property*> >
::const_iterator it;
std::map<std::string, std::vector<App::Property*> > dataProps;
std::vector<PropInfo>::const_iterator it;
PropertyModel::PropertyList dataProps;
for (it = propDataMap.begin(); it != propDataMap.end(); ++it) {
if (it->second.size() == array.size()) {
dataProps[it->first.first] = it->second;
if (it->propList.size() == array.size()) {
dataProps.push_back(std::make_pair(it->propName, it->propList));
}
}
propertyEditorData->buildUp(dataProps);

std::map<std::string, std::vector<App::Property*> > viewProps;
PropertyModel::PropertyList viewProps;
for (it = propViewMap.begin(); it != propViewMap.end(); ++it) {
if (it->second.size() == array.size()) {
viewProps[it->first.first] = it->second;
if (it->propList.size() == array.size()) {
viewProps.push_back(std::make_pair(it->propName, it->propList));
}
}
propertyEditorView->buildUp(viewProps);
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/PropertyView.h
Expand Up @@ -69,6 +69,8 @@ class PropertyView : public QWidget, public Gui::SelectionObserver
void onSelectionChanged(const SelectionChanges& msg);

private:
struct PropInfo;
struct PropFind;
QTabWidget* tabs;
};

Expand Down
4 changes: 2 additions & 2 deletions src/Gui/propertyeditor/PropertyEditor.cpp
Expand Up @@ -89,7 +89,7 @@ void PropertyEditor::commitData (QWidget * editor)
committing = false;
if (delaybuild) {
delaybuild = false;
propertyModel->buildUp(std::map<std::string, std::vector<App::Property*> >());
propertyModel->buildUp(PropertyModel::PropertyList());
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ void PropertyEditor::drawBranches(QPainter *painter, const QRect &rect, const QM
//painter->setPen(savedPen);
}

void PropertyEditor::buildUp(const std::map<std::string, std::vector<App::Property*> >& props)
void PropertyEditor::buildUp(const PropertyModel::PropertyList& props)
{
if (committing) {
Base::Console().Warning("While committing the data to the property the selection has changed.\n");
Expand Down
3 changes: 2 additions & 1 deletion src/Gui/propertyeditor/PropertyEditor.h
Expand Up @@ -31,6 +31,7 @@
#include <QTreeView>

#include "PropertyItem.h"
#include "PropertyModel.h"

namespace App {
class Property;
Expand All @@ -49,7 +50,7 @@ class PropertyEditor : public QTreeView
~PropertyEditor();

/** Builds up the list view with the properties. */
void buildUp(const std::map<std::string, std::vector<App::Property*> >& props);
void buildUp(const PropertyModel::PropertyList& props);
void setAutomaticDocumentUpdate(bool);
bool isAutomaticDocumentUpdate(bool) const;

Expand Down
5 changes: 2 additions & 3 deletions src/Gui/propertyeditor/PropertyModel.cpp
Expand Up @@ -199,15 +199,14 @@ QModelIndex PropertyModel::propertyIndexFromPath(const QStringList& path) const
return parent;
}

void PropertyModel::buildUp(const std::map<std::string, std::vector<App::Property*> >& props)
void PropertyModel::buildUp(const PropertyModel::PropertyList& props)
{
// fill up the listview with the properties
rootItem->reset();

// sort the properties into their groups
std::map<std::string, std::vector<std::vector<App::Property*> > > propGroup;
std::map<std::string, std::vector<App::Property*> >
::const_iterator jt;
PropertyModel::PropertyList::const_iterator jt;
for (jt = props.begin(); jt != props.end(); ++jt) {
App::Property* prop = jt->second.front();
const char* group = prop->getGroup();
Expand Down
4 changes: 3 additions & 1 deletion src/Gui/propertyeditor/PropertyModel.h
Expand Up @@ -41,6 +41,8 @@ class PropertyModel : public QAbstractItemModel
Q_OBJECT

public:
typedef std::vector< std::pair< std::string, std::vector<App::Property*> > > PropertyList;

PropertyModel(QObject* parent);
virtual ~PropertyModel();

Expand All @@ -54,7 +56,7 @@ class PropertyModel : public QAbstractItemModel
int rowCount (const QModelIndex & parent = QModelIndex()) const;
QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
bool setHeaderData (int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole);
void buildUp(const std::map<std::string, std::vector<App::Property*> >& props);
void buildUp(const PropertyList& props);
QStringList propertyPathFromIndex(const QModelIndex&) const;
QModelIndex propertyIndexFromPath(const QStringList&) const;

Expand Down

0 comments on commit 2bfb120

Please sign in to comment.