diff options
author | Tomaz Canabrava <tcanabrava@kde.org> | 2013-08-16 15:52:40 -0300 |
---|---|---|
committer | Tomaz Canabrava <tcanabrava@kde.org> | 2013-08-16 15:52:40 -0300 |
commit | 2b6c3b4c0cb094a06bc832573f68be00de9d7293 (patch) | |
tree | 931a2848dd2894a9c98fd7e1efb26a5de82b2cda /qt-ui/maintab.cpp | |
parent | b7fe4087a6b8461f029969a38222dd941e0b298d (diff) | |
download | subsurface-2b6c3b4c0cb094a06bc832573f68be00de9d7293.tar.gz |
Good deal of code cleanup.
This is a bit of code cleanup that I'm not sure that will
pass, since it's all macro-based, but I don't have a thing
against macros at all. Sometimes they helps us keep a better
and cleaner code base. I think I managed to remove around 120
lines of code, wich isn't much, but I replaced it by 14. and the
code is now easyer to maintain, so hooray.
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
Diffstat (limited to 'qt-ui/maintab.cpp')
-rw-r--r-- | qt-ui/maintab.cpp | 126 |
1 files changed, 32 insertions, 94 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index 9f962be8b..768a521f0 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -517,43 +517,38 @@ void MainTab::on_editReset_clicked() editMode = NONE; } #undef EDIT_TEXT2 -void MainTab::on_buddy_textChanged(const QString& text) -{ - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - EDIT_TEXT(mydive->buddy, text); + +#define EDIT_SELECTED_DIVES( WHAT ) \ + if (editMode == NONE) \ + return; \ + struct dive *mydive; \ +\ + for (int i = 0; i < dive_table.nr; i++) { \ + mydive = get_dive(i); \ + if (!mydive) \ + continue; \ + if (!mydive->selected) \ + continue; \ +\ + WHAT; \ } +void markChangedWidget(QWidget *w){ QPalette p; p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->buddy->setPalette(p); + w->setPalette(p); +} + +void MainTab::on_buddy_textChanged(const QString& text) +{ + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->buddy, text) ); + markChangedWidget(ui->buddy); } void MainTab::on_divemaster_textChanged(const QString& text) { - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - EDIT_TEXT(mydive->divemaster, text); - } - QPalette p; - p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->divemaster->setPalette(p); + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->divemaster, text) ); + markChangedWidget(ui->divemaster); } void MainTab::on_location_textChanged(const QString& text) @@ -565,40 +560,16 @@ void MainTab::on_location_textChanged(const QString& text) dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); EDIT_TEXT(currentTrip->location, text); } else if (editMode == DIVE){ - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - EDIT_TEXT(mydive->location, text); - } + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) ) } - QPalette p; - p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->location->setPalette(p); + markChangedWidget(ui->location); } void MainTab::on_suit_textChanged(const QString& text) { - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - EDIT_TEXT(mydive->suit, text); - } - - QPalette p; - p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->suit->setPalette(p); + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->suit, text) ); + markChangedWidget(ui->suit); } void MainTab::on_notes_textChanged() @@ -610,54 +581,21 @@ void MainTab::on_notes_textChanged() dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText()); } else if (editMode == DIVE) { - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - EDIT_TEXT(mydive->notes, ui->notes->toPlainText()); - } + EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui->notes->toPlainText()) ); } - - QPalette p; - p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); - ui->notes->setPalette(p); + markChangedWidget(ui->notes); } #undef EDIT_TEXT void MainTab::on_rating_valueChanged(int value) { - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - mydive->rating = value; - } + EDIT_SELECTED_DIVES(mydive->rating = value ); } void MainTab::on_visibility_valueChanged(int value) { - if (editMode == NONE) - return; - struct dive *mydive; - for (int i = 0; i < dive_table.nr; i++) { - mydive = get_dive(i); - if (!mydive) - continue; - if (!mydive->selected) - continue; - - mydive->visibility = value; - } + EDIT_SELECTED_DIVES( mydive->visibility = value ); } void MainTab::hideEvent(QHideEvent* event) |