+ fixes #0001063: Show a PropertyLink in Property view

This commit is contained in:
wmayer 2014-03-13 14:28:53 +01:00
parent ded5d43428
commit 2aa2cb3fa6
6 changed files with 360 additions and 10 deletions

View File

@ -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

151
src/Gui/DlgPropertyLink.cpp Normal file
View File

@ -0,0 +1,151 @@
/***************************************************************************
* Copyright (c) 2014 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <algorithm>
# include <sstream>
# include <QListWidgetItem>
# include <QMessageBox>
#endif
#include <App/Application.h>
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/GeoFeature.h>
#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<QListWidgetItem*> 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<QListWidgetItem*> 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<App::DocumentObject*> outList;
App::DocumentObject* par = doc->getObject((const char*)parName.toLatin1());
if (par) {
outList = par->getOutList();
outList.push_back(par);
}
std::vector<App::DocumentObject*> obj = doc->getObjectsOfType(baseType);
for (std::vector<App::DocumentObject*>::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"

59
src/Gui/DlgPropertyLink.h Normal file
View File

@ -0,0 +1,59 @@
/***************************************************************************
* Copyright (c) 2014 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <QDialog>
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

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Gui::Dialog::DlgPropertyLink</class>
<widget class="QDialog" name="Gui::Dialog::DlgPropertyLink">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>257</width>
<height>428</height>
</rect>
</property>
<property name="windowTitle">
<string>Link</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QListWidget" name="listWidget"/>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkObjectType">
<property name="text">
<string>Show all object types</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Gui::Dialog::DlgPropertyLink</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>128</x>
<y>406</y>
</hint>
<hint type="destinationlabel">
<x>128</x>
<y>213</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Gui::Dialog::DlgPropertyLink</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>128</x>
<y>406</y>
</hint>
<hint type="destinationlabel">
<x>128</x>
<y>213</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -32,6 +32,7 @@
# include <QPixmap>
# include <QSpinBox>
# include <QTextStream>
# include <QTimer>
#endif
#include <Base/Tools.h>
@ -48,6 +49,7 @@
#include <Gui/ViewProviderDocumentObject.h>
#include <Gui/Placement.h>
#include <Gui/FileDialog.h>
#include <Gui/DlgPropertyLink.h>
#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(
"<html><head><style type=\"text/css\">"
"p, li { white-space: pre-wrap; }"
@ -1988,21 +2009,32 @@ void LinkLabel::setPropertyLink(const QStringList& o)
"<span> </span>"
"<a href=\"@__edit_link_prop__@\"><span style=\" text-decoration: underline; color:#0000ff;\">%4</span></a>"
"</p></body></html>"
).arg(o[0]).arg(o[1]).arg(o[2]).arg(tr("Edit..."));
)
.arg(link[0])
.arg(link[1])
.arg(link[2])
.arg(tr("Edit..."));
setText(text);
}
QStringList LinkLabel::propertyLink() const
{
return object;
return link;
}
void LinkLabel::onLinkActivated (const QString& s)
{
if (s == QLatin1String("@__edit_link_prop__@"))
QMessageBox::warning(this, QLatin1String("Not yet implemented"), QLatin1String("Not yet implemented"));
else
Gui::Selection().addSelection((const char*)object[0].toAscii(), (const char*)object[1].toAscii());
if (s == QLatin1String("@__edit_link_prop__@")) {
Gui::Dialog::DlgPropertyLink dlg(link, this);
if (dlg.exec() == QDialog::Accepted) {
setPropertyLink(dlg.propertyLink());
/*emit*/ linkChanged(link);
}
}
else {
LinkSelection* select = new LinkSelection(link);
QTimer::singleShot(50, select, SLOT(select()));
}
}
TYPESYSTEM_SOURCE(Gui::PropertyEditor::PropertyLinkItem, Gui::PropertyEditor::PropertyItem);
@ -2022,6 +2054,8 @@ QVariant PropertyLinkItem::value(const App::Property* prop) const
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyLink::getClassTypeId()));
const App::PropertyLink* prop_link = static_cast<const App::PropertyLink*>(prop);
App::PropertyContainer* c = prop_link->getContainer();
App::DocumentObject* obj = prop_link->getValue();
QStringList list;
if (obj) {
@ -2030,7 +2064,8 @@ QVariant PropertyLinkItem::value(const App::Property* prop) const
list << QString::fromUtf8(obj->Label.getValue());
}
else {
App::PropertyContainer* c = prop_link->getContainer();
// no object assigned
// the document name
if (c->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) {
App::DocumentObject* obj = static_cast<App::DocumentObject*>(c);
list << QString::fromAscii(obj->getDocument()->getName());
@ -2038,10 +2073,21 @@ QVariant PropertyLinkItem::value(const App::Property* prop) const
else {
list << QString::fromAscii("");
}
// the internal object name
list << QString::fromAscii("Null");
// the object label
list << QString::fromAscii("");
}
// the name of this object
if (c->getTypeId().isDerivedFrom(App::DocumentObject::getClassTypeId())) {
App::DocumentObject* obj = static_cast<App::DocumentObject*>(c);
list << QString::fromAscii(obj->getNameInDocument());
}
else {
list << QString::fromAscii("Null");
}
return QVariant(list);
}
@ -2062,7 +2108,7 @@ QWidget* PropertyLinkItem::createEditor(QWidget* parent, const QObject* receiver
{
LinkLabel *ll = new LinkLabel(parent);
ll->setAutoFillBackground(true);
//QObject::connect(cb, SIGNAL(activated(int)), receiver, method);
QObject::connect(ll, SIGNAL(linkChanged(const QStringList&)), receiver, method);
return ll;
}

View File

@ -608,6 +608,21 @@ protected:
virtual QVariant toolTip(const App::Property*) const;
};
class LinkSelection : public QObject
{
Q_OBJECT
public:
LinkSelection(const QStringList&);
~LinkSelection();
public Q_SLOTS:
void select();
private:
QStringList link;
};
class LinkLabel : public QLabel
{
Q_OBJECT
@ -621,8 +636,11 @@ public:
protected Q_SLOTS:
void onLinkActivated(const QString&);
Q_SIGNALS:
void linkChanged(const QStringList&);
private:
QStringList object;
QStringList link;
};
/**