1 // -*- C++ -*-
2 // $Id: filterwidgets.cpp,v 1.5 2009-11-02 20:38:02 robertl Exp $
3 //------------------------------------------------------------------------
4 //
5 //  Copyright (C) 2009  S. Khai Mong <khai@mangrai.com>.
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License as
9 //  published by the Free Software Foundation; either version 2 of the
10 //  License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //  General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111
20 //  USA
21 //
22 
23 #include "filterwidgets.h"
24 
25 
26 //------------------------------------------------------------------------
TrackWidget(QWidget * parent,TrackFilterData & tfd)27 TrackWidget::TrackWidget(QWidget *parent, TrackFilterData &tfd): FilterWidget(parent) , tfd(tfd)
28 {
29   ui.setupUi(this);
30 
31   // Checkbox interlocks
32   addCheckEnabler(ui.titleCheck, ui.titleText);
33   addCheckEnabler(ui.moveCheck,
34 		  (QList<QWidget *> ()
35 		   << ui.daysLabel << ui.daysSpin
36 		   << ui.hoursLabel<< ui.hoursSpin
37 		   << ui.minsLabel << ui.minsSpin
38 		   << ui.secsLabel << ui.secsSpin));
39   addCheckEnabler(ui.startCheck,    ui.startEdit);
40   addCheckEnabler(ui.stopCheck,     ui.stopEdit);
41   addCheckEnabler(ui.GPSFixesCheck, ui.GPSFixesCombo);
42 
43   addCheckEnabler(ui.splitTimeCheck,
44 		  (QList<QWidget *> ()
45 		   <<ui.splitTimeSpin
46 		   <<ui.splitTimeCombo));
47   addCheckEnabler(ui.splitDistanceCheck,
48 		  (QList<QWidget *> ()
49 		   <<ui.splitDistSpin
50 		   <<ui.splitDistCombo));
51 
52   connect(ui.mergeCheck, SIGNAL(clicked()) , this, SLOT(mergeCheckX()));
53   connect(ui.packCheck,  SIGNAL(clicked()),  this, SLOT(packCheckX()));
54   connect(ui.startCheck, SIGNAL(clicked()),  this, SLOT(otherCheckX()));
55   connect(ui.stopCheck,   SIGNAL(clicked()), this, SLOT(otherCheckX()));
56 
57   connect(ui.splitDateCheck,   SIGNAL(clicked()), this, SLOT(splitDateX()));
58   connect(ui.splitTimeCheck,   SIGNAL(clicked()), this, SLOT(splitTimeX()));
59   connect(ui.splitDistanceCheck,   SIGNAL(clicked()), this, SLOT(splitDistanceX()));
60 
61   ui.startEdit->setDisplayFormat("dd MMM yyyy hh:mm:ss AP");
62   ui.stopEdit->setDisplayFormat("dd MMM yyyy hh:mm:ss AP");
63 
64   // Collect the data fields.
65   fopts << new BoolFilterOption(tfd.title,  ui.titleCheck);
66   fopts << new BoolFilterOption(tfd.move,   ui.moveCheck);
67   fopts << new BoolFilterOption(tfd.TZ,     ui.TZCheck);
68   fopts << new BoolFilterOption(tfd.start,  ui.startCheck);
69   fopts << new BoolFilterOption(tfd.stop,   ui.stopCheck);
70   fopts << new BoolFilterOption(tfd.pack,   ui.packCheck);
71   fopts << new BoolFilterOption(tfd.merge,  ui.mergeCheck);
72   fopts << new BoolFilterOption(tfd.splitByDate,  ui.splitDateCheck);
73   fopts << new BoolFilterOption(tfd.splitByTime,  ui.splitTimeCheck);
74   fopts << new BoolFilterOption(tfd.splitByDistance,  ui.splitDistanceCheck);
75   fopts << new BoolFilterOption(tfd.GPSFixes,  ui.GPSFixesCheck);
76   fopts << new BoolFilterOption(tfd.course, ui.courseCheck);
77   fopts << new BoolFilterOption(tfd.speed,  ui.speedCheck);
78 
79   fopts << new IntSpinFilterOption(tfd.days,  ui.daysSpin, -2000, 2000);
80   fopts << new IntSpinFilterOption(tfd.hours, ui.hoursSpin);
81   fopts << new IntSpinFilterOption(tfd.mins,  ui.minsSpin);
82   fopts << new IntSpinFilterOption(tfd.secs,  ui.secsSpin);
83   fopts << new IntSpinFilterOption(tfd.splitTime,  ui.splitTimeSpin, 0, 1000);
84   fopts << new IntSpinFilterOption(tfd.splitDist,  ui.splitDistSpin, 0, 5280);
85 
86   fopts << new DateTimeFilterOption(tfd.startTime, ui.startEdit);
87   fopts << new DateTimeFilterOption(tfd.stopTime,  ui.stopEdit);
88 
89   fopts << new StringFilterOption(tfd.titleString, ui.titleText);
90   fopts << new ComboFilterOption(tfd.GPSFixesVal,  ui.GPSFixesCombo);
91   fopts << new ComboFilterOption(tfd.splitTimeUnit,  ui.splitTimeCombo);
92   fopts << new ComboFilterOption(tfd.splitDistUnit,  ui.splitDistCombo);
93   setWidgetValues();
94   checkChecks();
95 }
96 
97 //------------------------------------------------------------------------
otherCheckX()98 void TrackWidget::otherCheckX()
99 {
100   ui.TZCheck->setEnabled(ui.stopCheck->isChecked() || ui.startCheck->isChecked());
101 
102   ui.splitTimeSpin->setEnabled(ui.splitTimeCheck->isChecked());
103   ui.splitTimeCombo->setEnabled(ui.splitTimeCheck->isChecked());
104   ui.splitDistSpin->setEnabled(ui.splitDistanceCheck->isChecked());
105   ui.splitDistCombo->setEnabled(ui.splitDistanceCheck->isChecked());
106 
107   bool bb = (ui.mergeCheck->isChecked() || ui.packCheck->isChecked());
108   ui.splitDateCheck->setEnabled(bb);
109   ui.splitTimeCheck->setEnabled(bb);
110   ui.splitDistanceCheck->setEnabled(bb);
111 }
112 
113 //------------------------------------------------------------------------
mergeCheckX()114 void TrackWidget::mergeCheckX()
115 {
116   if (ui.mergeCheck->isChecked())
117     ui.packCheck->setChecked(false);
118   otherCheckX();
119 }
120 //------------------------------------------------------------------------
packCheckX()121 void TrackWidget::packCheckX()
122 {
123   if (ui.packCheck->isChecked())
124     ui.mergeCheck->setChecked(false);
125   otherCheckX();
126 }
127 
128 //------------------------------------------------------------------------
splitDateX()129 void TrackWidget::splitDateX()
130 {
131   if (ui.splitDateCheck->isChecked()) {
132     ui.splitTimeCheck->setChecked(false);
133     ui.splitDistanceCheck->setChecked(false);
134   }
135   otherCheckX();
136 }
137 //------------------------------------------------------------------------
splitTimeX()138 void TrackWidget::splitTimeX()
139 {
140   if (ui.splitTimeCheck->isChecked()) {
141     ui.splitDateCheck->setChecked(false);
142     ui.splitDistanceCheck->setChecked(false);
143   }
144   otherCheckX();
145 }
146 //------------------------------------------------------------------------
splitDistanceX()147 void TrackWidget::splitDistanceX()
148 {
149   if (ui.splitDistanceCheck->isChecked()) {
150     ui.splitDateCheck->setChecked(false);
151     ui.splitTimeCheck->setChecked(false);
152   }
153   otherCheckX();
154 }
155 
156 
157 //------------------------------------------------------------------------
158 //------------------------------------------------------------------------
WayPtsWidget(QWidget * parent,WayPtsFilterData & wfd)159 WayPtsWidget::WayPtsWidget(QWidget *parent, WayPtsFilterData &wfd): FilterWidget(parent) , wfd(wfd)
160 {
161   ui.setupUi(this);
162   addCheckEnabler(ui.duplicatesCheck,
163 		  QList<QWidget*>() << ui.shortNamesCheck << ui.locationsCheck);
164   addCheckEnabler(ui.positionCheck,
165 		  QList<QWidget*>() << ui.positionText << ui.positionUnitCombo);
166   addCheckEnabler(ui.radiusCheck,
167 		  QList<QWidget*>() << ui.latLabel << ui.latText << ui.longLabel <<
168 		  ui.longText << ui.radiusUnitCombo << ui.radiusText);
169 
170   fopts << new BoolFilterOption(wfd.duplicates, ui.duplicatesCheck);
171   fopts << new BoolFilterOption(wfd.shortNames, ui.shortNamesCheck);
172   fopts << new BoolFilterOption(wfd.locations, ui.locationsCheck);
173   fopts << new BoolFilterOption(wfd.position, ui.positionCheck);
174   fopts << new BoolFilterOption(wfd.radius, ui.radiusCheck);
175   fopts << new BoolFilterOption(wfd.sort, ui.sortCheck);
176   fopts << new DoubleFilterOption(wfd.positionVal, ui.positionText, 0.0, 1.0E308);
177   fopts << new DoubleFilterOption(wfd.radiusVal, ui.radiusText, 0.0, 1.0E308);
178   fopts << new DoubleFilterOption(wfd.longVal, ui.longText, -180, 180, 7, 'f');
179   fopts << new DoubleFilterOption(wfd.latVal, ui.latText,  -90, 90, 7, 'f');
180   fopts << new ComboFilterOption(wfd.positionUnit, ui.positionUnitCombo);
181   fopts << new ComboFilterOption(wfd.radiusUnit, ui.radiusUnitCombo);
182 
183   connect(ui.shortNamesCheck, SIGNAL(clicked()), this, SLOT(shortNamesCkX()));
184   connect(ui.locationsCheck, SIGNAL(clicked()), this, SLOT(locationsCkX()));
185   setWidgetValues();
186   checkChecks();
187 }
188 //------------------------------------------------------------------------
shortNamesCkX()189 void WayPtsWidget::shortNamesCkX()
190 {
191   if (!ui.shortNamesCheck->isChecked())
192     ui.locationsCheck->setChecked(true);
193 }
194 //------------------------------------------------------------------------
locationsCkX()195 void WayPtsWidget::locationsCkX()
196 {
197   if (!ui.locationsCheck->isChecked())
198     ui.shortNamesCheck->setChecked(true);
199 }
200 
201 //------------------------------------------------------------------------
202 //------------------------------------------------------------------------
RtTrkWidget(QWidget * parent,RtTrkFilterData & rfd)203 RtTrkWidget::RtTrkWidget(QWidget *parent, RtTrkFilterData &rfd): FilterWidget(parent) , rfd(rfd)
204 {
205   ui.setupUi(this);
206   addCheckEnabler(ui.simplifyCheck,
207 		  QList<QWidget*>() << ui.limitToLabel << ui.limitToSpin << ui.pointLabel);
208 
209   fopts << new BoolFilterOption(rfd.simplify, ui.simplifyCheck);
210   fopts << new BoolFilterOption(rfd.reverse, ui.reverseCheck);
211   fopts << new IntSpinFilterOption(rfd.limitTo, ui.limitToSpin, 1, 5000);
212   setWidgetValues();
213   checkChecks();
214 }
215 
216 //------------------------------------------------------------------------
217 //------------------------------------------------------------------------
MiscFltWidget(QWidget * parent,MiscFltFilterData & mfd)218 MiscFltWidget::MiscFltWidget(QWidget *parent, MiscFltFilterData &mfd): FilterWidget(parent) , mfd(mfd)
219 {
220   ui.setupUi(this);
221   ui.transformCombo->addItem(QString("%1 %2 %3").arg(tr("Tracks")).arg(QChar(8594)).arg(tr("Waypoints")));
222   ui.transformCombo->addItem(QString("%1 %2 %3").arg(tr("Routes")).arg(QChar(8594)).arg(tr("Tracks")));
223   ui.transformCombo->addItem(QString("%1 %2 %3").arg(tr("Waypoints")).arg(QChar(8594)).arg(tr("Routes")));
224   ui.transformCombo->addItem(QString("%1 %2 %3").arg(tr("Routes")).arg(QChar(8594)).arg(tr("Waypoints")));
225   ui.transformCombo->addItem(QString("%1 %2 %3").arg(tr("Tracks")).arg(QChar(8594)).arg(tr("Routes")));
226   ui.transformCombo->addItem(QString("%1 %2 %3").arg(tr("Waypoints")).arg(QChar(8594)).arg(tr("Tracks")));
227   addCheckEnabler(ui.transformCheck,
228 		  QList<QWidget*>() << ui.transformCombo << ui.deleteCheck);
229 
230   fopts << new BoolFilterOption(mfd.transform, ui.transformCheck);
231   fopts << new BoolFilterOption(mfd.swap, ui.swapCheck);
232   fopts << new BoolFilterOption(mfd.del, ui.deleteCheck);
233   fopts << new BoolFilterOption(mfd.nukeTracks, ui.nukeTracks);
234   fopts << new BoolFilterOption(mfd.nukeRoutes, ui.nukeRoutes);
235   fopts << new BoolFilterOption(mfd.nukeWaypoints, ui.nukeWaypoints);
236   fopts << new ComboFilterOption(mfd.transformVal,  ui.transformCombo);
237 
238   setWidgetValues();
239   checkChecks();
240 }
241