MapVisibilityWidget.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2010-2016, Mathieu Labbe - IntRoLab - Universite de Sherbrooke
00003 All rights reserved.
00004 
00005 Redistribution and use in source and binary forms, with or without
00006 modification, are permitted provided that the following conditions are met:
00007     * Redistributions of source code must retain the above copyright
00008       notice, this list of conditions and the following disclaimer.
00009     * Redistributions in binary form must reproduce the above copyright
00010       notice, this list of conditions and the following disclaimer in the
00011       documentation and/or other materials provided with the distribution.
00012     * Neither the name of the Universite de Sherbrooke nor the
00013       names of its contributors may be used to endorse or promote products
00014       derived from this software without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00017 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00018 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
00020 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00021 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00022 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00023 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00024 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00025 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 */
00027 
00028 #include "rtabmap/gui/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) && iter->first > 0)
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         Q_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 } /* namespace rtabmap */


rtabmap
Author(s): Mathieu Labbe
autogenerated on Thu Jun 6 2019 21:59:20