CurveColorConfig.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 <rqt_multiplot/ColorOperations.h>
00020 
00021 #include "rqt_multiplot/CurveColorConfig.h"
00022 
00023 namespace rqt_multiplot {
00024 
00025 /*****************************************************************************/
00026 /* Constructors and Destructor                                               */
00027 /*****************************************************************************/
00028 
00029 CurveColorConfig::CurveColorConfig(QObject* parent, Type type, unsigned char
00030     autoColorIndex, const QColor& customColor) :
00031   Config(parent),
00032   type_(type),
00033   autoColorIndex_(autoColorIndex),
00034   customColor_(customColor) {
00035 }
00036 
00037 CurveColorConfig::~CurveColorConfig() {
00038 }
00039 
00040 /*****************************************************************************/
00041 /* Accessors                                                                 */
00042 /*****************************************************************************/
00043 
00044 void CurveColorConfig::setType(Type type) {
00045   if (type != type_) {
00046     type_ = type;
00047     
00048     emit typeChanged(type);
00049     emit currentColorChanged(getCurrentColor());
00050     emit changed();
00051   }
00052 }
00053 
00054 CurveColorConfig::Type CurveColorConfig::getType() const {
00055   return type_;
00056 }
00057 
00058 void CurveColorConfig::setAutoColorIndex(unsigned char index) {
00059   if (index != autoColorIndex_) {
00060     autoColorIndex_ = index;
00061     
00062     emit autoColorIndexChanged(index);
00063     emit currentColorChanged(getCurrentColor());
00064     emit changed();
00065   }
00066 }
00067 
00068 unsigned char CurveColorConfig::getAutoColorIndex() const {
00069   return autoColorIndex_;
00070 }
00071 
00072 void CurveColorConfig::setCustomColor(const QColor& color) {
00073   if (color != customColor_) {
00074     customColor_ = color;
00075     
00076     emit customColorChanged(color);
00077     if (type_ == Custom)
00078       emit currentColorChanged(getCurrentColor());
00079     emit changed();
00080   }
00081 }
00082 
00083 const QColor& CurveColorConfig::getCustomColor() const {
00084   return customColor_;
00085 }
00086 
00087 QColor CurveColorConfig::getCurrentColor() const {
00088   if (type_ == Auto)
00089     return ColorOperations::intToRgb(autoColorIndex_);
00090   else
00091     return customColor_;
00092 }
00093 
00094 /*****************************************************************************/
00095 /* Methods                                                                   */
00096 /*****************************************************************************/
00097 
00098 void CurveColorConfig::save(QSettings& settings) const {
00099   settings.setValue("type", type_);
00100   settings.setValue("custom_color", QVariant::fromValue<QColor>(
00101     customColor_));
00102 }
00103 
00104 void CurveColorConfig::load(QSettings& settings) {
00105   setType(static_cast<Type>(settings.value("type", Auto).toInt()));
00106   setCustomColor(settings.value("custom_color", QColor(Qt::black)).
00107     value<QColor>());
00108 }
00109 
00110 void CurveColorConfig::reset() {
00111   setType(Auto);
00112   setCustomColor(Qt::black);
00113 }
00114 
00115 void CurveColorConfig::write(QDataStream& stream) const {
00116   stream << type_;
00117   stream << customColor_;
00118 }
00119 
00120 void CurveColorConfig::read(QDataStream& stream) {
00121   int type;
00122   QColor customColor;
00123   
00124   stream >> type;
00125   setType(static_cast<Type>(type));
00126   stream >> customColor;
00127   setCustomColor(customColor);
00128 }
00129 
00130 /*****************************************************************************/
00131 /* Operators                                                                 */
00132 /*****************************************************************************/
00133 
00134 CurveColorConfig& CurveColorConfig::operator=(const CurveColorConfig& src) {
00135   setType(src.type_);
00136   setAutoColorIndex(src.autoColorIndex_);
00137   setCustomColor(src.customColor_);
00138   
00139   return *this;
00140 }
00141 
00142 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Tue May 9 2017 02:16:02