From e3a65568784b4a590493c388ce5a7638c19da8f6 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 2 Nov 2019 13:02:12 +0800 Subject: [PATCH] App: fix PropertyXLink file path saving Also modified ProeprtyLinkItem to show file path as tooltip. --- src/App/PropertyLinks.cpp | 11 ++++------- src/App/PropertyLinks.h | 4 ++++ src/Gui/propertyeditor/PropertyItem.cpp | 15 ++++++++++++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 5979a1c87f..1eafe40f6c 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -2902,6 +2902,8 @@ void PropertyXLink::setValue(App::DocumentObject *lValue, if(lValue == owner) throw Base::ValueError("self linking"); + aboutToSetValue(); + DocInfoPtr info; const char *name = ""; if(lValue) { @@ -2921,7 +2923,6 @@ void PropertyXLink::setValue(App::DocumentObject *lValue, } setFlag(LinkDetached,false); - aboutToSetValue(); #ifndef USE_OLD_DAG if (!owner->testStatus(ObjectStatus::Destroy) && _pcScope!=LinkScope::Hidden) { if(_pcLink) @@ -2934,9 +2935,7 @@ void PropertyXLink::setValue(App::DocumentObject *lValue, unlink(); docInfo = info; } - if(docInfo) - filePath = docInfo->filePath(); - else + if(!docInfo) filePath.clear(); _pcLink=lValue; if(docInfo && docInfo->pcDoc) @@ -2981,9 +2980,7 @@ void PropertyXLink::setValue(std::string &&filename, std::string &&name, unlink(); docInfo = info; } - if(docInfo) - filePath = docInfo->filePath(); - else + if(!docInfo) filePath.clear(); if(docInfo && docInfo->pcDoc) stamp=docInfo->pcDoc->LastModifiedDate.getValue(); diff --git a/src/App/PropertyLinks.h b/src/App/PropertyLinks.h index 5519113b8c..2406b85e87 100644 --- a/src/App/PropertyLinks.h +++ b/src/App/PropertyLinks.h @@ -1125,6 +1125,10 @@ public: virtual void setAllowPartial(bool enable) override; + const char *getFilePath() const { + return filePath.c_str(); + } + protected: void unlink(); void detach(); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index c55acce3b9..b9ca3bfdb3 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -3625,10 +3625,19 @@ QVariant PropertyLinkItem::toString(const QVariant& prop) const } QVariant PropertyLinkItem::data(int column, int role) const { - if(propertyItems.size() && column == 1 && role == Qt::TextColorRole) { + if(propertyItems.size() && column == 1 + && (role == Qt::TextColorRole || role == Qt::ToolTipRole)) + { auto xlink = Base::freecad_dynamic_cast(propertyItems[0]); - if(xlink && xlink->checkRestore()>1) - return QVariant::fromValue(QColor(0xff,0,0)); + if(xlink) { + if(role==Qt::TextColorRole && xlink->checkRestore()>1) + return QVariant::fromValue(QColor(0xff,0,0)); + else if(role == Qt::ToolTipRole) { + const char *filePath = xlink->getFilePath(); + if(filePath && filePath[0]) + return QVariant::fromValue(QString::fromUtf8(filePath)); + } + } } return PropertyItem::data(column,role); }