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 <QVBoxLayout> 00027 # include <QListWidget> 00028 # include <QListWidgetItem> 00029 #endif 00030 00032 #include <App/Document.h> 00033 00034 #include "SelectionView.h" 00035 #include "Application.h" 00036 #include "Document.h" 00037 #include "ViewProvider.h" 00038 00039 00040 00041 using namespace Gui; 00042 using namespace Gui::DockWnd; 00043 00044 00045 /* TRANSLATOR Gui::DockWnd::SelectionView */ 00046 00047 SelectionView::SelectionView(Gui::Document* pcDocument, QWidget *parent) 00048 : DockWindow(pcDocument,parent) 00049 { 00050 setWindowTitle( tr( "Property View" ) ); 00051 00052 QVBoxLayout* pLayout = new QVBoxLayout( this ); 00053 pLayout->setSpacing( 0 ); 00054 pLayout->setMargin ( 0 ); 00055 00056 00057 selectionView = new QListWidget(this); 00058 pLayout->addWidget( selectionView); 00059 resize( 200, 200 ); 00060 00061 Gui::Selection().Attach(this); 00062 } 00063 00064 SelectionView::~SelectionView() 00065 { 00066 Gui::Selection().Detach(this); 00067 } 00068 00070 void SelectionView::OnChange(Gui::SelectionSingleton::SubjectType &rCaller, 00071 Gui::SelectionSingleton::MessageType Reason) 00072 { 00073 std::string temp; 00074 00075 if (Reason.Type == SelectionChanges::AddSelection) { 00076 // insert the selection as item 00077 temp = Reason.pDocName; 00078 temp += "."; 00079 temp += Reason.pObjectName; 00080 if (Reason.pSubName[0] != 0 ) { 00081 temp += "."; 00082 temp += Reason.pSubName; 00083 } 00084 00085 new QListWidgetItem(QString::fromAscii(temp.c_str()), selectionView); 00086 } 00087 else if (Reason.Type == SelectionChanges::ClrSelection) { 00088 // remove all items 00089 selectionView->clear(); 00090 } 00091 else if (Reason.Type == SelectionChanges::RmvSelection) { 00092 // build name 00093 temp = Reason.pDocName; 00094 temp += "."; 00095 temp += Reason.pObjectName; 00096 if (Reason.pSubName[0] != 0) { 00097 temp += "."; 00098 temp += Reason.pSubName; 00099 } 00100 00101 // remove all items 00102 QList<QListWidgetItem *> l = selectionView->findItems(QLatin1String(temp.c_str()),Qt::MatchExactly); 00103 if (l.size() == 1) 00104 delete l[0]; 00105 00106 } 00107 else if (Reason.Type == SelectionChanges::SetSelection) { 00108 // remove all items 00109 selectionView->clear(); 00110 std::vector<SelectionSingleton::SelObj> objs = Gui::Selection().getSelection(Reason.pDocName); 00111 for (std::vector<SelectionSingleton::SelObj>::iterator it = objs.begin(); it != objs.end(); ++it) { 00112 // build name 00113 temp = it->DocName; 00114 temp += "."; 00115 temp += it->FeatName; 00116 if (it->SubName && it->SubName[0] != '\0') { 00117 temp += "."; 00118 temp += it->SubName; 00119 } 00120 new QListWidgetItem(QString::fromAscii(temp.c_str()), selectionView); 00121 } 00122 } 00123 } 00124 00125 void SelectionView::onUpdate(void) 00126 { 00127 } 00128 00129 bool SelectionView::onMsg(const char* pMsg) 00130 { 00131 // no messages yet 00132 return false; 00133 } 00135 00136 #include "moc_SelectionView.cpp"