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
00025
00026
00027
00028 #include "MapVisibilityWidget.h"
00029
00030 #include <QCheckBox>
00031 #include <QVBoxLayout>
00032 #include <QScrollArea>
00033
00034 #include <rtabmap/utilite/ULogger.h>
00035
00036 namespace rtabmap {
00037
00038 MapVisibilityWidget::MapVisibilityWidget(QWidget * parent) : QWidget(parent) {
00039
00040 QVBoxLayout * verticalLayout1 = new QVBoxLayout(this);
00041 QScrollArea * scrollArea = new QScrollArea(this);
00042 scrollArea->setWidgetResizable(true);
00043 QWidget * scrollAreaWidgetContent = new QWidget();
00044 scrollAreaWidgetContent->setObjectName("area");
00045 QVBoxLayout * layout2 = new QVBoxLayout(scrollAreaWidgetContent);
00046 scrollAreaWidgetContent->setLayout(layout2);
00047 scrollArea->setWidget(scrollAreaWidgetContent);
00048
00049 QCheckBox * selectAll = new QCheckBox("Select all", this);
00050 connect(selectAll, SIGNAL(toggled(bool)), this, SLOT(selectAll(bool)));
00051 verticalLayout1->addWidget(selectAll);
00052 verticalLayout1->addWidget(scrollArea);
00053 }
00054
00055 MapVisibilityWidget::~MapVisibilityWidget() {
00056
00057 }
00058
00059 void MapVisibilityWidget::showEvent(QShowEvent * event)
00060 {
00061 updateCheckBoxes();
00062 }
00063
00064 void MapVisibilityWidget::clear()
00065 {
00066 _poses.clear();
00067 _mask.clear();
00068 updateCheckBoxes();
00069 }
00070
00071 void MapVisibilityWidget::updateCheckBoxes()
00072 {
00073 QWidget * area = this->findChild<QWidget*>("area");
00074 QVBoxLayout * layout = (QVBoxLayout *)area->layout();
00075 QList<QCheckBox*> checkboxes = area->findChildren<QCheckBox*>();
00076 while(checkboxes.size() && checkboxes.size() > (int)_poses.size())
00077 {
00078 delete *checkboxes.begin();
00079 checkboxes.erase(checkboxes.begin());
00080 }
00081 int i=0;
00082 for(std::map<int, Transform>::iterator iter=_poses.begin(); iter!=_poses.end(); ++iter)
00083 {
00084 bool added = false;
00085 if(i >= checkboxes.size())
00086 {
00087 checkboxes.push_back(new QCheckBox(area));
00088 added = true;
00089 }
00090 checkboxes[i]->setText(QString("%1 (%2)").arg(iter->first).arg(iter->second.prettyPrint().c_str()));
00091 checkboxes[i]->setChecked(_mask.at(iter->first));
00092 if(added)
00093 {
00094 connect(checkboxes[i], SIGNAL(stateChanged(int)), this, SLOT(signalVisibility()));
00095 layout->addWidget(checkboxes[i]);
00096 }
00097
00098 ++i;
00099 }
00100 }
00101
00102 void MapVisibilityWidget::setMap(const std::map<int, Transform> & poses, const std::map<int, bool> & mask)
00103 {
00104 UASSERT(poses.size() == mask.size());
00105 _poses = poses;
00106 _mask = mask;
00107 if(this->isVisible())
00108 {
00109 updateCheckBoxes();
00110 }
00111 }
00112
00113 std::map<int, Transform> MapVisibilityWidget::getVisiblePoses() const
00114 {
00115 std::map<int, Transform> poses;
00116 for(std::map<int, Transform>::const_iterator iter=_poses.begin(); iter!=_poses.end(); ++iter)
00117 {
00118 if(_mask.at(iter->first))
00119 {
00120 poses.insert(*iter);
00121 }
00122 }
00123 return poses;
00124 }
00125
00126 void MapVisibilityWidget::signalVisibility()
00127 {
00128 QCheckBox * check = qobject_cast<QCheckBox*>(sender());
00129 _mask.at(check->text().split('(').first().toInt()) = check->isChecked();
00130 emit visibilityChanged(check->text().split('(').first().toInt(), check->isChecked());
00131 }
00132
00133 void MapVisibilityWidget::selectAll(bool checked)
00134 {
00135 QWidget * area = this->findChild<QWidget*>("area");
00136 QList<QCheckBox*> checkboxes = area->findChildren<QCheckBox*>();
00137 for(int i = 0; i<checkboxes.size(); ++i)
00138 {
00139 checkboxes[i]->setChecked(checked);
00140 }
00141 }
00142
00143 }