ObjectList.cpp
Go to the documentation of this file.
00001 /*******************************************************************************
00002 *  ObjectList.cpp
00003 *
00004 *  (C) 2008 AG Aktives Sehen <agas@uni-koblenz.de>
00005 *           Universitaet Koblenz-Landau
00006 *
00007 *  §Author: SG;
00008 *
00009 *******************************************************************************/
00010 
00011 #include "ObjectList.h"
00012 
00013 #include <vector>
00014 #include <string>
00015 #include <QWidget>
00016 #include <QPushButton>
00017 #include <QVBoxLayout>
00018 #include <QString>
00019 #include <QTableWidget>
00020 #include <QHeaderView>
00021 #include <QFileDialog>
00022 #include <QGroupBox>
00023 #include <QLabel>
00024 #include <QMessageBox>
00025 
00026 #include <ros/ros.h>
00027 
00028 //TODO
00029 //#include "Messages/ORObjectPropertiesM.h"
00030 //#include "Messages/ORObjectNamesM.h"
00031 //#include "Messages/ORCommandM.h"
00032 
00033 #include "../../Workers/ObjectRecognition/ObjectProperties.h"
00034 
00035 //#include "Architecture/Serializer/BinaryInStream.h"
00036 //#include "Architecture/Serializer/ExtendedInStream.h"
00037 
00038 //included for debug Purposes
00039 #include <iostream>
00040 #include <fstream>
00041 
00042 #define THIS ObjectList
00043 
00044 
00045 THIS::THIS(QWidget *parent): QWidget( parent )
00046 {
00047 
00048   setMinimumSize(100,100);
00049 
00050     QPushButton* loadObjectButton;
00051 
00052     loadObjectButton = new QPushButton("Load");
00053     deleteObjectButton = new QPushButton("Delete");;
00054     deleteObjectButton->setEnabled(false);
00055 
00056     m_objectsList = new QTableWidget();
00057     m_objectsList->setColumnCount ( 2 );
00058     m_objectsList->setRowCount( 0 );
00059     QStringList headerList;
00060     headerList << "Name" << "Type";
00061     m_objectsList->setHorizontalHeaderLabels (headerList);
00062     m_objectsList->horizontalHeader()->setResizeMode(0, QHeaderView::Interactive);
00063     m_objectsList->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch);
00064     m_objectsList->verticalHeader()->hide();
00065     m_objectsList->setSelectionBehavior(QAbstractItemView::SelectRows);
00066     m_objectsList->setSortingEnabled(true);
00067 
00068     //create main layout
00069     QVBoxLayout* mainLayout = new QVBoxLayout();
00070 
00071     QGridLayout* listLayout = new QGridLayout();
00072     listLayout->addWidget(m_objectsList,0,0,1,2);
00073     listLayout->addWidget(loadObjectButton,1,0);
00074     listLayout->addWidget(deleteObjectButton,1,1);
00075 
00076     heading=new QLabel( "Objects (0)" );
00077     QFont font;
00078     font.setBold(true);
00079     heading->setFont(font);
00080 
00081     mainLayout->addWidget( heading );
00082     mainLayout->addLayout( listLayout );
00083     mainLayout->setSpacing(0);
00084     setLayout(mainLayout);
00085 
00086     //signal slot connections
00087     connect(loadObjectButton,SIGNAL(clicked()),this,SLOT(loadObject()));
00088     connect(deleteObjectButton,SIGNAL(clicked()),this,SLOT(deleteObject()));
00089 
00090     m_LastOpenPath = "/objectProperties"; // TODO check whether path is correct
00091 }
00092 
00093 THIS::~THIS(){}
00094 
00095 // TODO
00096 //void THIS::processMessage( Message* newMessage )
00097 //{
00098 //    switch(newMessage->getType()) {
00099 
00100 //    case MessageTypes::OR_OBJECT_NAMES_M:
00101 //        {
00102 //            if (ORObjectNamesM* message=Message::castTo<ORObjectNamesM>(newMessage))
00103 //            {
00104 //                map<string,string> names = message->getNames();
00105 
00106 //                m_objectsList->setRowCount( 0 );
00107 
00108 //                m_objectsList->setSortingEnabled(false);
00109 
00110 //                map<string,string>::iterator it;
00111 //                for ( it=names.begin() ; it != names.end(); it++ )
00112 //                {
00113 //                    QString objectName = QString((*it).first.c_str());
00114 
00115 //                    int indexRow = m_objectsList->rowCount();
00116 //                    QColor rowColor(235,235,235);
00117 
00118 //                    //create item with object name
00119 //                    m_objectsList->insertRow (indexRow);
00120 //                    QTableWidgetItem* item = new QTableWidgetItem(objectName);
00121 //                    item->setBackground(rowColor);
00122 //                    item->setFlags(Qt::ItemIsSelectable);
00123 //                    m_objectsList->setItem (indexRow,0,item);
00124 
00125 //                    //create item with object type
00126 //                    item = new QTableWidgetItem(QString((*it).second.c_str()));
00127 //                    item->setBackground(rowColor);
00128 //                    item->setFlags(Qt::ItemIsSelectable);
00129 //                    item->setTextAlignment(Qt::AlignCenter);
00130 //                    m_objectsList->setItem (indexRow,1,item);
00131 
00132 //                    //select row in table that was just added
00133 //                    m_objectsList->selectRow(indexRow);
00134 //                    m_objectsList->scrollToItem(m_objectsList->item(indexRow,0), QAbstractItemView::EnsureVisible);
00135 //                }
00136 //                m_objectsList->setSortingEnabled(true);
00137 //                deleteObjectButton->setEnabled(m_objectsList->rowCount()>0);
00138 //                heading->setText("Objects ("+QString::number(m_objectsList->rowCount()) +")");
00139 //            }
00140 //        } break;
00141 
00142 //    default:
00143 //        break;
00144 
00145 //    }
00146 //}
00147 
00148 void THIS::deleteObject(){
00149     m_objectsList->setSortingEnabled(false);
00150 
00151     QList<QTableWidgetItem *> selectedItems = m_objectsList->selectedItems();
00152 
00153     int i=0;
00154     while(i<m_objectsList->rowCount())
00155     {
00156         if(selectedItems.contains(m_objectsList->item(i,0)))
00157         {
00158             // TODO
00159             //sendMessage(new ORCommandM( ORCommandM::UnloadObject, m_objectsList->item(i,0)->text().toStdString()));
00160             m_objectsList->removeRow(i);
00161             --i;
00162         }
00163         ++i;
00164     }
00165     m_objectsList->setSortingEnabled(true);
00166     deleteObjectButton->setEnabled(m_objectsList->rowCount()>0);
00167     heading->setText("Objects ("+QString::number(m_objectsList->rowCount()) +")");
00168 }
00169 
00170 void THIS::loadObject() // TODO fix this method to load objects!!!!
00171 {
00172     QStringList files = QFileDialog::getOpenFileNames(this, tr("Load Object"), m_LastOpenPath,"Objectproperties (*.objprop)");
00173 
00174     for (int i = 0; i < files.size(); i++)
00175     {
00176         QString file=files.at(i);
00177         QDir fileDir( file );
00178         fileDir.cdUp();
00179         m_LastOpenPath = fileDir.absolutePath();
00180 
00181         std::ifstream in(file.toStdString().c_str());
00182 
00183         ROS_INFO_STREAM("file: " << file.toStdString());
00184 
00185 
00186 
00187 
00188         // TODO this is needed to load objects !!!
00189 //        BinaryInStream binIn(in);
00190 //        ExtendedInStream extStrm( binIn );
00191 //        ObjectProperties* objectProperties = new ObjectProperties(extStrm);
00192 //        in.close();
00193 
00194 //        bool addObject = true;
00195 //        QString objectName = QString(objectProperties->getName().c_str());
00196 
00197 //        m_objectsList->setSortingEnabled(false);
00198 //        for(int j=0;j<m_objectsList->rowCount();++j)
00199 //        {
00200 //            if(m_objectsList->item(j,0)->text()==(objectName))
00201 //            {
00202  //               addObject = false;
00203 //                break;
00204 //            }
00205 //        }
00206 //        m_objectsList->setSortingEnabled(true);
00207 
00208 
00209 //        //add object only if it wasn't already added
00210 //        if(addObject){
00211 //            // TODO
00212 //            //ORObjectPropertiesM* message = new ORObjectPropertiesM( objectProperties );
00213 //            //sendMessage(message);
00214 //        }
00215 //        else
00216 //        {
00217 //            //Display information if object was already to the table
00218 //            QMessageBox m(this);
00219 //            m.setIcon(QMessageBox::Information);
00220 //            m.setText("Object '" + objectName + "' is already inserted.");
00221 //            m.exec();
00222 //        }
00223     }
00224 }
00225 
00226 #undef THIS


obj_rec_gui
Author(s): AGAS/agas@uni-koblenz.de
autogenerated on Mon Oct 6 2014 02:53:43