diff --git a/src/Gui/PropertyView.cpp b/src/Gui/PropertyView.cpp index 776da73f2..e126cd075 100644 --- a/src/Gui/PropertyView.cpp +++ b/src/Gui/PropertyView.cpp @@ -28,6 +28,8 @@ # include #endif +#include + /// Here the FreeCAD includes sorted by Base,App,Gui...... #include #include @@ -90,10 +92,29 @@ PropertyView::PropertyView(QWidget *parent) // connect after adding all tabs, so adding doesn't thrash the parameter connect(tabs, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); + + this->connectPropData = + App::GetApplication().signalChangedObject.connect(boost::bind + (&PropertyView::slotChangePropertyData, this, _1, _2)); + this->connectPropView = + Gui::Application::Instance->signalChangedObject.connect(boost::bind + (&PropertyView::slotChangePropertyView, this, _1, _2)); } PropertyView::~PropertyView() { + this->connectPropData.disconnect(); + this->connectPropView.disconnect(); +} + +void PropertyView::slotChangePropertyData(const App::DocumentObject&, const App::Property& prop) +{ + propertyEditorData->updateProperty(prop); +} + +void PropertyView::slotChangePropertyView(const Gui::ViewProvider&, const App::Property& prop) +{ + propertyEditorView->updateProperty(prop); } struct PropertyView::PropInfo diff --git a/src/Gui/PropertyView.h b/src/Gui/PropertyView.h index a1b59c105..b0aaacf74 100644 --- a/src/Gui/PropertyView.h +++ b/src/Gui/PropertyView.h @@ -28,12 +28,15 @@ #include "DockWindow.h" #include "Selection.h" +#include class QPixmap; class QTabWidget; namespace App { + class Property; class PropertyContainer; + class DocumentObject; } namespace Gui { @@ -47,7 +50,7 @@ class PropertyEditor; } // namespace Gui namespace Gui { - +class ViewProvider; /** The property view class. */ @@ -71,10 +74,15 @@ protected: private: void onSelectionChanged(const SelectionChanges& msg); + void slotChangePropertyData(const App::DocumentObject&, const App::Property&); + void slotChangePropertyView(const Gui::ViewProvider&, const App::Property&); private: struct PropInfo; struct PropFind; + typedef boost::BOOST_SIGNALS_NAMESPACE::connection Connection; + Connection connectPropData; + Connection connectPropView; QTabWidget* tabs; }; diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index 1640c0f43..c56b0b0f8 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -145,4 +145,11 @@ void PropertyEditor::buildUp(const PropertyModel::PropertyList& props) } } +void PropertyEditor::updateProperty(const App::Property& prop) +{ + // forward this to the model if the property is changed from outside + //if (!committing) + propertyModel->updateProperty(prop); +} + #include "moc_PropertyEditor.cpp" diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index 53f004b20..8cea30280 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -51,6 +51,7 @@ public: /** Builds up the list view with the properties. */ void buildUp(const PropertyModel::PropertyList& props); + void updateProperty(const App::Property&); void setAutomaticDocumentUpdate(bool); bool isAutomaticDocumentUpdate(bool) const; diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 23e0ad3bc..279153e5f 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -97,6 +97,15 @@ const std::vector& PropertyItem::getPropertyData() const return propertyItems; } +bool PropertyItem::hasProperty(const App::Property* prop) const +{ + std::vector::const_iterator it = std::find(propertyItems.begin(), propertyItems.end(), prop); + if (it != propertyItems.end()) + return true; + else + return false; +} + App::Property* PropertyItem::getFirstProperty() { if (propertyItems.empty()) diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index fec932ddc..86a100d2d 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -61,6 +61,7 @@ public: /** Sets the current property objects. */ void setPropertyData( const std::vector& ); const std::vector& getPropertyData() const; + bool hasProperty(const App::Property*) const; App::Property* getFirstProperty(); const App::Property* getFirstProperty() const; diff --git a/src/Gui/propertyeditor/PropertyModel.cpp b/src/Gui/propertyeditor/PropertyModel.cpp index 952d94445..f67aaebbb 100644 --- a/src/Gui/propertyeditor/PropertyModel.cpp +++ b/src/Gui/propertyeditor/PropertyModel.cpp @@ -261,4 +261,40 @@ void PropertyModel::buildUp(const PropertyModel::PropertyList& props) reset(); } +void PropertyModel::updateProperty(const App::Property& prop) +{ + int column = 1; + int numChild = rootItem->childCount(); + for (int row=0; rowchild(row); + if (child->hasProperty(&prop)) { + QModelIndex data = this->index(row, column, QModelIndex()); + if (data.isValid()) { + dataChanged(data, data); + updateChildren(child, column, data); + } + break; + } + } +} + +void PropertyModel::updateChildren(PropertyItem* item, int column, const QModelIndex& parent) +{ + int numChild = item->childCount(); + if (numChild > 0) { + QModelIndex topLeft = this->index(0, column, parent); + QModelIndex bottomRight = this->index(numChild, column, parent); + dataChanged(topLeft, bottomRight); +#if 0 // It seems we don't have to inform grand children + for (int row=0; rowchild(row); + QModelIndex data = this->index(row, column, parent); + if (data.isValid()) { + updateChildren(child, column, data); + } + } +#endif + } +} + #include "moc_PropertyModel.cpp" diff --git a/src/Gui/propertyeditor/PropertyModel.h b/src/Gui/propertyeditor/PropertyModel.h index 9d7282112..ea4d56d70 100644 --- a/src/Gui/propertyeditor/PropertyModel.h +++ b/src/Gui/propertyeditor/PropertyModel.h @@ -57,9 +57,13 @@ public: 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 PropertyList& props); + void updateProperty(const App::Property&); QStringList propertyPathFromIndex(const QModelIndex&) const; QModelIndex propertyIndexFromPath(const QStringList&) const; +private: + void updateChildren(PropertyItem* item, int column, const QModelIndex& parent); + private: PropertyItem *rootItem; };