CurveListWidget.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include <QKeyEvent>
00020 
00021 #include "rqt_multiplot/CurveListWidget.h"
00022 
00023 namespace rqt_multiplot {
00024 
00025 /*****************************************************************************/
00026 /* Constructors and Destructor                                               */
00027 /*****************************************************************************/
00028 
00029 CurveListWidget::CurveListWidget(QWidget* parent) :
00030   QListWidget(parent) {
00031 }
00032 
00033 CurveListWidget::~CurveListWidget() {
00034 }
00035 
00036 /*****************************************************************************/
00037 /* Accessors                                                                 */
00038 /*****************************************************************************/
00039 
00040 size_t CurveListWidget::getNumCurves() const {
00041   return count();
00042 }
00043 
00044 CurveItemWidget* CurveListWidget::getCurveItem(size_t index) const {
00045   QListWidgetItem* widgetItem = item(index);
00046   
00047   if (widgetItem)
00048     return static_cast<CurveItemWidget*>(itemWidget(widgetItem));
00049   else
00050     return 0;
00051 }
00052 
00053 /*****************************************************************************/
00054 /* Methods                                                                   */
00055 /*****************************************************************************/
00056 
00057 void CurveListWidget::addCurve(CurveConfig* config) {
00058   CurveItemWidget* itemWidget = new CurveItemWidget(this);
00059   itemWidget->setConfig(config);
00060   
00061   QListWidgetItem* widgetItem = new QListWidgetItem(this);
00062   widgetItem->setSizeHint(itemWidget->sizeHint());
00063 
00064   addItem(widgetItem);
00065   setItemWidget(widgetItem, itemWidget);
00066 
00067   emit curveAdded(row(widgetItem));
00068 }
00069 
00070 void CurveListWidget::removeCurve(size_t index) {
00071   QListWidgetItem* widgetItem = item(index);
00072 
00073   if (widgetItem) {
00074     delete widgetItem;
00075     
00076     emit curveRemoved(index);
00077   }
00078 }
00079 
00080 void CurveListWidget::keyPressEvent(QKeyEvent* event) {
00081   if ((event->modifiers() == Qt::ControlModifier) &&
00082       (event->key() == Qt::Key_A)) {
00083     for (size_t index = 0; index < count(); ++index)
00084       item(index)->setSelected(true);
00085   }
00086   
00087   QListWidget::keyPressEvent(event);
00088 }
00089 
00090 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:10