src/MainWindow.h

Sat, 11 Feb 2023 15:48:02 +0100

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 11 Feb 2023 15:48:02 +0100
changeset 493
520306773450
parent 480
94b3def5d778
permissions
-rw-r--r--

Monitor iSpindels: use global variables instead of repeated expensive MySQL calls. Use the yeast temperature ranges for the colors on the thermometer scale. Don't show SVG and ABV if the OG is not yet known. Turn statusfield red if offline. Extra mon_ispindles fields yeast_lo and yeast_hi. Need at least bmsd version 0.3.42. If a websocket message is received that cannot be parsed, show the whole received message.

#ifndef _MAINWINDOW_H
#define _MAINWINDOW_H

#include "RecipesTree.h"
#include "InventorySuppliers.h"
#include "InventoryFermentables.h"
#include "InventoryHops.h"
#include "InventoryYeasts.h"
#include "InventoryYeastPacks.h"
#include "InventoryMiscs.h"
#include "InventoryWaters.h"
#include "InventoryEquipments.h"
#include "ProdInprod.h"
#include "ProdOnName.h"
#include "ProdOnCode.h"
#include "ProdOnDate.h"
#include "ProdOnTree.h"
#include "ProfileWaters.h"
#include "ProfileMashs.h"
#include "ProfileStyles.h"
#include "ProfileFerments.h"
#include "MonNodes.h"
#include "MonFermenters.h"
#include "MonCO2meters.h"
#include "MoniSpindels.h"
#include "ImportXML.h"
#include "ImportBrew.h"
#include "Setup.h"

#include <QMainWindow>
#include <QStandardItemModel>
#include <QMenu>
#include <QToolButton>
#include <QApplication>
#include <QDateTime>
#include <QDebug>
#include <QDir>
// #include <QDomDocument>
#include <QFile>
#include <QList>
#include <QMetaProperty>
#include <QObject>
#include <QSettings>
#include <QString>
#include <QTextStream>
#include <QTranslator>
#include <QtSql>
#include <QUuid>
#include <QStyle>
#include <QPlainTextEdit>
#include <QMessageBox>
#include <QLabel>
#include <QImage>
#include <QImageReader>
#include <QImageWriter>
#include <QColorSpace>
#include <QGraphicsView>
#include <QFileDialog>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMap>
#include <QPrinter>
#include <QWidget>
#include <QWebSocket>
#include <QChart>
#include <QValueAxis>
#include <QDateTimeAxis>
#include <QLineSeries>
#include <QSplineSeries>
#include <QChartView>
#include <QAreaSeries>


using namespace QtCharts;

typedef struct IniMySQL
{
    QString host;               ///< MySQL host
    QString port;               ///< MySQL port
    QString name;               ///< MySQL database
    QString user;               ///< MySQL username
    QString pass;               ///< MySQL password
    QString charset;            ///< MySQL character encoding
} IniMySQL;

static IniMySQL dbProd;
static IniMySQL dbDev;


typedef struct IniWS
{
    QString host;               ///< MQTT host
    QString port;               ///< MQTT port
} IniWS;

static IniWS wsProd;
static IniWS wsDev;


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(bool useDevelopOption, bool startConfigOption, QWidget *parent = 0);
    ~MainWindow();

    // Keep pointers to new windows.
    RecipesTree *RecipesTreeWindow;
    InventorySuppliers *InventorySuppliersWindow;
    InventoryFermentables *InventoryFermentablesWindow;
    InventoryHops *InventoryHopsWindow;
    InventoryYeasts *InventoryYeastsWindow;
    InventoryYeastPacks *InventoryYeastPacksWindow;
    InventoryMiscs *InventoryMiscsWindow;
    InventoryWaters *InventoryWatersWindow;
    InventoryEquipments *InventoryEquipmentsWindow;
    ProdInprod *ProdInprodWindow;
    ProdOnName *ProdOnNameWindow;
    ProdOnCode *ProdOnCodeWindow;
    ProdOnDate *ProdOnDateWindow;
    ProdOnTree *ProdOnTreeWindow;
    ProfileWaters *ProfileWatersWindow;
    ProfileMashs *ProfileMashsWindow;
    ProfileStyles *ProfileStylesWindow;
    ProfileFerments *ProfileFermentsWindow;
    MonNodes *MonNodesWindow;
    MonFermenters *MonFermentersWindow;
    MonCO2meters *MonCO2metersWindow;
    MoniSpindels *MoniSpindelsWindow;
    ImportXML *ImportXMLWindow;
    ImportBrew *ImportBrewWindow;
    Setup *SetupWindow;

signals:
    void updateNodes(QString);
    void updateFermenters(QString);
    void updateCO2meters(QString);
    void updateiSpindels(QString);

private slots:
    void on_actionImport_XML_triggered();
    void on_actionImport_Brew_triggered();
    void on_actionExit_triggered();
    void on_actionMon_Nodes_triggered();
    void on_actionMon_Fermenters_triggered();
    void on_actionMon_CO2meters_triggered();
    void on_actionMon_iSpindels_triggered();
    void on_actionProd_inprod_triggered();
    void on_actionRep_Production_triggered();
    void on_actionRep_Efficiency_triggered();
    void on_actionRep_Fermentation_triggered();
    void on_actionOn_Name_triggered();
    void on_actionOn_Code_triggered();
    void on_actionOn_Date_triggered();
    void on_actionOn_Tree_triggered();
    void on_actionRecipes_triggered();
    void on_actionSuppliers_triggered();
    void on_actionFermentables_triggered();
    void on_actionHops_triggered();
    void on_actionYeasts_triggered();
    void on_actionYeastPacks_triggered();
    void on_actionMiscs_triggered();
    void on_actionWaters_triggered();
    void on_actionEquipments_triggered();
    void on_actionSupplies_list_triggered();
    void on_actionYeast_bank_triggered();
    void on_actionWater_profiles_triggered();
    void on_actionMash_profiles_triggered();
    void on_actionStyles_profiles_triggered();
    void on_actionFerments_profiles_triggered();
    void on_actionSetup_triggered();
    void on_actionAbout_triggered();

public slots:
    void fromImportXML();
    void fromImportBrew();
    void fromMonNodes();
    void fromMonFermenters();
    void fromMonCO2meters();
    void fromMoniSpindels();
    void fromRecipesTree();
    void fromInventorySuppliers();
    void fromInventoryFermentables();
    void fromInventoryHops();
    void fromInventoryYeasts();
    void fromInventoryYeastPacks();
    void fromInventoryMiscs();
    void fromInventoryWaters();
    void fromInventoryEquipments();
    void fromProdInprod();
    void fromProdOnName();
    void fromProdOnCode();
    void fromProdOnDate();
    void fromProdOnTree();
    void fromProfileWaters();
    void fromProfileMashs();
    void fromProfileStyles();
    void fromProfileFerments();
    void fromSetup();
    void windowTitle(QString);
    void statusMsg(QString);

private:
    Ui::MainWindow *ui;

    /**
     * @brief Load profile_setup record and set global variables.
     */
    void loadSetup();

    /**
     * @brief Do database updates.
     */
    void updateDataBase();

    /**
     * @brief Do database maintenance.
     */
    void maintDataBase();

    /**
     * @brief Open Websocket connection.
     * @param develop Is true if connect to develop server, else production.
     * @return Returns true if succes.
     */
    bool openWS(bool develop);

    void wsConnected();

    void wsClosed();

    void wsTextMessageReceived(QString message);

    /**
     * @brief Read user settings for the MySQL connection.
     *        Settings in $HOME/.config/mbse/bmsapp.ini
     */
    void readsettings();

    /**
     * @brief Write or update the user settings for the MySQL connection.
     */
    void writesettings();
};

#endif

mercurial