File indexing completed on 2024-12-22 04:17:44

0001 //
0002 // C++ Interface: rangetab
0003 //
0004 // Description: 
0005 //
0006 //
0007 // Author: Barth Netterfield <netterfield@physics.utoronto.ca>, (C) 2008
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *   This program is free software; you can redistribute it and/or modify  *
0012  *   it under the terms of the GNU General Public License as published by  *
0013  *   the Free Software Foundation; either version 2 of the License, or     *
0014  *   (at your option) any later version.                                   *
0015  *                                                                         *
0016  ***************************************************************************/
0017 #include "rangetab.h"
0018 #include "math_kst.h"
0019 
0020 #include <QDebug>
0021 
0022 namespace Kst {
0023 RangeTab::RangeTab(PlotItem* plotItem, QWidget *parent) 
0024     : DialogTab(parent), _plotItem(plotItem) {
0025   setupUi(this);
0026   setTabTitle(tr("Range"));
0027 
0028   connect(_xAuto, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0029   connect(_xMean, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0030   connect(_xBorder, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0031   connect(_xSpike, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0032   connect(_xFixed, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0033 
0034   connect(_yAuto, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0035   connect(_yMean, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0036   connect(_yBorder, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0037   connect(_ySpike, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0038   connect(_yFixed, SIGNAL(toggled(bool)), this, SIGNAL(modified()));
0039 
0040   connect(_xMin, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
0041   connect(_xMax, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
0042   connect(_xRange, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
0043 
0044   connect(_yMin, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
0045   connect(_yMax, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
0046   connect(_yRange, SIGNAL(textChanged(QString)), this, SIGNAL(modified()));
0047 
0048   connect(this, SIGNAL(modified()), this, SLOT(updateButtons()));
0049 
0050 }
0051 
0052 
0053 RangeTab::~RangeTab() {
0054 }
0055 
0056 
0057 void RangeTab::setupRange() {
0058   Q_ASSERT(_plotItem);
0059 
0060   double xmax = _plotItem->xMax();
0061   double xmin = _plotItem->xMin();
0062   double ymax = _plotItem->yMax();
0063   double ymin = _plotItem->yMin();
0064   if (_plotItem->xAxis()->axisLog()) {
0065     xmax = pow(10.0f,xmax);
0066     xmin = pow(10.0f,xmin);
0067   }
0068   if (_plotItem->yAxis()->axisLog()) {
0069     ymax = pow(10.0f,ymax);
0070     ymin = pow(10.0f,ymin);
0071   }
0072 
0073   _xRange->setText(QString::number(fabs(xmax - xmin),'g', 13));
0074   _xMin->setText(QString::number(xmin,'g', 13));
0075   _xMax->setText(QString::number(xmax,'g', 13));
0076 
0077   _yRange->setText(QString::number(fabs(ymax - ymin),'g', 13));
0078   _yMin->setText(QString::number(ymin,'g', 13));
0079   _yMax->setText(QString::number(ymax,'g', 13));
0080 
0081   switch (_plotItem->xAxis()->axisZoomMode()) {
0082     case PlotAxis::Auto:
0083       _xAuto->setChecked(true);
0084       break;
0085     case PlotAxis::AutoBorder: 
0086       _xBorder->setChecked(true);
0087       break;
0088     case PlotAxis::FixedExpression:
0089       _xFixed->setChecked(true);
0090       break;
0091     case PlotAxis::SpikeInsensitive:
0092       _xSpike->setChecked(true);
0093       break;
0094     case PlotAxis::MeanCentered:
0095       _xMean->setChecked(true);
0096       break;
0097     default:
0098       break;
0099   }
0100   switch (_plotItem->yAxis()->axisZoomMode()) {
0101     case PlotAxis::Auto:
0102       _yAuto->setChecked(true);
0103       break;
0104     case PlotAxis::AutoBorder: 
0105       _yBorder->setChecked(true);
0106       break;
0107     case PlotAxis::FixedExpression:
0108       _yFixed->setChecked(true);
0109       break;
0110     case PlotAxis::SpikeInsensitive:
0111       _ySpike->setChecked(true);
0112       break;
0113     case PlotAxis::MeanCentered:
0114       _yMean->setChecked(true);
0115       break;
0116     default:
0117       break;
0118   }
0119 }
0120 
0121 
0122 void RangeTab::modified() {
0123   emit tabModified();
0124 }
0125 
0126 
0127 void RangeTab::clearTabValues() {
0128 
0129   _xHidden->setChecked(true);
0130   _yHidden->setChecked(true);
0131   _xRange->clear();
0132   _xMin->clear();
0133   _xMax->clear();
0134 
0135   _yRange->clear();
0136   _yMin->clear();
0137   _yMax->clear();
0138 }
0139 
0140 
0141 void RangeTab::updateButtons() {
0142   if (!_xHidden->isChecked()) {
0143     label->setEnabled(_xMean->isChecked());
0144     _xRange->setEnabled(_xMean->isChecked());
0145 
0146     label_2->setEnabled(_xFixed->isChecked());
0147     _xMin->setEnabled(_xFixed->isChecked());
0148     label_3->setEnabled(_xFixed->isChecked());
0149     _xMax->setEnabled(_xFixed->isChecked());
0150   } else {
0151     label->setEnabled(true);
0152     _xRange->setEnabled(true);
0153 
0154     label_2->setEnabled(true);
0155     _xMin->setEnabled(true);
0156     label_3->setEnabled(true);
0157     _xMax->setEnabled(true);
0158   }
0159 
0160   if (!_yHidden->isChecked()) {
0161     label_4->setEnabled(_yMean->isChecked());
0162     _yRange->setEnabled(_yMean->isChecked());
0163 
0164     label_5->setEnabled(_yFixed->isChecked());
0165     _yMin->setEnabled(_yFixed->isChecked());
0166     label_6->setEnabled(_yFixed->isChecked());
0167     _yMax->setEnabled(_yFixed->isChecked());
0168   } else {
0169     label_4->setEnabled(true);
0170     _yRange->setEnabled(true);
0171 
0172     label_5->setEnabled(true);
0173     _yMin->setEnabled(true);
0174     label_6->setEnabled(true);
0175     _yMax->setEnabled(true);
0176   }
0177 
0178 }
0179 
0180 
0181 bool RangeTab::xModeDirty() const {
0182   return (!_xHidden->isChecked());
0183 }
0184 
0185 
0186 bool RangeTab::xRangeDirty() const {
0187   return (!_xRange->text().isEmpty());
0188 }
0189 
0190 
0191 bool RangeTab::xMinDirty() const {
0192   return (!_xMin->text().isEmpty());
0193 }
0194 
0195 
0196 bool RangeTab::xMaxDirty() const {
0197   return (!_xMax->text().isEmpty());
0198 }
0199 
0200 
0201 bool RangeTab::yModeDirty() const {
0202   return (!_yHidden->isChecked());
0203 }
0204 
0205 
0206 bool RangeTab::yRangeDirty() const {
0207   return (!_yRange->text().isEmpty());
0208 }
0209 
0210 
0211 bool RangeTab::yMinDirty() const {
0212   return (!_yMin->text().isEmpty());
0213 }
0214 
0215 
0216 bool RangeTab::yMaxDirty() const {
0217   return (!_yMax->text().isEmpty());
0218 }
0219 
0220 }
0221