PropertyView.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
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
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
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
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
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
00131
00132
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
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"