#ifndef BASEVIEWMODEL_H #define BASEVIEWMODEL_H #include #include #include "model/ultrasoundModule/UsHelper.h" #include "model/ultrasoundModule/UsEventSender.h" #include "model/ultrasoundModule/UsEventReceiver.h" #include "model/databaseManager/type/EDatabaseRequest.h" #include "viewModel/utils/AutoProperty.h" #include "viewModel/utils/UsMultiButton.h" #include "viewModel/utils/UsSpinBox.h" #include "viewModel/utils/UsSwitchButton.h" #include "viewModel/utils/UsJoystick.h" #include "viewModel/utils/UsRadioButton.h" #include "viewModel/utils/UsInfoBox.h" #include "viewModel/utils/UsTrackball.h" #include "viewModel/utils/UsList.h" #include "viewModel/utils/UsImage.h" //macro defenition //Place this in each and every class that inherits from BaseViewModel //so that you dont have to type all this again //uncrustify off #define US_VIEW_MODEL(VIEW_MODEL_NAME) \ private: \ void prepareData() override; \ void sendData() override; \ void setInitialValue() override; \ void turnOnMinimalMode() override; \ void turnOffMinimalMode() override; \ explicit VIEW_MODEL_NAME(); \ private slots: \ void newCommandRequest(const CommandRequest& request); \ public: \ virtual void init() override; \ #define APPLY_DIFF_COMMAND(PROPERTY) \ auto diffValue = GET_VALUE(request, 0, qint16); \ auto nextValue = getNextValue(PROPERTY() + diffValue, 0, PROPERTY ## Values().length() - 1); \ PROPERTY(nextValue); \ //uncrustify on /*************************************************************************************************/ class BaseViewModel : public QtMvvm::ViewModel { Q_OBJECT US_EVENT_SENDER(protected) US_EVENT_RECEIVER(protected) private: int _awaitingSend; bool isSendingAllowed(); virtual void setInitialValue() = 0; virtual void prepareData() = 0; virtual void sendData() = 0; virtual void turnOnMinimalMode() = 0; virtual void turnOffMinimalMode() = 0; protected: void allowSending(); void blockSending(); virtual void send() final; virtual QList arithmeticSeries(int start, int end, int step) final; virtual QList arithmeticSeries(float start, float end, float step, int precision) final; virtual CommandResult sendDataIntoDatabase(EDatabaseRequest::eDatabaseRequest request, const QList args) final; virtual CommandResult requestDataFromDatabase(EDatabaseRequest::eDatabaseRequest request, const QList args) final; template T translateDatabaseData(const QList args, const quint32 index) { return args[index].value(); } public: explicit BaseViewModel(); void start(); virtual void init() = 0; void changeMode(bool minimal); virtual int getNextValue(const int estimatedValue, const int lowerBound, const int upperBound) final; }; #endif //BASEVIEWMODEL_H