Mark a lot of TODO's where I think it should be moved to C code.

This marks a lot of todo's where I think there's core stuff being mangled
on the interface - we should remove this from the interface to make
testing and maintenability easier.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-04-16 23:56:42 -03:00 committed by Dirk Hohndel
parent 1a1cbc296b
commit f14c14c383
8 changed files with 44 additions and 14 deletions

2
dive.h
View file

@ -846,7 +846,9 @@ struct diveplan {
struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2, bool entered); struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int o2, int he, int po2, bool entered);
void get_gas_string(int o2, int he, char *buf, int len); void get_gas_string(int o2, int he, char *buf, int len);
struct divedatapoint *create_dp(int time_incr, int depth, int o2, int he, int po2); struct divedatapoint *create_dp(int time_incr, int depth, int o2, int he, int po2);
#if DEBUG_PLAN
void dump_plan(struct diveplan *diveplan); void dump_plan(struct diveplan *diveplan);
#endif
void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, bool add_deco); void plan(struct diveplan *diveplan, char **cached_datap, struct dive **divep, bool add_deco);
void delete_single_dive(int idx); void delete_single_dive(int idx);

View file

@ -242,6 +242,7 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
QItemSelection newDeselected = selectionModel()->selection(); QItemSelection newDeselected = selectionModel()->selection();
QModelIndexList diveList; QModelIndexList diveList;
//TODO: This should be called find_first_selected_dive and be ported to C code.
int firstSelectedDive = -1; int firstSelectedDive = -1;
/* context for temp. variables. */ { /* context for temp. variables. */ {
int i = 0; int i = 0;
@ -250,6 +251,7 @@ void DiveListView::selectDives(const QList<int> &newDiveSelection)
dive->selected = newDiveSelection.contains(i) == true; dive->selected = newDiveSelection.contains(i) == true;
if (firstSelectedDive == -1 && dive->selected) { if (firstSelectedDive == -1 && dive->selected) {
firstSelectedDive = i; firstSelectedDive = i;
break;
} }
} }
} }
@ -444,6 +446,7 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
const QAbstractItemModel *model = index.model(); const QAbstractItemModel *model = index.model();
struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>(); struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>();
if (!dive) { // it's a trip! if (!dive) { // it's a trip!
//TODO: deselect_trip_dives on c-code?
if (model->rowCount(index)) { if (model->rowCount(index)) {
struct dive *child = (struct dive *)model->data(index.child(0, 0), DiveTripModel::DIVE_ROLE).value<void *>(); struct dive *child = (struct dive *)model->data(index.child(0, 0), DiveTripModel::DIVE_ROLE).value<void *>();
while (child) { while (child) {
@ -462,6 +465,7 @@ void DiveListView::selectionChanged(const QItemSelection &selected, const QItemS
const QAbstractItemModel *model = index.model(); const QAbstractItemModel *model = index.model();
struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>(); struct dive *dive = (struct dive *)model->data(index, DiveTripModel::DIVE_ROLE).value<void *>();
if (!dive) { // it's a trip! if (!dive) { // it's a trip!
//TODO: select_trip_dives on C code?
if (model->rowCount(index)) { if (model->rowCount(index)) {
QItemSelection selection; QItemSelection selection;
struct dive *child = (struct dive *)model->data(index.child(0, 0), DiveTripModel::DIVE_ROLE).value<void *>(); struct dive *child = (struct dive *)model->data(index.child(0, 0), DiveTripModel::DIVE_ROLE).value<void *>();
@ -523,7 +527,8 @@ void DiveListView::merge_trip(const QModelIndex &a, int offset)
dive_trip_t *trip_a = (dive_trip_t *)a.data(DiveTripModel::TRIP_ROLE).value<void *>(); dive_trip_t *trip_a = (dive_trip_t *)a.data(DiveTripModel::TRIP_ROLE).value<void *>();
dive_trip_t *trip_b = (dive_trip_t *)b.data(DiveTripModel::TRIP_ROLE).value<void *>(); dive_trip_t *trip_b = (dive_trip_t *)b.data(DiveTripModel::TRIP_ROLE).value<void *>();
// TODO: merge_trip on the C code? some part of this needs to stay ( getting the trips from the model,
// but not the algorithm.
if (trip_a == trip_b || !trip_a || !trip_b) if (trip_a == trip_b || !trip_a || !trip_b)
return; return;
@ -538,6 +543,7 @@ void DiveListView::merge_trip(const QModelIndex &a, int offset)
fixMessyQtModelBehaviour(); fixMessyQtModelBehaviour();
restoreSelection(); restoreSelection();
mark_divelist_changed(true); mark_divelist_changed(true);
//TODO: emit a signal to signalize that the divelist changed?
} }
void DiveListView::mergeTripAbove() void DiveListView::mergeTripAbove()
@ -552,6 +558,7 @@ void DiveListView::mergeTripBelow()
void DiveListView::removeFromTrip() void DiveListView::removeFromTrip()
{ {
//TODO: move this to C-code.
int i; int i;
struct dive *d; struct dive *d;
for_each_dive(i, d) { for_each_dive(i, d) {
@ -567,11 +574,12 @@ void DiveListView::removeFromTrip()
void DiveListView::newTripAbove() void DiveListView::newTripAbove()
{ {
dive_trip_t *trip;
int idx;
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>(); struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
if (!d) // shouldn't happen as we only are setting up this action if this is a dive if (!d) // shouldn't happen as we only are setting up this action if this is a dive
return; return;
//TODO: port to c-code.
dive_trip_t *trip;
int idx;
rememberSelection(); rememberSelection();
trip = create_and_hookup_trip_from_dive(d); trip = create_and_hookup_trip_from_dive(d);
for_each_dive(idx, d) { for_each_dive(idx, d) {
@ -597,15 +605,17 @@ void DiveListView::addToTripAbove()
void DiveListView::addToTrip(bool below) void DiveListView::addToTrip(bool below)
{ {
int idx, delta = (currentOrder == Qt::AscendingOrder) ? -1 : +1; int delta = (currentOrder == Qt::AscendingOrder) ? -1 : +1;
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
rememberSelection();
//TODO: This part should be moved to C-code.
int idx;
dive_trip_t *trip = NULL; dive_trip_t *trip = NULL;
struct dive *pd = NULL; struct dive *pd = NULL;
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
if (!d) // shouldn't happen as we only are setting up this action if this is a dive
return;
if (below) // Should we add to the trip below instead? if (below) // Should we add to the trip below instead?
delta *= -1; delta *= -1;
rememberSelection();
if (d->selected) { // we are right-clicking on one of possibly many selected dive(s) if (d->selected) { // we are right-clicking on one of possibly many selected dive(s)
// find the top selected dive, depending on the list order // find the top selected dive, depending on the list order
if (delta == 1) { if (delta == 1) {
@ -637,6 +647,7 @@ void DiveListView::addToTrip(bool below)
} }
trip->expanded = 1; trip->expanded = 1;
mark_divelist_changed(true); mark_divelist_changed(true);
//This part stays at C++ code.
reload(currentLayout, false); reload(currentLayout, false);
restoreSelection(); restoreSelection();
fixMessyQtModelBehaviour(); fixMessyQtModelBehaviour();
@ -651,6 +662,7 @@ void DiveListView::markDiveInvalid()
for_each_dive(i, d) { for_each_dive(i, d) {
if (!d->selected) if (!d->selected)
continue; continue;
//TODO: this should be done in the future
// now mark the dive invalid... how do we do THAT? // now mark the dive invalid... how do we do THAT?
// d->invalid = true; // d->invalid = true;
} }
@ -669,10 +681,12 @@ void DiveListView::markDiveInvalid()
void DiveListView::deleteDive() void DiveListView::deleteDive()
{ {
int i;
struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>(); struct dive *d = (struct dive *)contextMenuIndex.data(DiveTripModel::DIVE_ROLE).value<void *>();
if (!d) if (!d)
return; return;
//TODO: port this to C-code.
int i;
// after a dive is deleted the ones following it move forward in the dive_table // after a dive is deleted the ones following it move forward in the dive_table
// so instead of using the for_each_dive macro I'm using an explicit for loop // so instead of using the for_each_dive macro I'm using an explicit for loop
// to make this easier to understand // to make this easier to understand
@ -829,6 +843,7 @@ void DiveListView::loadImages()
for (int i = 0; i < fileNames.size(); ++i) { for (int i = 0; i < fileNames.size(); ++i) {
if (readfile(fileNames.at(i).toUtf8().data(), &mem) <= 0) if (readfile(fileNames.at(i).toUtf8().data(), &mem) <= 0)
continue; continue;
//TODO: This inner code should be ported to C-Code.
retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size); retval = exif.parseFrom((const unsigned char *)mem.buffer, (unsigned)mem.size);
free(mem.buffer); free(mem.buffer);
if (retval != PARSE_EXIF_SUCCESS) if (retval != PARSE_EXIF_SUCCESS)
@ -836,7 +851,7 @@ void DiveListView::loadImages()
imagetime = shiftDialog.epochFromExiv(&exif); imagetime = shiftDialog.epochFromExiv(&exif);
if (!imagetime) if (!imagetime)
continue; continue;
imagetime += shiftDialog.amount(); imagetime += shiftDialog.amount(); // TODO: this should be cached and passed to the C-function
int j = 0; int j = 0;
struct dive *dive; struct dive *dive;
for_each_dive(j, dive) { for_each_dive(j, dive) {

View file

@ -469,6 +469,7 @@ void DivePlannerGraphics::drawProfile()
plannerModel->deleteTemporaryPlan(); plannerModel->deleteTemporaryPlan();
return; return;
} }
//TODO: divedatapoint_list_get_max_depth on C - code?
while (dp->next) { while (dp->next) {
if (dp->time && dp->depth > max_depth) if (dp->time && dp->depth > max_depth)
max_depth = dp->depth; max_depth = dp->depth;
@ -1489,7 +1490,7 @@ void DivePlannerPointsModel::createTemporaryPlan()
// We just start with a surface node at time = 0 // We just start with a surface node at time = 0
if (!stagingDive) if (!stagingDive)
return; return;
//TODO: this thingy looks like it could be a good C-based function
diveplan.dp = NULL; diveplan.dp = NULL;
int lastIndex = -1; int lastIndex = -1;
for (int i = 0; i < rowCount(); i++) { for (int i = 0; i < rowCount(); i++) {
@ -1559,6 +1560,7 @@ void DivePlannerPointsModel::createPlan()
return cancelPlan(); return cancelPlan();
createTemporaryPlan(); createTemporaryPlan();
//TODO: C-based function here?
plan(&diveplan, &cache, &tempDive, isPlanner()); plan(&diveplan, &cache, &tempDive, isPlanner());
copy_cylinders(stagingDive, tempDive); copy_cylinders(stagingDive, tempDive);
int mean[MAX_CYLINDERS], duration[MAX_CYLINDERS]; int mean[MAX_CYLINDERS], duration[MAX_CYLINDERS];

View file

@ -391,6 +391,7 @@ void MainWindow::on_actionAddDive_triggered()
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
// now cheat - create one dive that we use to store the info tab data in // now cheat - create one dive that we use to store the info tab data in
//TODO: C-function create_temporary_dive ?
struct dive *dive = alloc_dive(); struct dive *dive = alloc_dive();
dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset(); dive->when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset();
dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file dive->dc.model = "manually added dive"; // don't translate! this is stored in the XML file

View file

@ -444,7 +444,7 @@ void WeightModel::passInData(const QModelIndex &index, const QVariant &value)
} }
} }
} }
//TODO: Move to C
weight_t string_to_weight(const char *str) weight_t string_to_weight(const char *str)
{ {
const char *end; const char *end;
@ -469,6 +469,7 @@ lbs:
return weight; return weight;
} }
//TODO: Move to C.
depth_t string_to_depth(const char *str) depth_t string_to_depth(const char *str)
{ {
const char *end; const char *end;
@ -492,6 +493,7 @@ ft:
return depth; return depth;
} }
//TODO: Move to C.
pressure_t string_to_pressure(const char *str) pressure_t string_to_pressure(const char *str)
{ {
const char *end; const char *end;
@ -515,6 +517,7 @@ psi:
return pressure; return pressure;
} }
//TODO: Move to C.
/* Imperial cylinder volumes need working pressure to be meaningful */ /* Imperial cylinder volumes need working pressure to be meaningful */
volume_t string_to_volume(const char *str, pressure_t workp) volume_t string_to_volume(const char *str, pressure_t workp)
{ {
@ -547,6 +550,7 @@ l:
return volume; return volume;
} }
//TODO: Move to C.
fraction_t string_to_fraction(const char *str) fraction_t string_to_fraction(const char *str)
{ {
const char *end; const char *end;
@ -564,6 +568,7 @@ bool WeightModel::setData(const QModelIndex &index, const QVariant &value, int r
switch (index.column()) { switch (index.column()) {
case TYPE: case TYPE:
if (!value.isNull()) { if (!value.isNull()) {
//TODO: C-function weigth_system_set_description ?
if (!ws->description || gettextFromC::instance()->tr(ws->description) != vString) { if (!ws->description || gettextFromC::instance()->tr(ws->description) != vString) {
// loop over translations to see if one matches // loop over translations to see if one matches
int i = -1; int i = -1;

View file

@ -93,6 +93,7 @@ void PrintLayout::setup()
} }
// go trought the dive table and find how many dives we are a going to print // go trought the dive table and find how many dives we are a going to print
// TODO: C function: 'count_selected_dives' or something
int PrintLayout::estimateTotalDives() const int PrintLayout::estimateTotalDives() const
{ {
int total = 0, i = 0; int total = 0, i = 0;

View file

@ -224,6 +224,7 @@ void ShiftImageTimesDialog::syncCameraClicked()
connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &))); connect(ui.dcTime, SIGNAL(dateTimeChanged(const QDateTime &)), this, SLOT(dcDateTimeChanged(const QDateTime &)));
} }
//TODO: This should be moved to C-Code.
time_t ShiftImageTimesDialog::epochFromExiv(EXIFInfo *exif) time_t ShiftImageTimesDialog::epochFromExiv(EXIFInfo *exif)
{ {
struct tm tm; struct tm tm;

View file

@ -40,7 +40,7 @@ static bool is_automatic_fix(struct dive *gpsfix)
} }
#define SAME_GROUP 6 * 3600 // six hours #define SAME_GROUP 6 * 3600 // six hours
//TODO: C Code. static functions are not good if we plan to have a test for them.
static bool merge_locations_into_dives(void) static bool merge_locations_into_dives(void)
{ {
int i, nr = 0, changed = 0; int i, nr = 0, changed = 0;
@ -94,7 +94,7 @@ static bool merge_locations_into_dives(void)
} }
return changed > 0; return changed > 0;
} }
//TODO: C-code.
static void clear_table(struct dive_table *table) static void clear_table(struct dive_table *table)
{ {
int i; int i;
@ -103,6 +103,7 @@ static void clear_table(struct dive_table *table)
table->nr = 0; table->nr = 0;
} }
// TODO: This looks like should be ported to C code. or a big part of it.
bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected) bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected)
{ {
static const char errPrefix[] = "divelog.de-upload:"; static const char errPrefix[] = "divelog.de-upload:";
@ -451,6 +452,7 @@ void SubsurfaceWebServices::setStatusText(int status)
ui.status->setText(text); ui.status->setText(text);
} }
//TODO: C-Code.
/* requires that there is a <download> or <error> tag under the <root> tag */ /* requires that there is a <download> or <error> tag under the <root> tag */
void SubsurfaceWebServices::download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status) void SubsurfaceWebServices::download_dialog_traverse_xml(xmlNodePtr node, unsigned int *download_status)
{ {
@ -467,6 +469,7 @@ void SubsurfaceWebServices::download_dialog_traverse_xml(xmlNodePtr node, unsign
} }
} }
// TODO: C-Code
unsigned int SubsurfaceWebServices::download_dialog_parse_response(const QByteArray &xml) unsigned int SubsurfaceWebServices::download_dialog_parse_response(const QByteArray &xml)
{ {
xmlNodePtr root; xmlNodePtr root;