diff --git a/src/Gui/CMakeLists.txt b/src/Gui/CMakeLists.txt index f3df6a980..33a26703f 100644 --- a/src/Gui/CMakeLists.txt +++ b/src/Gui/CMakeLists.txt @@ -149,6 +149,7 @@ set(Gui_MOC_HDRS DlgPreferencesImp.h DlgProjectInformationImp.h DlgProjectUtility.h + DlgPropertyLink.h DlgReportViewImp.h DlgSettings3DViewImp.h DlgSettingsViewColor.h @@ -240,6 +241,7 @@ SET(Gui_UIC_SRCS DlgPreferences.ui DlgProjectInformation.ui DlgProjectUtility.ui + DlgPropertyLink.ui DlgReportView.ui DlgSettings3DView.ui DlgSettingsUnits.ui @@ -309,6 +311,7 @@ SET(Dialog_CPP_SRCS DlgParameterImp.cpp DlgProjectInformationImp.cpp DlgProjectUtility.cpp + DlgPropertyLink.cpp DlgTipOfTheDayImp.cpp TaskDlgRelocation.cpp DlgUndoRedo.cpp @@ -338,6 +341,7 @@ SET(Dialog_HPP_SRCS DlgParameterImp.h DlgProjectInformationImp.h DlgProjectUtility.h + DlgPropertyLink.h DlgTipOfTheDayImp.h TaskDlgRelocation.h DlgUndoRedo.h @@ -372,6 +376,7 @@ SET(Dialog_SRCS DlgParameter.ui DlgProjectInformation.ui DlgProjectUtility.ui + DlgPropertyLink.ui DlgTipOfTheDay.ui DlgTreeWidget.ui DownloadManager.ui diff --git a/src/Gui/DlgPropertyLink.cpp b/src/Gui/DlgPropertyLink.cpp new file mode 100644 index 000000000..70c903158 --- /dev/null +++ b/src/Gui/DlgPropertyLink.cpp @@ -0,0 +1,151 @@ +/*************************************************************************** + * Copyright (c) 2014 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" +#ifndef _PreComp_ +# include +# include +# include +# include +#endif + +#include +#include +#include +#include + +#include "DlgPropertyLink.h" +#include "Application.h" +#include "ViewProvider.h" +#include "ui_DlgPropertyLink.h" + + +using namespace Gui::Dialog; + +/* TRANSLATOR Gui::Dialog::DlgPropertyLink */ + +DlgPropertyLink::DlgPropertyLink(const QStringList& list, QWidget* parent, Qt::WFlags fl) + : QDialog(parent, fl), link(list), ui(new Ui_DlgPropertyLink) +{ +#ifdef FC_DEBUG + assert(list.size() == 4); +#endif + ui->setupUi(this); + findObjects(ui->checkObjectType->isChecked()); +} + +/** + * Destroys the object and frees any allocated resources + */ +DlgPropertyLink::~DlgPropertyLink() +{ + // no need to delete child widgets, Qt does it all for us + delete ui; +} + +void DlgPropertyLink::accept() +{ + QList items = ui->listWidget->selectedItems(); + if (items.isEmpty()) { + QMessageBox::warning(this, tr("No selection"), tr("Please select an object of the list")); + } + else { + QDialog::accept(); + } +} + +QStringList DlgPropertyLink::propertyLink() const +{ + QList items = ui->listWidget->selectedItems(); + if (items.isEmpty()) { + return link; + } + else { + QStringList list = link; + list[1] = items[0]->data(Qt::UserRole).toString(); + list[2] = items[0]->text(); + return list; + } +} + +void DlgPropertyLink::findObjects(bool on) +{ + QString docName = link[0]; + QString objName = link[1]; + QString parName = link[3]; + + App::Document* doc = App::GetApplication().getDocument((const char*)docName.toLatin1()); + if (doc) { + Base::Type baseType = App::DocumentObject::getClassTypeId(); + if (!on) { + App::DocumentObject* obj = doc->getObject((const char*)objName.toLatin1()); + if (obj) { + Base::Type objType = obj->getTypeId(); + // get only geometric types + if (objType.isDerivedFrom(App::GeoFeature::getClassTypeId())) + baseType = App::GeoFeature::getClassTypeId(); + + // get the direct base class of App::DocumentObject which 'obj' is derived from + while (!objType.isBad()) { + std::string name = objType.getName(); + Base::Type parType = objType.getParent(); + if (parType == baseType) { + baseType = objType; + break; + } + objType = parType; + } + } + } + + std::vector outList; + App::DocumentObject* par = doc->getObject((const char*)parName.toLatin1()); + if (par) { + outList = par->getOutList(); + outList.push_back(par); + } + + std::vector obj = doc->getObjectsOfType(baseType); + for (std::vector::iterator it = obj.begin(); it != obj.end(); ++it) { + Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(*it); + if (vp) { + // filter out the objects + if (std::find(outList.begin(), outList.end(), *it) == outList.end()) { + QListWidgetItem* item = new QListWidgetItem(ui->listWidget); + item->setIcon(vp->getIcon()); + item->setText(QString::fromUtf8((*it)->Label.getValue())); + QByteArray ba((*it)->getNameInDocument()); + item->setData(Qt::UserRole, ba); + } + } + } + } +} + +void DlgPropertyLink::on_checkObjectType_toggled(bool on) +{ + ui->listWidget->clear(); + findObjects(on); +} + +#include "moc_DlgPropertyLink.cpp" diff --git a/src/Gui/DlgPropertyLink.h b/src/Gui/DlgPropertyLink.h new file mode 100644 index 000000000..0a9fca65b --- /dev/null +++ b/src/Gui/DlgPropertyLink.h @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (c) 2014 Werner Mayer * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#ifndef GUI_DIALOG_DLGPROPERTYLINK_H +#define GUI_DIALOG_DLGPROPERTYLINK_H + +#include + +namespace Gui { namespace Dialog { + +class Ui_DlgPropertyLink; +class DlgPropertyLink : public QDialog +{ + Q_OBJECT + +public: + DlgPropertyLink(const QStringList& list, QWidget* parent = 0, Qt::WFlags fl = 0); + ~DlgPropertyLink(); + + void accept(); + QStringList propertyLink() const; + +private Q_SLOTS: + void on_checkObjectType_toggled(bool); + +private: + void findObjects(bool on); + +private: + QStringList link; + Ui_DlgPropertyLink* ui; +}; + +} // namespace Dialog +} // namespace Gui + + +#endif // GUI_DIALOG_DLGPROPERTYLINK_H + diff --git a/src/Gui/DlgPropertyLink.ui b/src/Gui/DlgPropertyLink.ui new file mode 100644 index 000000000..21a60e4e5 --- /dev/null +++ b/src/Gui/DlgPropertyLink.ui @@ -0,0 +1,71 @@ + + + Gui::Dialog::DlgPropertyLink + + + + 0 + 0 + 257 + 428 + + + + Link + + + + + + + + + Show all object types + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Gui::Dialog::DlgPropertyLink + accept() + + + 128 + 406 + + + 128 + 213 + + + + + buttonBox + rejected() + Gui::Dialog::DlgPropertyLink + reject() + + + 128 + 406 + + + 128 + 213 + + + + + diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 9d0361539..515a500a0 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -32,6 +32,7 @@ # include # include # include +# include #endif #include @@ -48,6 +49,7 @@ #include #include #include +#include #include "PropertyItem.h" @@ -1965,6 +1967,24 @@ QVariant PropertyTransientFileItem::editorData(QWidget *editor) const // --------------------------------------------------------------- +LinkSelection::LinkSelection(const QStringList& list) : link(list) +{ +} + +LinkSelection::~LinkSelection() +{ +} + +void LinkSelection::select() +{ + Gui::Selection().clearSelection(); + Gui::Selection().addSelection((const char*)link[0].toAscii(), + (const char*)link[1].toAscii()); + this->deleteLater(); +} + +// --------------------------------------------------------------- + LinkLabel::LinkLabel (QWidget * parent) : QLabel(parent) { setTextFormat(Qt::RichText); @@ -1978,7 +1998,8 @@ LinkLabel::~LinkLabel() void LinkLabel::setPropertyLink(const QStringList& o) { - object = o; + link = o; + QString text = QString::fromAscii( "