Change of plans – one function is bad idea
I wanted to write today about something different, but i found a bug. That bug is most likely a result of my lack of experience (like most of bugs here :). That bug is in function which is setting UI – setUi() function. I wanted to use it to create layout and later for changing in during application works, unfortunately that is not good way to do this and I learned the hard way 🙂
New plan – two functions
I decided to change that idea. New plan is to write two functions, one for creating the layout and second one for changing it. Old object for layouts was created on a heap as a dynamic memory, now all layouts object will be declared in the class definition. That allow to manipulate them after start of the application.
Example
#include ... class DataTab { QGroupBox * startingPointGroupBox; QFormLayout * startingPointFormLayout; QGroupBox * coolingPointGroupBox; QFormLayout * coolingPointFormLayout; QGroupBox * exchangerPointGroupBox; QFormLayout * exchangerPointFormLayout; QGroupBox * heatingPointGroupBox; QFormLayout * heatingPointFormLayout; QGroupBox * humidifyierChoosingGroupBox; QVBoxLayout *humidifyierChoosingButtonLayout; QGroupBox * humidifyierPointGroupBox; QFormLayout * humidifyierPointFormLayout; QGroupBox * mixPointGroupBox; QFormLayout * mixPointFormLayout; QGroupBox * mixingPointGroupBox; QFormLayout * mixingPointFormLayout; QGroupBox * processingModelGroupBox; QVBoxLayout * processingModelLayout; }
Code above shows declaration of every groupBox used in the app. Thanks to that I will be able to easily change layout attributes. But that is not everything what needs to be done. Next is splitting function setUI for creating UI and changing UI. I hope next time i will write about their implementation.
Image by title shows old/new UI 🙂
New code is available on GitHub.