TaskSelectLinkProperty.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
00026 #ifndef _PreComp_
00027 # include <algorithm>
00028 # include <boost/bind.hpp>
00029 #endif
00030
00031 #include "ui_TaskSelectLinkProperty.h"
00032 #include "TaskSelectLinkProperty.h"
00033 #include <Base/Console.h>
00034 #include <App/DocumentObject.h>
00035 #include <Gui/Application.h>
00036 #include <Gui/Document.h>
00037 #include <Gui/BitmapFactory.h>
00038 #include <Gui/ViewProvider.h>
00039 #include <Gui/WaitCursor.h>
00040 #include <Gui/SelectionFilter.h>
00041
00042 using namespace Gui::TaskView;
00043
00044
00045
00046 TaskSelectLinkProperty::TaskSelectLinkProperty(const char *sFilter,App::Property *prop,QWidget *parent)
00047 : TaskBox(Gui::BitmapFactory().pixmap("mouse_pointer"),tr("edit selection"),true, parent),Filter(0),LinkSub(0),LinkList(0)
00048 {
00049
00050 proxy = new QWidget(this);
00051 ui = new Ui_TaskSelectLinkProperty();
00052 ui->setupUi(proxy);
00053
00054 QMetaObject::connectSlotsByName(this);
00055
00056 this->groupLayout()->addWidget(proxy);
00057 Gui::Selection().Attach(this);
00058
00059 ui->Remove->setIcon(Gui::BitmapFactory().pixmap("delete"));
00060 ui->Add->setIcon(Gui::BitmapFactory().pixmap("add"));
00061 ui->Invert->setIcon(Gui::BitmapFactory().pixmap("edit_remove"));
00062 ui->Help->setIcon(Gui::BitmapFactory().pixmap("help-browser"));
00063
00064
00065 ui->Remove->setDisabled(true);
00066 ui->Add->setDisabled(true);
00067 ui->Invert->setDisabled(true);
00068 ui->Help->setDisabled(true);
00069
00070
00071 assert(prop);
00072 if (prop->getTypeId().isDerivedFrom(App::PropertyLinkSub::getClassTypeId())) {
00073 LinkSub = dynamic_cast<App::PropertyLinkSub *>(prop);
00074 }
00075 else if (prop->getTypeId().isDerivedFrom(App::PropertyLinkList::getClassTypeId())) {
00076 LinkList = dynamic_cast<App::PropertyLinkList *>(prop);
00077 }
00078 else {
00079 Base::Console().Warning("Unknown Link property type in "
00080 "Gui::TaskView::TaskSelectLinkProperty::TaskSelectLinkProperty()");
00081 }
00082
00083 setFilter(sFilter);
00084 }
00085
00086 TaskSelectLinkProperty::~TaskSelectLinkProperty()
00087 {
00088 delete ui;
00089 Gui::Selection().Detach(this);
00090 }
00091
00092 void TaskSelectLinkProperty::changeEvent(QEvent *e)
00093 {
00094 TaskBox::changeEvent(e);
00095 if (e->type() == QEvent::LanguageChange) {
00096 ui->retranslateUi(proxy);
00097 }
00098 }
00099
00101
00102
00103 bool TaskSelectLinkProperty::setFilter(const char * sFilter)
00104 {
00105 Filter = new SelectionFilter(sFilter);
00106 return Filter->isValid();
00107 }
00108
00109
00110 void TaskSelectLinkProperty::activate(void)
00111 {
00112
00113 Gui::Selection().clearSelection();
00114
00115 Gui::Selection().addSelectionGate(new SelectionFilterGate(Filter));
00116
00117
00118 if (LinkSub) {
00119
00120 StartValueBuffer = LinkSub->getSubValues();
00121 StartObject = LinkSub->getValue();
00122 if(StartObject) {
00123 std::string ObjName = StartObject->getNameInDocument();
00124 std::string DocName = StartObject->getDocument()->getName();
00125
00126 for (std::vector<std::string>::const_iterator it = StartValueBuffer.begin();it!=StartValueBuffer.end();++it)
00127 {
00128 Gui::Selection().addSelection(DocName.c_str(),ObjName.c_str(),it->c_str());
00129 }
00130 }
00131
00132 }
00133
00134 else if (LinkList) {
00135
00136 const std::vector<App::DocumentObject*> &Values = LinkList->getValues();
00137 for(std::vector<App::DocumentObject*>::const_iterator it = Values.begin();it!=Values.end();++it)
00138 {
00139 std::string ObjName = (*it)->getNameInDocument();
00140 std::string DocName = (*it)->getDocument()->getName();
00141 Gui::Selection().addSelection(DocName.c_str(),ObjName.c_str());
00142 }
00143 }
00144
00145 checkSelectionStatus();
00146 }
00147
00148 bool TaskSelectLinkProperty::accept(void)
00149 {
00150
00151 sendSelection2Property();
00152
00153
00154 Gui::Selection().clearSelection();
00155 Gui::Selection().rmvSelectionGate();
00156 return true;
00157 }
00158
00159 bool TaskSelectLinkProperty::reject(void)
00160 {
00161 if(LinkSub){
00162
00163 LinkSub->setValue(StartObject,StartValueBuffer);
00164 }
00165
00166
00167 Gui::Selection().clearSelection();
00168 Gui::Selection().rmvSelectionGate();
00169 return true;
00170 }
00171
00172 void TaskSelectLinkProperty::sendSelection2Property(void)
00173 {
00174 if (LinkSub) {
00175 std::vector<Gui::SelectionObject> temp = Gui::Selection().getSelectionEx();
00176 assert(temp.size() >= 1);
00177 LinkSub->setValue(temp[0].getObject(),temp[0].getSubNames());
00178 }
00179 else if (LinkList) {
00180 std::vector<Gui::SelectionObject> sel = Gui::Selection().getSelectionEx();
00181 std::vector<App::DocumentObject*> temp;
00182 for (std::vector<Gui::SelectionObject>::iterator it=sel.begin();it!=sel.end();++it)
00183 temp.push_back(it->getObject());
00184
00185 LinkList->setValues(temp);
00186 }
00187
00188 }
00189
00190 void TaskSelectLinkProperty::checkSelectionStatus(void)
00191 {
00192 QPalette palette(QApplication::palette());
00193
00194 if (Filter->match()) {
00195 palette.setBrush(QPalette::Base,QColor(200,250,200));
00196 emitSelectionFit();
00197 }
00198 else {
00199 palette.setBrush(QPalette::Base,QColor(250,200,200));
00200 emitSelectionMisfit();
00201 }
00202
00203 ui->listWidget->setPalette(palette);
00204 }
00205
00206 void TaskSelectLinkProperty::OnChange(Gui::SelectionSingleton::SubjectType &rCaller,
00207 Gui::SelectionSingleton::MessageType Reason)
00208 {
00209 if (Reason.Type == SelectionChanges::AddSelection ||
00210 Reason.Type == SelectionChanges::RmvSelection ||
00211 Reason.Type == SelectionChanges::SetSelection ||
00212 Reason.Type == SelectionChanges::ClrSelection) {
00213 ui->listWidget->clear();
00214 std::vector<Gui::SelectionSingleton::SelObj> sel = Gui::Selection().getSelection();
00215 for (std::vector<Gui::SelectionSingleton::SelObj>::const_iterator it=sel.begin();it!=sel.end();++it){
00216 std::string temp;
00217 temp += it->FeatName;
00218 if (strcmp(it->SubName, "") != 0){
00219 temp += "::";
00220 temp += it->SubName;
00221 }
00222 new QListWidgetItem(QString::fromAscii(temp.c_str()), ui->listWidget);
00223 }
00224 checkSelectionStatus();
00225 }
00226 }
00228
00229 void TaskSelectLinkProperty::on_Remove_clicked(bool)
00230 {
00231 }
00232
00233 void TaskSelectLinkProperty::on_Add_clicked(bool)
00234 {
00235 }
00236
00237 void TaskSelectLinkProperty::on_Invert_clicked(bool)
00238 {
00239 }
00240
00241 void TaskSelectLinkProperty::on_Help_clicked(bool)
00242 {
00243 }
00244
00245
00246 #include "moc_TaskSelectLinkProperty.cpp"