mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									b7fe4087a6
								
							
						
					
					
						commit
						2b6c3b4c0c
					
				
					 1 changed files with 31 additions and 93 deletions
				
			
		|  | @ -517,43 +517,38 @@ void MainTab::on_editReset_clicked() | ||||||
| 	editMode = NONE; | 	editMode = NONE; | ||||||
| } | } | ||||||
| #undef EDIT_TEXT2 | #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; | 	QPalette p; | ||||||
| 	p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); | 	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) | void MainTab::on_divemaster_textChanged(const QString& text) | ||||||
| { | { | ||||||
| 	if (editMode == NONE) | 	EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->divemaster, text) ); | ||||||
| 		return; | 	markChangedWidget(ui->divemaster); | ||||||
| 	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); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MainTab::on_location_textChanged(const QString& text) | 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(); | 		dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); | ||||||
| 		EDIT_TEXT(currentTrip->location, text); | 		EDIT_TEXT(currentTrip->location, text); | ||||||
| 	} else if (editMode == DIVE){ | 	} else if (editMode == DIVE){ | ||||||
| 		struct dive *mydive; | 		EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->location, text) ) | ||||||
| 		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); |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	QPalette p; | 	markChangedWidget(ui->location); | ||||||
| 	p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); |  | ||||||
| 	ui->location->setPalette(p); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MainTab::on_suit_textChanged(const QString& text) | void MainTab::on_suit_textChanged(const QString& text) | ||||||
| { | { | ||||||
| 	if (editMode == NONE) | 	EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->suit, text) ); | ||||||
| 		return; | 	markChangedWidget(ui->suit); | ||||||
| 	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); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MainTab::on_notes_textChanged() | void MainTab::on_notes_textChanged() | ||||||
|  | @ -610,54 +581,21 @@ void MainTab::on_notes_textChanged() | ||||||
| 		dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); | 		dive_trip_t *currentTrip = *mainWindow()->dive_list()->selectedTrips.begin(); | ||||||
| 		EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText()); | 		EDIT_TEXT(currentTrip->notes, ui->notes->toPlainText()); | ||||||
| 	} else if (editMode == DIVE) { | 	} else if (editMode == DIVE) { | ||||||
| 		struct dive *mydive; | 		EDIT_SELECTED_DIVES( EDIT_TEXT(mydive->notes, ui->notes->toPlainText()) ); | ||||||
| 		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()); |  | ||||||
| 	} | 	} | ||||||
| 	} | 	markChangedWidget(ui->notes); | ||||||
| 
 |  | ||||||
| 	QPalette p; |  | ||||||
| 	p.setBrush(QPalette::Base, QColor(Qt::yellow).lighter()); |  | ||||||
| 	ui->notes->setPalette(p); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #undef EDIT_TEXT | #undef EDIT_TEXT | ||||||
| 
 | 
 | ||||||
| void MainTab::on_rating_valueChanged(int value) | void MainTab::on_rating_valueChanged(int value) | ||||||
| { | { | ||||||
| 	if (editMode == NONE) | 	EDIT_SELECTED_DIVES(mydive->rating  = value ); | ||||||
| 		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; |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MainTab::on_visibility_valueChanged(int value) | void MainTab::on_visibility_valueChanged(int value) | ||||||
| { | { | ||||||
| 	if (editMode == NONE) | 	EDIT_SELECTED_DIVES( mydive->visibility = value ); | ||||||
| 		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; |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void MainTab::hideEvent(QHideEvent* event) | void MainTab::hideEvent(QHideEvent* event) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue