PropertyView.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QGridLayout>
00027 # include <QHeaderView>
00028 # include <QEvent>
00029 #endif
00030 
00032 
00033 #include <App/PropertyStandard.h>
00034 #include <App/PropertyGeo.h>
00035 #include <App/PropertyLinks.h>
00036 #include <App/PropertyContainer.h>
00037 #include <App/DocumentObject.h>
00038 #include <App/Document.h>
00039 
00040 #include "PropertyView.h"
00041 #include "Application.h"
00042 #include "Document.h"
00043 #include "BitmapFactory.h"
00044 #include "ViewProvider.h"
00045 
00046 #include "propertyeditor/PropertyEditor.h"
00047 
00048 using namespace std;
00049 using namespace Gui;
00050 using namespace Gui::DockWnd;
00051 using namespace Gui::PropertyEditor;
00052 
00053 
00054 /* TRANSLATOR Gui::PropertyView */
00055 
00056 PropertyView::PropertyView(QWidget *parent)
00057   : QWidget(parent)
00058 {
00059     QGridLayout* pLayout = new QGridLayout( this ); 
00060     pLayout->setSpacing(0);
00061     pLayout->setMargin (0);
00062 
00063     tabs = new QTabWidget (this);
00064     tabs->setObjectName(QString::fromUtf8("propertyTab"));
00065     tabs->setTabPosition(QTabWidget::South);
00066     tabs->setTabShape(QTabWidget::Triangular);
00067     pLayout->addWidget(tabs, 0, 0);
00068 
00069     propertyEditorView = new Gui::PropertyEditor::PropertyEditor();
00070     propertyEditorView->setAutomaticDocumentUpdate(false);
00071     tabs->addTab(propertyEditorView, tr("View"));
00072     propertyEditorData = new Gui::PropertyEditor::PropertyEditor();
00073     propertyEditorData->setAutomaticDocumentUpdate(true);
00074     tabs->addTab(propertyEditorData, tr("Data"));
00075 }
00076 
00077 PropertyView::~PropertyView()
00078 {
00079 }
00080 
00081 void PropertyView::onSelectionChanged(const SelectionChanges& msg)
00082 {
00083     if (msg.Type != SelectionChanges::AddSelection &&
00084         msg.Type != SelectionChanges::RmvSelection &&
00085         msg.Type != SelectionChanges::SetSelection &&
00086         msg.Type != SelectionChanges::ClrSelection)
00087         return;
00088     // group the properties by <name,id>
00089     std::map<std::pair<std::string, int>, std::vector<App::Property*> > propDataMap;
00090     std::map<std::pair<std::string, int>, std::vector<App::Property*> > propViewMap;
00091     std::vector<SelectionSingleton::SelObj> array = Gui::Selection().getCompleteSelection();
00092     for (std::vector<SelectionSingleton::SelObj>::const_iterator it = array.begin(); it != array.end(); ++it) {
00093         App::DocumentObject *ob=0;
00094         ViewProvider *vp=0;
00095 
00096         std::map<std::string,App::Property*> dataMap;
00097         std::map<std::string,App::Property*> viewMap;
00098         if ((*it).pObject) {
00099             (*it).pObject->getPropertyMap(dataMap);
00100             ob = (*it).pObject;
00101 
00102             // get also the properties of the associated view provider
00103             Gui::Document* doc = Gui::Application::Instance->getDocument(it->pDoc);
00104             vp = doc->getViewProvider((*it).pObject);
00105             if(!vp) continue;
00106             vp->getPropertyMap(viewMap);
00107         }
00108 
00109         // store the properties with <name,id> as key in a map
00110         std::map<std::string,App::Property*>::iterator pt;
00111         if (ob) {
00112             for (pt = dataMap.begin(); pt != dataMap.end(); ++pt) {
00113                 std::pair<std::string, int> nameType = std::make_pair
00114                     <std::string, int>(pt->first, pt->second->getTypeId().getKey());
00115                 if (!ob->isHidden(pt->second))
00116                     propDataMap[nameType].push_back(pt->second);
00117             }
00118         }
00119         // the same for the view properties
00120         if (vp) {
00121             for(pt = viewMap.begin(); pt != viewMap.end(); ++pt) {
00122                 std::pair<std::string, int> nameType = std::make_pair
00123                     <std::string, int>( pt->first, pt->second->getTypeId().getKey());
00124                 if (!vp->isHidden(pt->second))
00125                     propViewMap[nameType].push_back(pt->second);
00126             }
00127         }
00128     }
00129 
00130     // the property must be part of each selected object, i.e. the number
00131     // of selected objects is equal to the number of properties with same
00132     // name and id
00133     std::map<std::pair<std::string, int>, std::vector<App::Property*> >
00134         ::const_iterator it;
00135     std::map<std::string, std::vector<App::Property*> > dataProps;
00136     for (it = propDataMap.begin(); it != propDataMap.end(); ++it) {
00137         if (it->second.size() == array.size()) {
00138             dataProps[it->first.first] = it->second;
00139         }
00140     }
00141     propertyEditorData->buildUp(dataProps);
00142 
00143     std::map<std::string, std::vector<App::Property*> > viewProps;
00144     for (it = propViewMap.begin(); it != propViewMap.end(); ++it) {
00145         if (it->second.size() == array.size()) {
00146             viewProps[it->first.first] = it->second;
00147         }
00148     }
00149     propertyEditorView->buildUp(viewProps);
00150 }
00151 
00152 void PropertyView::changeEvent(QEvent *e)
00153 {
00154     if (e->type() == QEvent::LanguageChange) {
00155         tabs->setTabText(0, trUtf8("View"));
00156         tabs->setTabText(1, trUtf8("Data"));
00157     }
00158 
00159     QWidget::changeEvent(e);
00160 }
00161 
00162 /* TRANSLATOR Gui::DockWnd::PropertyDockView */
00163 
00164 PropertyDockView::PropertyDockView(Gui::Document* pcDocument, QWidget *parent)
00165   : DockWindow(pcDocument,parent)
00166 {
00167     setWindowTitle(tr("Property View"));
00168 
00169     PropertyView* view = new PropertyView(this);
00170     QGridLayout* pLayout = new QGridLayout(this);
00171     pLayout->setSpacing(0);
00172     pLayout->setMargin (0);
00173     pLayout->addWidget(view, 0, 0);
00174 
00175     resize( 200, 400 );
00176 }
00177 
00178 PropertyDockView::~PropertyDockView()
00179 {
00180 }
00181 
00182 #include "moc_PropertyView.cpp"

Generated on Wed Nov 23 19:00:31 2011 for FreeCAD by  doxygen 1.6.1