Hi there,

i program an Operationcenter for our local fire department (our younger members ( < 13 years old) use it on special training courses).
To monitor all vehicles' state i designed a Status-Monitor. If a vehicle changes his state (e.g. has an accident and is not ready for any incidents) there are several things to do for the program:
1.) Change color of a label
2.) Change text of a label

These tasks are very simple to program but now to my real problem.
There are 9 possible states. Each vehicle has its own groupbox and combobox. With the combobox and a pushbutton the user can choose the current state and set it.

Here is a screenshot:
captureeta.png

Now to my question:
Is there a possible way to create a function that gets two arguments (id of state and instance of label to where colour and text shall be applied to) instead of creating a function like this (its just the beginning of a function not the complete one!):
Qt Code:
  1. void ControlPanel::setStatus(int id, int boxId)
  2. {
  3. if(boxId == 1){
  4. switch(id){
  5. case 1:
  6. this->lblStatus1->setStyleSheet("background-color: rgb(181, 217, 164);");
  7. this->lblStatus1->setText("1");
  8. break;
  9. case 2:
  10. this->lblStatus1->setStyleSheet("background-color: rgb(121, 185, 92);");
  11. this->lblStatus1->setText("2");
  12. break;
  13. case 3:
  14. this->lblStatus1->setStyleSheet("background-color: rgb(244, 209, 81);");
  15. this->lblStatus1->setText("3");
  16. break;
  17. case 4:
  18. this->lblStatus1->setStyleSheet("background-color: rgb(239, 174, 77);");
  19. this->lblStatus1->setText("4");
  20. break;
  21. case 5:
  22. this->lblStatus1->setStyleSheet("background-color: rgb(239, 174, 77);");
  23. this->lblStatus1->setText("4");
  24. break;
  25. }
  26. }
  27. }
To copy to clipboard, switch view to plain text mode 

I mean the main thing i want to know is how i can pass an instance of an object to a function so that i dont need the if(boxId == 1) thing?
Are there maybe better and more efficient ways? Dont want to waste 100 lines of code if there is a better solution with less lines


Greetz