IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Discussion :

Fuite de mémoire

  1. #21
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Merci pour tout ce temps investi à m'aider, et au passage me faire progresser.

    Je mets pour le moment le QSignalMapper de côté pour continuer à avancer dans la refonte de mon code. Mais je reviendrai dessus... promis.

  2. #22
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    C'est fait... QSignalMapper en place...
    Du coup je m'y suis mis tout de suite car ça aurait été beaucoup plus compliqué pour continuer sans...
    Et vous aviez plus que raison... cela sera énormément plus simple à ajouter (pour ce passage) une marque à ma liste.

    Donc ce bout de code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    //Slots that launch the function to generate the Type window by sending the mark
    void MainWindow::runBrother()
    {
        TypeWindow("brother");
    }
     
    void MainWindow::runCanon()
    {
        TypeWindow("canon");
    }
     
    void MainWindow::runEpson()
    {
        TypeWindow("epson");
    }
     
    void MainWindow::runHP()
    {
        TypeWindow("hp");
    }
     
    void MainWindow::runLexmark()
    {
        TypeWindow("lexmark");
    }
     
    void MainWindow::runSamsung()
    {
        TypeWindow("samsung");
    }
    a été remplacé par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    void MainWindow::runMark(QString mark)
    {
        TypeWindow(mark.toStdString());
    }
    J'ai également dû changer ce passage
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    void MainWindow::Button()
    {
        //###########################################################
        //############## Mark chooser window's buttons ##############
        //###########################################################
     
        std::ifstream file("database.txt", std::ifstream::in);
     
        for (int n = 0; n < 6; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::MARK_COL_1;
            else
                x = Init::MARK_COL_2;
     
            if (n < 2)
                y = Init::MARK_LIN_1;
            else if (n < 4)
                y = Init::MARK_LIN_2;
            else if (n < 6)
                y = Init::MARK_LIN_3;
     
            //Setting button's attributes
            markButton.push_back(new QPushButton(this));
            markButton[n]->setIcon(QIcon(QString::fromStdString("pictures/" + ReadInfos(file) + ".png")));
            markButton[n]->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
            markButton[n]->setFlat(true);
            markButton[n]->setGeometry(x, y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        }
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    void MainWindow::Button()
    {
        //###########################################################
        //############## Mark chooser window's buttons ##############
        //###########################################################
     
        std::ifstream file("database.txt", std::ifstream::in);
     
        //Initialisation of the signalMapper
        QSignalMapper *signalMapper = new QSignalMapper(this);
     
        std::string mark;
     
        for (int n = 0; n < 6; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::MARK_COL_1;
            else
                x = Init::MARK_COL_2;
     
            if (n < 2)
                y = Init::MARK_LIN_1;
            else if (n < 4)
                y = Init::MARK_LIN_2;
            else if (n < 6)
                y = Init::MARK_LIN_3;
     
            mark = ReadInfos(file);
     
            //Setting button's attributes
            markButton.push_back(new QPushButton(this));
            markButton[n]->setIcon(QIcon(QString::fromStdString("pictures/" + mark + ".png")));
            markButton[n]->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
            markButton[n]->setFlat(true);
            markButton[n]->setGeometry(x, y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
     
            //Connection and mapping of the signalMapper
            connect(markButton[n], SIGNAL(clicked(bool)), signalMapper, SLOT(map()));
            signalMapper->setMapping(markButton[n], QString::fromStdString(mark));
        }
        connect(signalMapper, SIGNAL(mapped(QString)), this, SIGNAL(buttonClicked(QString)));
    Le morceau "initialisant" les 'connect' est passé de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    void MainWindow::Slots()
    {
        connect(markButton[0], SIGNAL(clicked(bool)), this, SLOT(runBrother()));
        connect(markButton[1], SIGNAL(clicked(bool)), this, SLOT(runCanon()));
        connect(markButton[2], SIGNAL(clicked(bool)), this, SLOT(runEpson()));
        connect(markButton[3], SIGNAL(clicked(bool)), this, SLOT(runHP()));
        connect(markButton[4], SIGNAL(clicked(bool)), this, SLOT(runLexmark()));
        connect(markButton[5], SIGNAL(clicked(bool)), this, SLOT(runSamsung()));
        connect(exitButton, SIGNAL(clicked(bool)), this, SLOT(HomeWindow()));
        connect(nextSeriesButton, SIGNAL(clicked(bool)), this, SLOT(NextSeriesButtonClicked()));
        connect(previousSeriesButton, SIGNAL(clicked(bool)), this, SLOT(PreviousSeriesButtonClicked()));
        connect(inkButton, SIGNAL(clicked(bool)), this, SLOT(InkClicked()));
        connect(laserButton, SIGNAL(clicked(bool)), this, SLOT(LaserClicked()));
    }
    A
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    void MainWindow::Slots()
    {
        connect(this, SIGNAL(buttonClicked(QString)), this, SLOT(runMark(QString)));
        connect(exitButton, SIGNAL(clicked(bool)), this, SLOT(HomeWindow()));
        connect(nextSeriesButton, SIGNAL(clicked(bool)), this, SLOT(NextSeriesButtonClicked()));
        connect(previousSeriesButton, SIGNAL(clicked(bool)), this, SLOT(PreviousSeriesButtonClicked()));
        connect(inkButton, SIGNAL(clicked(bool)), this, SLOT(InkClicked()));
        connect(laserButton, SIGNAL(clicked(bool)), this, SLOT(LaserClicked()));
    }
    Et enfin j'ai dû légèrement modifier mon header... avant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    #ifndef MAINWINDOW
    #define MAINWINDOW
     
    #include <QtWidgets>
    #include <vector>
    #include <QVector>
    #include <fstream>
    #include "Init.h"
     
    class MainWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        MainWindow();
     
        private slots:
        void HomeWindow();
        void runBrother();
        void runCanon();
        void runEpson();
        void runHP();
        void runLexmark();
        void runSamsung();
        void InkClicked();
        void LaserClicked();
        void NextSeriesButtonClicked();
        void PreviousSeriesButtonClicked();
     
        private:
        std::vector<std::string> seriesTable;
        QVector<QPushButton*> markButton;
        QVector<QPushButton*> seriesButton;
     
        int myPage;
        int pageNumber;
        std::string myMark;
     
        QPushButton *inkButton;
        QPushButton *laserButton;
     
        QPushButton *markPic;
        QPushButton *logo;
        QPushButton *nextSeriesButton;
        QPushButton *previousSeriesButton;
        QPushButton *exitButton;
     
        std::string ReadInfos(std::ifstream &file);
        void SearchSeries(std::ifstream &file, std::vector<std::string> &table, std::string series);
        void AssignSeries(std::ifstream &file, std::vector<std::string> &table);
     
        void TypeWindow(std::string mark);
        void HideTypeButtons();
        void HideSeriesButtons();
        void SetSeriesInfos();
        void ShowSeriesButton(int number);
        void SeriesWindowGeneration(std::string series);
     
        void Button();
        void Slots();
    };
     
    #endif // MAINWINDOW
    Après
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    #ifndef MAINWINDOW
    #define MAINWINDOW
     
    #include <QtWidgets>
    #include <vector>
    #include <QVector>
    #include <fstream>
    #include "Init.h"
     
    class MainWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        MainWindow();
     
        signals:
        void buttonClicked (QString mark);
     
        private slots:
        void HomeWindow();
        void runMark(QString mark);
        void InkClicked();
        void LaserClicked();
        void NextSeriesButtonClicked();
        void PreviousSeriesButtonClicked();
     
        private:
        std::vector<std::string> seriesTable;
        QVector<QPushButton*> markButton;
        QVector<QPushButton*> seriesButton;
     
        QSignalMapper *signalMapper;
     
        int myPage;
        int pageNumber;
        std::string myMark;
     
        QPushButton *inkButton;
        QPushButton *laserButton;
     
        QPushButton *markPic;
        QPushButton *logo;
        QPushButton *nextSeriesButton;
        QPushButton *previousSeriesButton;
        QPushButton *exitButton;
     
        std::string ReadInfos(std::ifstream &file);
        void SearchSeries(std::ifstream &file, std::vector<std::string> &table, std::string series);
        void AssignSeries(std::ifstream &file, std::vector<std::string> &table);
     
        void TypeWindow(std::string mark);
        void HideTypeButtons();
        void HideSeriesButtons();
        void SetSeriesInfos();
        void ShowSeriesButton(int number);
        void SeriesWindowGeneration(std::string series);
     
        void Button();
        void Slots();
    };
     
    #endif // MAINWINDOW
    J'ai supprimé les 'void runBrother()'... et ajouté un signal et un slot persos (respectivement clicked(QString mark) et runMark(QString mark)).

    Et au passage, encore 17 lignes de moins dans mon fichier source

  3. #23
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Sinon, votre programme il fonctionne correctement ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  4. #24
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Oui, il fonctionne parfaitement (au point où j'en suis : pages de sélection de marque, puis type, puis famille), et grâce à vous il est beaucoup plus facile à relire.

    Il ne me reste plus qu'à le finir (ajouter les pages de sélection de modèle et enfin l'affichage des résultats).

    Je pourrais alors mettre ma "v1" aux oubliettes.

    Merci

  5. #25
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Bon... presque fini...

    J'ai mis un peu de temps à finir mes quelques fonctions car j'ai dû mettre mon programme en "pause" car pas beaucoup de temps pour travailler dessus.

    Toutes mes fonctions fonctionnent, le programme aussi, tout est implémenté... mais il me reste un petit problème que je n'arrive pas à identifier.

    Pour rappel mon programme sert à retrouver quelles cartouches d'encre vont dans un modèle précis d'imprimante.

    Le chemin est le suivant :
    1. on sélectionne la marque
    2. on sélectionne le type (cartouche ou laser)
    3. on sélectionne la famille de modèles
    4. on sélectionne le modèle
    5. on affiche alors le résultat


    Tout se passe normalement, mais si l'on utilise le programme plusieurs fois d'affilé (ce qui est le but car il sera à disposition de clients dans un magasin sur une tablette), le temps mis pour afficher le résultat (transition entre étape 4 et 5) augmente petit à petit jusqu'à devenir long.

    J'ai arrêté mon teste jusqu'à avoir 5-6 secondes de temps d'attente pour afficher le résultat, pendant ce temps rien ne se passe, comme si le programme était figé et "travaillait" en arrière plan.

    Pour obtenir ce délai il m'a fallu faire 20-25 fois le chemin complet depuis le début (étape 1 à 5). Aux premières utilisations (jusqu'au 5 premières fois) l'affichage du résultat est immédiat.

    En revanche, le délai entre toutes les autres étapes reste inchangé.

    Il faut alors que je ferme mon programme, l'exécute à nouveau et là je retrouve le délai immédiat au début qui s'allonge avec le nombre d'utilisation.

    Je fais de nouveau appel à un peu d'aide afin d'identifier l'origine du problème et le régler.

    Mon code est dans le post suivant.

    Par avance merci pour votre aide.






    P.S. : Quelques indications pour se situer dans mon code...
    la transition entre l'étape 4 et 5 (celle dont le temps augmente en fonction du nombre d'utilisations) se fait lorsque l'on clique sur un bouton pour choisir un modèle.
    Via un SignalMapper (nommé modelsSignalMapper) je connecte chacun des boutons à un SIGNAL perso transmettant un QString (le nom du modèle) à un SLOT que j'ai créé (nommé RunResults()) pour modifier la fenêtre en cours :
    - masquer les boutons de choix de modèle avec HideModelsButtons()
    - puis afficher le nouveau contenu avec SetResultsInfos()

    SetResultsInfos() lance la recherche des données dans ma base de données (un fichier .txt d'un peu moins de 800ko) par la fonction SearchResults() (prenant en paramètres le flux de ma base de données, un point de repère en gros pour déplacer le curseur dans lea base de données pour éviter de rechercher un doublon vu que certains modèles d'imprimantes ont le même nom, puis le modèle d'imprimante sélectionné), puis les attribue aux QLabel correspondant grâce à AssignResults() (prenant en paramètre mon flux).

    Bien entendu, à chaque fois que je passe en paramètre mon flux, c'est par référence, le reste étant des string ou QString de 10-15 caractères maxi, je n'utilise pas de référence.

    Tout ceci se termine par ShowResultsLabels() qui sert à afficher les QLabel.

    Mes QLabel ainsi que tous mes QPusButton sont initialiser dès le lancement du programme et sont tous masqués. Ils sont alors affichés et/ou masqué à volonté en fonction des boutons cliqués.

    Toutes les informations lues depuis ma base de données sont stockées dans des std::vector<std::string> qui sont vidés (via leur fonction clear()) à chaque fois que je reviens sur la même page (exemple, j'affiche un résultat donc mon vector se rempli pour l'afficher, je reviens au début du programme, je refais tout le chemin pour afficher un nouveau résultat, et juste avant d'afficher ce résultat, c'est là que le vector se vide).

  6. #26
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Je ne mets pas le main, ne servant qu'à "lancer" mon programme (donc ne contient presque rien), ni les Init.cpp et Init.h (ne contenant que des valeurs constantes : tailles de polices, positions...).

    MainWindow.h
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    #ifndef MAINWINDOW
    #define MAINWINDOW
     
    #include <QtWidgets>
    #include <vector>
    #include <QVector>
    #include <fstream>
    #include "Init.h"
     
    class MainWindow : public QWidget
    {
        Q_OBJECT
     
        public:
        MainWindow();
     
        signals:
        void markClicked(QString mark);
        void seriesClicked(QString series);
        void modelsClicked(QString series);
     
        private slots:
        void HomeWindow();
        void RunMark(QString mark);
        void RunSeries(QString series);
        void RunResults(QString model);
        void InkClicked();
        void LaserClicked();
        void NextSeriesButtonClicked();
        void PreviousSeriesButtonClicked();
        void NextModelsButtonClicked();
        void PreviousModelsButtonClicked();
     
        private:
        //Labels's list for buttons
        std::vector<std::string> seriesTable;
        std::vector<std::string> modelsTable;
        std::vector<std::string> resultsTable;
        std::vector<std::string> epsonInkResultsTable;
     
        //Buttons's lists
        QVector<QPushButton*> markButton;
        QVector<QPushButton*> seriesButton;
        QVector<QPushButton*> modelsButton;
        QVector<QLabel*> resultsLabel;
        QVector<QLabel*> epsonInkresultsLabel;
        QVector<QPushButton*> epsonInkresultsButton;
     
        int myPage;
        int myModelPage;
        int pageNumber;
        int modelPageNumber;
        std::string myMark;
        std::string myType;
        std::string mySeries;
        std::string myModel;
     
     
        //Type window's buttons
        QPushButton *inkButton;
        QPushButton *laserButton;
     
        QLabel *seriesLabel;
        QPushButton *markPic;
        QPushButton *logo;
        QPushButton *nextSeriesButton;
        QPushButton *previousSeriesButton;
        QPushButton *nextModelsButton;
        QPushButton *previousModelsButton;
        QPushButton *exitButton;
     
        //Function to read data word by word from file
        std::string ReadInfos(std::ifstream &file);
     
        //Function to search the series in the file to fill the table
        void SearchDatas(std::ifstream &file, std::vector<std::string> &table, std::string series);
     
        //Function to fill the table from the file
        void AssignSeries(std::ifstream &file, std::vector<std::string> &table);
     
        //Function to search the series in the file to fill the table only for the results window
        void SearchResults(std::ifstream &file, std::string series, std::string model);
     
        //Function to fill the table from the file only for the results window
        void AssignResults(std::ifstream &file);
     
        //Function to search the series in the file to fill the table only for the Epson Ink results window
        void SearchEpsonInkResults(std::ifstream &file, std::string series, std::string model);
     
        //Function to fill the table from the file only for the Epson Ink results window
        void AssignEpsonInkResults(std::ifstream &file);
     
        //Functions to hide elements
        void HideTypeButtons();
        void HideSeriesButtons();
        void HideModelsButtons();
        void HideResultsLabels();
        void HideEpsonInkResultsElements();
     
        //Functions to show buttons and labels
        void ShowSeriesButton(int number);
        void ShowModelsButton(int number);
        void ShowResultsLabels();
        void ShowEpsonInkResultsElements();
     
        //Functions to set infos on buttons and labels
        void SetSeriesInfos();
        void SetModelsInfos();
        void SetResultsInfos();
        void SetEpsonInkResultsInfos();
     
        //Functions to generate the right content of the window
        void TypeWindow(std::string mark);
        void SeriesWindowGeneration(std::string series);
        void RunEpsonInkResults(QString model);
     
        //Function to determine the number of page to display
        int pageNumberDetermination(std::vector<std::string> &table, int buttonNumber);
     
        void Button();
        void Slots();
     
     
    };
     
    #endif // MAINWINDOW
    MainWindow.cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    #include "MainWindow.h"
     
    MainWindow::MainWindow() : QWidget()
    {
        setMaximumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setMinimumSize(Init::WINDOW_WIDTH, Init::WINDOW_HEIGHT);
        setWindowTitle(tr("Ink Finder"));
     
        Button();
     
        Slots();
    }
     
    //############### Private functions ###############
    void MainWindow::Button()
    {
        //###########################################################
        //############## Mark chooser window's buttons ##############
        //###########################################################
     
        std::ifstream file("database.txt", std::ifstream::in);
     
        //Initialisation of the QSignalMapper
        QSignalMapper *markSignalMapper = new QSignalMapper(this);
     
        std::string mark;
     
        for (int n = 0; n < 6; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::MARK_COL_1;
            else
                x = Init::MARK_COL_2;
     
            if (n < 2)
                y = Init::MARK_LIN_1;
            else if (n < 4)
                y = Init::MARK_LIN_2;
            else
                y = Init::MARK_LIN_3;
     
            mark = ReadInfos(file);
     
            //Setting button's attributes
            markButton.push_back(new QPushButton(this));
            markButton[n]->setIcon(QIcon(QString::fromStdString("pictures/" + mark + ".png")));
            markButton[n]->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
            markButton[n]->setFlat(true);
            markButton[n]->setGeometry(x, y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
     
            //Connection and mapping of the QSignalMapper
            connect(markButton[n], SIGNAL(clicked(bool)), markSignalMapper, SLOT(map()));
            markSignalMapper->setMapping(markButton[n], QString::fromStdString(mark));
        }
        connect(markSignalMapper, SIGNAL(mapped(QString)), this, SIGNAL(markClicked(QString)));
     
     
        //###########################################################
        //############## Type chooser window's buttons ##############
        //###########################################################
     
        inkButton = new QPushButton("Jet d'encre", this);
        inkButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_1, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        inkButton->setFont(Init::FONT1);
        inkButton->hide();
     
        laserButton = new QPushButton("Laser", this);
        laserButton->setGeometry(Init::TYPE_COL_1, Init::TYPE_LIN_2, Init::TYPE_WIDTH, Init::TYPE_HEIGHT);
        laserButton->setFont(Init::FONT1);
        laserButton->hide();
     
        //###########################################################
        //############# Series chooser window's buttons #############
        //###########################################################
     
        for (int n = 0; n < 10; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 2 == 0)
                x = Init::HOME_COL_1;
            else
                x = Init::HOME_COL_2;
     
            if (n <= 1)
                y = Init::HOME_LIN_1;
            else if (n <= 3)
                y = Init::HOME_LIN_2;
            else if (n <= 5)
                y = Init::HOME_LIN_3;
            else if (n <= 7)
                y = Init::HOME_LIN_4;
            else
                y = Init::HOME_LIN_5;
     
            //Setting button's attributes
            seriesButton.push_back(new QPushButton(this));
            seriesButton[n]->setFont(Init::FONT6);
            seriesButton[n]->hide();
            seriesButton[n]->setGeometry(x, y, Init::HOME_WIDTH, Init::HOME_HEIGHT);
        }
     
        //###########################################################
        //############# Models chooser window's buttons #############
        //###########################################################
     
        for (int n = 0; n < 30; n++)
        {
            //Determinate coords of each button
            int x, y;
            if (n % 5 == 0)
                x = Init::MODEL_COL_1;
            else if ((n - 1) % 5 == 0)
                x = Init::MODEL_COL_2;
            else if ((n - 2) % 5 == 0)
                x = Init::MODEL_COL_3;
            else if ((n - 3) % 5 == 0)
                x = Init::MODEL_COL_4;
            else
                x = Init::MODEL_COL_5;
     
            if (n <= 4)
                y = Init::MODEL_LIN_1;
            else if (n <= 9)
                y = Init::MODEL_LIN_2;
            else if (n <= 14)
                y = Init::MODEL_LIN_3;
            else if (n <= 19)
                y = Init::MODEL_LIN_4;
            else if (n <= 24)
                y = Init::MODEL_LIN_5;
            else
                y = Init::MODEL_LIN_6;
     
            //Setting button's attributes
            modelsButton.push_back(new QPushButton(this));
            modelsButton[n]->setFont(Init::FONT2);
            modelsButton[n]->hide();
            modelsButton[n]->setGeometry(x, y, Init::MODEL_WIDTH, Init::MODEL_HEIGHT);
        }
     
        //###########################################################
        //################# Common window's buttons #################
        //###########################################################
     
        logo = new QPushButton(QIcon("pictures/logo.png"), "", this);
        logo->setIconSize(QSize(Init::LOGO_WIDTH, Init::LOGO_HEIGHT));
        logo->setGeometry(Init::LOGO_X, Init::LOGO_Y, Init::LOGO_WIDTH, Init::LOGO_HEIGHT);
        logo->setFlat(true);
     
        markPic = new QPushButton(this);
        markPic->setIconSize(QSize(Init::MARK_WIDTH, Init::MARK_HEIGHT));
        markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->setFlat(true);
        markPic->hide();
     
        seriesLabel = new QLabel(this);
        seriesLabel->setGeometry(Init::SERIES_LABEL_X, Init::SERIES_LABEL_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        seriesLabel->setFont(Init::FONT1);
        seriesLabel->setAlignment(Qt::AlignCenter);
        seriesLabel->hide();
     
        nextSeriesButton = new QPushButton(QIcon("pictures/next.png"), "", this);
        nextSeriesButton->setGeometry(Init::EXIT_X - 75, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        nextSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        nextSeriesButton->setFlat(true);
        nextSeriesButton->hide();
     
        previousSeriesButton = new QPushButton(QIcon("pictures/previous.png"), "", this);
        previousSeriesButton->setGeometry(Init::EXIT_X - 150, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        previousSeriesButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        previousSeriesButton->setFlat(true);
        previousSeriesButton->hide();
     
        nextModelsButton = new QPushButton(QIcon("pictures/next.png"), "", this);
        nextModelsButton->setGeometry(Init::EXIT_X - 75, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        nextModelsButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        nextModelsButton->setFlat(true);
        nextModelsButton->hide();
     
        previousModelsButton = new QPushButton(QIcon("pictures/previous.png"), "", this);
        previousModelsButton->setGeometry(Init::EXIT_X - 150, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        previousModelsButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        previousModelsButton->setFlat(true);
        previousModelsButton->hide();
     
        exitButton = new QPushButton(QIcon("pictures/back.png"), "", this);
        exitButton->setGeometry(Init::EXIT_X, Init::EXIT_Y, Init::EXIT_WIDTH, Init::EXIT_HEIGHT);
        exitButton->setIconSize(QSize(Init::EXIT_WIDTH, Init::EXIT_HEIGHT));
        exitButton->hide();
     
        //###########################################################
        //################# Result window's buttons #################
        //###########################################################
     
        for (int n = 0; n < 44; n++)
        {
            resultsLabel.push_back(new QLabel(this));
     
            //Determinate coords of each label
            int x, y;
     
            if (n <= 5)
                y = Init::FINAL_LIN_1;
            else if (n <= 11)
                y = Init::FINAL_LIN_2;
            else if (n <= 17)
                y = Init::FINAL_LIN_3;
            else if (n <= 23)
                y = Init::FINAL_LIN_4;
            else if (n <= 29)
                y = Init::FINAL_LIN_5;
            else if (n <= 35)
                y = Init::FINAL_LIN_6;
            else if (n <= 41)
                y = Init::FINAL_LIN_7;
            else
                y = Init::FINAL_LIN_8;
     
            if (n % 6 == 0)
                x = Init::FINAL_COL_1;
            else if ((n - 1) % 6 == 0)
            {
                x = Init::FINAL_COL_2;
                if (n != 43)
                    if (y != Init::FINAL_LIN_3 && y != Init::FINAL_LIN_5 && y != Init::FINAL_LIN_7)
                        resultsLabel[n]->setStyleSheet("QLabel { background-color : black; color : white}");
            }
            else if ((n - 2) % 6 == 0)
            {
                x = Init::FINAL_COL_3;
                if (y != Init::FINAL_LIN_3 && y != Init::FINAL_LIN_5 && y != Init::FINAL_LIN_7)
                    resultsLabel[n]->setStyleSheet("QLabel { background-color : magenta}");
            }
            else if ((n - 3) % 6 == 0)
            {
                x = Init::FINAL_COL_4;
                if (y != Init::FINAL_LIN_3 && y != Init::FINAL_LIN_5 && y != Init::FINAL_LIN_7)
                    resultsLabel[n]->setStyleSheet("QLabel { background-color : cyan}");
            }
            else if ((n - 4) % 6 == 0)
            {
                x = Init::FINAL_COL_5;
                if (y != Init::FINAL_LIN_3 && y != Init::FINAL_LIN_5 && y != Init::FINAL_LIN_7)
                    resultsLabel[n]->setStyleSheet("QLabel { background-color : yellow}");
            }
            else
                x = Init::FINAL_COL_6;
     
            //Setting label's attributes
            if (n == 0)
                resultsLabel[n]->setFont(Init::FONT4);
            else
                resultsLabel[n]->setFont(Init::FONT2);
     
            resultsLabel[n]->hide();
            if (n == 43)
                resultsLabel[n]->setGeometry(x, y, Init::FINAL_WIDTH * 5, Init::FINAL_HEIGHT * 2);
            else
            {
                resultsLabel[n]->setGeometry(x, y, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
                resultsLabel[n]->setAlignment(Qt::AlignCenter);
            }
        }
     
        //Setting text to labels
        resultsLabel[1]->setText("Noir");
        resultsLabel[2]->setText("Magenta");
        resultsLabel[3]->setText("Cyan");
        resultsLabel[4]->setText("Jaune");
        resultsLabel[5]->setText("Type");
        resultsLabel[6]->setText("Référence :");
        resultsLabel[11]->setText("NORMAL");
        resultsLabel[12]->setText("Nombre de pages*");
        resultsLabel[18]->setText("Référence :");
        resultsLabel[23]->setText("XL");
        resultsLabel[24]->setText("Nombre de pages*");
        resultsLabel[30]->setText("Référence :");
        resultsLabel[36]->setText("Nombre de pages*");
        resultsLabel[43]->setText("<i>* Données constructeur (nombre de pages A4)<br>Pour les cartouches photos le nombre de pages estimées est le nombre de photos 10x15</i>");
     
        //###########################################################
        //############ Epson Ink Result window's buttons ############
        //###########################################################
     
        for (int n = 0; n < 5; n++)
        {
            epsonInkresultsLabel.push_back(new QLabel(this));
            epsonInkresultsLabel[n]->setFont(Init::FONT2);
            epsonInkresultsLabel[n]->setAlignment(Qt::AlignCenter);
            epsonInkresultsLabel[n]->hide();
        }
     
        epsonInkresultsLabel[0]->setText("Capacité");
        epsonInkresultsLabel[0]->setGeometry(Init::FINAL_EPSON_COL_1, Init::FINAL_EPSON_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        epsonInkresultsLabel[1]->setText("Noir");
        epsonInkresultsLabel[1]->setGeometry(Init::FINAL_EPSON_COL_2 + ((Init::FINAL_EPSON_WIDTH - Init::FINAL_WIDTH) / 2), Init::FINAL_EPSON_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        epsonInkresultsLabel[2]->setText("Couleurs");
        epsonInkresultsLabel[2]->setGeometry(Init::FINAL_EPSON_COL_3 + ((Init::FINAL_EPSON_WIDTH - Init::FINAL_WIDTH) / 2), Init::FINAL_LIN_1, Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        epsonInkresultsLabel[3]->setText("NORMAL");
        epsonInkresultsLabel[3]->setGeometry(Init::FINAL_EPSON_COL_1, Init::FINAL_EPSON_LIN_2 + ((Init::FINAL_EPSON_HEIGHT - Init::FINAL_HEIGHT) / 2), Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
        epsonInkresultsLabel[4]->setText("XL");
        epsonInkresultsLabel[4]->setGeometry(Init::FINAL_EPSON_COL_1, Init::FINAL_EPSON_LIN_3 + ((Init::FINAL_EPSON_HEIGHT - Init::FINAL_HEIGHT) / 2), Init::FINAL_WIDTH, Init::FINAL_HEIGHT);
     
        for (int n = 0; n < 4; n++)
        {
            int x, y;
            if (n % 2 == 0)
                x = Init::FINAL_EPSON_COL_2;
            else
                x = Init::FINAL_EPSON_COL_3;
     
            if (n <= 1)
                y = Init::FINAL_EPSON_LIN_2;
            else
                y = Init::FINAL_EPSON_LIN_3;
     
            //Setting button's attributes
            epsonInkresultsButton.push_back(new QPushButton(this));
            epsonInkresultsButton[n]->setIconSize(QSize(Init::FINAL_EPSON_WIDTH, Init::FINAL_EPSON_HEIGHT));
            epsonInkresultsButton[n]->setFlat(true);
            epsonInkresultsButton[n]->hide();
            epsonInkresultsButton[n]->setGeometry(x, y, Init::FINAL_EPSON_WIDTH, Init::FINAL_EPSON_HEIGHT);
        }
    }
     
    void MainWindow::Slots()
    {
        connect(this, SIGNAL(markClicked(QString)), this, SLOT(RunMark(QString)));
        connect(this, SIGNAL(seriesClicked(QString)), this, SLOT(RunSeries(QString)));
        connect(this, SIGNAL(modelsClicked(QString)), this, SLOT(RunResults(QString)));
        connect(exitButton, SIGNAL(clicked(bool)), this, SLOT(HomeWindow()));
        connect(nextSeriesButton, SIGNAL(clicked(bool)), this, SLOT(NextSeriesButtonClicked()));
        connect(previousSeriesButton, SIGNAL(clicked(bool)), this, SLOT(PreviousSeriesButtonClicked()));
        connect(nextModelsButton, SIGNAL(clicked(bool)), this, SLOT(NextModelsButtonClicked()));
        connect(previousModelsButton, SIGNAL(clicked(bool)), this, SLOT(PreviousModelsButtonClicked()));
        connect(inkButton, SIGNAL(clicked(bool)), this, SLOT(InkClicked()));
        connect(laserButton, SIGNAL(clicked(bool)), this, SLOT(LaserClicked()));
    }
     
    //Function that read datas in the database file
    std::string MainWindow::ReadInfos(std::ifstream &file)
    {
        std::string word;
        file >> word;
        return word;
    }
     
    //Function that search datas in the database file
    void MainWindow::SearchDatas(std::ifstream &database, std::vector<std::string> &table, std::string series)
    {
        std::string line;
        while(getline(database, line))
        {
            if(line == series)
            {
                AssignSeries(database, table);
            }
        }
    }
     
    //Function that generates the series table from datas read from the database file
    void MainWindow::AssignSeries(std::ifstream &database, std::vector<std::string> &table)
    {
        std::string word = "";
        while (word != "endlist")
        {
            word = ReadInfos(database);
            if (word != "endlist")
                table.push_back(word);
        }
    }
     
    void MainWindow::SearchResults(std::ifstream &file, std::string series, std::string model)
    {
        std::string line;
        while(getline(file, line))
        {
            if(line == series)
            {
                while(getline(file, line))
                {
                    if(line == model)
                    {
                        AssignResults(file);
                    }
                }
            }
        }
    }
     
    void MainWindow::SearchEpsonInkResults(std::ifstream &file, std::string series, std::string model)
    {
        std::string line;
        while(getline(file, line))
        {
            if(line == series)
            {
                while(getline(file, line))
                {
                    if(line == model)
                    {
                        AssignEpsonInkResults(file);
                    }
                }
            }
        }
    }
     
    void MainWindow::AssignResults(std::ifstream &file)
    {
        resultsLabel[0]->setText(QString::fromStdString(ReadInfos(file)));
     
        for (int n = 7; n < 11; n++)
            resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
     
        for (int n = 19; n < 23; n++)
            resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
     
        for (int n = 31; n < 35; n++)
            resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
     
        for (int n = 13; n < 17; n++)
            resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
     
        for (int n = 25; n < 29; n++)
            resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
     
        for (int n = 37; n < 41; n++)
            resultsLabel[n]->setText(QString::fromStdString(ReadInfos(file)));
    }
     
    void MainWindow::AssignEpsonInkResults(std::ifstream &file)
    {
        for (int n = 0; n < 4; n++)
        {
            epsonInkresultsButton[n]->setIcon(QIcon(QString::fromStdString("pictures/epson/" + ReadInfos(file) + ".png")));
        }
    }
     
    //Function that generates the Type window (to choose between ink and laser)
    void MainWindow::TypeWindow(std::string mark)
    {
        myMark = mark;
        markPic->setIcon(QIcon(QString::fromStdString("pictures/" + myMark + ".png")));
        markPic->show();
     
        //Hiding all mark buttons
        for (int n = 0; n < 6; n++)
            markButton[n]->hide();
     
        inkButton->show();
        laserButton->show();
     
        exitButton->show();
    }
     
    //Function that hide all type buttons
    void MainWindow::HideTypeButtons()
    {
        inkButton->hide();
        laserButton->hide();
    }
     
    //Function that hide all series buttons
    void MainWindow::HideSeriesButtons()
    {
        for (int n = 0; n < 10; n++)
            seriesButton[n]->hide();
     
        nextSeriesButton->hide();
        previousSeriesButton->hide();
    }
     
    //Function that hide all models buttons
    void MainWindow::HideModelsButtons()
    {
        for (int n = 0; n < 30; n++)
            modelsButton[n]->hide();
     
        nextModelsButton->hide();
        previousModelsButton->hide();
    }
     
    //Function that hide all results labels
    void MainWindow::HideResultsLabels()
    {
        for (int n = 0; n < 44; n++)
            resultsLabel[n]->hide();
    }
     
    void MainWindow::HideEpsonInkResultsElements()
    {
        for (int n = 0; n < 5; n++)
            epsonInkresultsLabel[n]->hide();
     
        for (int n = 0; n < 4; n++)
            epsonInkresultsButton[n]->hide();
    }
     
    //Function that determines which buttons to display
    void MainWindow::ShowSeriesButton(int number)
    {
        HideSeriesButtons();
     
        //Showing buttons
        for (int i = 0; i < number; i++)
            seriesButton[i]->show();
     
        //Showing 'next' and 'previous' as it's needed
        if (myPage == 1)
        {
            if (pageNumber > 1)
                nextSeriesButton->show();
            else
                nextSeriesButton->hide();
     
            previousSeriesButton->hide();
        }
        if (myPage == pageNumber && pageNumber > 1)
        {
            nextSeriesButton->hide();
            previousSeriesButton->show();
        }
        if (myPage > 1 && myPage < pageNumber)
        {
            nextSeriesButton->show();
            previousSeriesButton->show();
        }
    }
     
    void MainWindow::ShowModelsButton(int number)
    {
        HideModelsButtons();
     
        seriesLabel->show();
     
        //Showing buttons
        for (int i = 0; i < number; i++)
            modelsButton[i]->show();
     
        //Showing 'next' and 'previous' as it's needed
        if (myPage == 1)
        {
            if (pageNumber > 1)
                nextModelsButton->show();
            else
                nextModelsButton->hide();
     
            previousModelsButton->hide();
        }
        if (myPage == pageNumber && pageNumber > 1)
        {
            nextModelsButton->hide();
            previousModelsButton->show();
        }
        if (myPage > 1 && myPage < pageNumber)
        {
            nextModelsButton->show();
            previousModelsButton->show();
        }
    }
     
    void::MainWindow::ShowResultsLabels()
    {
        for (int n = 0; n < 44; n++)
            resultsLabel[n]->show();
    }
     
    void MainWindow::ShowEpsonInkResultsElements()
    {
        for (int n = 0; n < 5; n++)
            epsonInkresultsLabel[n]->show();
     
        for (int n = 0; n < 4; n++)
            epsonInkresultsButton[n]->show();
    }
     
    //Function that generates the Series window (to choose between different series)
    void MainWindow::SeriesWindowGeneration(std::string series)
    {
        myPage = 1;
     
        //Resetting the table
        seriesTable.clear();
     
        HideTypeButtons();
     
        //Generating the table
        std::ifstream file("database.txt", std::ifstream::in);
        SearchDatas(file, seriesTable, series + myType);
     
        SetSeriesInfos();
    }
     
    void MainWindow::SetSeriesInfos()
    {
        int max = pageNumberDetermination(seriesTable, 10);
     
        //Initialisation of the QSignalMapper
        QSignalMapper *seriesSignalMapper = new QSignalMapper(this);
     
        //Setting text to button
        QString seriesName;
        for (int n = 0; n < max; n++)
        {
            seriesName = QString::fromStdString(seriesTable[n + (10 * (myPage - 1))]);
            seriesButton[n]->setText(seriesName);
     
            //Connection and mapping of the QSignalMapper
            connect(seriesButton[n], SIGNAL(clicked(bool)), seriesSignalMapper, SLOT(map()));
            seriesSignalMapper->setMapping(seriesButton[n], seriesName);
        }
     
        connect(seriesSignalMapper, SIGNAL(mapped(QString)), this, SIGNAL(seriesClicked(QString)));
     
        ShowSeriesButton(max);
    }
     
    void MainWindow::SetModelsInfos()
    {
        int max = pageNumberDetermination(modelsTable, 30);
     
        //Initialisation of the QSignalMapper
        QSignalMapper *modelsSignalMapper = new QSignalMapper(this);
     
        //Setting text to button
        QString modelsName;
        for (int n = 0; n < max; n++)
        {
            modelsName = QString::fromStdString(modelsTable[n + (30 * (myPage - 1))]);
            modelsButton[n]->setText(modelsName);
     
            //Connection and mapping of the QSignalMapper
            connect(modelsButton[n], SIGNAL(clicked(bool)), modelsSignalMapper, SLOT(map()));
            modelsSignalMapper->setMapping(modelsButton[n], modelsName);
        }
     
        connect(modelsSignalMapper, SIGNAL(mapped(QString)), this, SIGNAL(modelsClicked(QString)));
     
        ShowModelsButton(max);
    }
     
    void MainWindow::SetResultsInfos()
    {
        seriesLabel->setText(QString::fromStdString(mySeries + "<br>" + myModel));
     
        if (myType == "Ink")
        {
            resultsLabel[0]->setText("Cartouche");
            resultsLabel[35]->setText("PHOTO");
        }
        else
        {
            resultsLabel[0]->setText("Toner");
            resultsLabel[35]->setText("XXL");
        }
     
        std::ifstream file("database.txt", std::ifstream::in);
        SearchResults(file, myMark + mySeries + myType + "Series", mySeries + "<br>" + myModel);
     
        ShowResultsLabels();
    }
     
    void MainWindow::SetEpsonInkResultsInfos()
    {
        seriesLabel->setText(QString::fromStdString(mySeries + "<br>" + myModel));
     
        std::ifstream file("database.txt", std::ifstream::in);
        SearchEpsonInkResults(file, myMark + mySeries + myType + "Series", mySeries + "<br>" + myModel);
     
        ShowEpsonInkResultsElements();
    }
     
    //Function to determine the number of page and buttons to show
    int MainWindow::pageNumberDetermination(std::vector<std::string> &table, int buttonNumber)
    {
        //Calculating number of pages
        pageNumber = table.size() / buttonNumber;
     
        //Calculating number of series to show
        if ((table.size() % buttonNumber) != 0)
            pageNumber++;
     
        if (myPage == pageNumber)
        {
            if (table.size() % buttonNumber == 0)
                return buttonNumber;
            else
                return table.size() % buttonNumber;
        }
        else if (myPage < pageNumber)
            return buttonNumber;
     
        return 0;
    }
     
    //#############################################
    //############### Private slots ###############
    //#############################################
     
    //Slot that reset the actual window to the home window
    void MainWindow::HomeWindow()
    {
        HideTypeButtons();
        HideSeriesButtons();
        HideModelsButtons();
        HideResultsLabels();
        HideEpsonInkResultsElements();
     
        markPic->setGeometry(Init::MARK_CENTER_X, Init::MARK_CENTER_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
        markPic->hide();
        exitButton->hide();
        seriesLabel->hide();
     
        for (int n = 0; n < markButton.size(); n++)
            markButton[n]->show();
    }
     
    //Slot that launch the function to generate the Type window by sending the mark
    void MainWindow::RunMark(QString mark)
    {
        TypeWindow(mark.toStdString());
    }
     
    //Slot that launch the function to generate the Models window by sending the series
    void MainWindow::RunSeries(QString series)
    {
        HideSeriesButtons();
     
        myPage = 1;
        mySeries = series.toStdString();
     
        markPic->setGeometry(Init::MARK_SERIES_X, Init::MARK_SERIES_Y, Init::MARK_WIDTH, Init::MARK_HEIGHT);
     
        seriesLabel->setText(series);
     
        //Resetting the table
        modelsTable.clear();
     
        HideModelsButtons();
     
        //Generating the table
        std::ifstream file("database.txt", std::ifstream::in);
        SearchDatas(file, modelsTable, myMark + mySeries + myType + "Series");
     
        SetModelsInfos();
    }
     
    //Slot that launch the function to generate the Results window by sending the model
    void MainWindow::RunResults(QString model)
    {
        if (myMark == "epson" && myType == "Ink")
            RunEpsonInkResults(model);
        else
        {
     
            myModel = model.toStdString();
     
            HideModelsButtons();
     
            SetResultsInfos();
        }
    }
     
    //Slot that launch the function to generate the Results window by sending the model
    void MainWindow::RunEpsonInkResults(QString model)
    {
        myModel = model.toStdString();
     
        HideModelsButtons();
     
        SetEpsonInkResultsInfos();
    }
     
    //Slots that launch the right functions depending of the mark and the clicked button
    void MainWindow::InkClicked()
    {
        myType = "Ink";
        SeriesWindowGeneration(myMark);
    }
     
    void MainWindow::LaserClicked()
    {
        myType = "Laser";
        SeriesWindowGeneration(myMark);
    }
     
    //Slots that determines the next and previous button's actions
    void MainWindow::NextSeriesButtonClicked()
    {
        myPage++;
        SetSeriesInfos();
    }
     
    void MainWindow::PreviousSeriesButtonClicked()
    {
        myPage--;
        SetSeriesInfos();
    }
     
    void MainWindow::NextModelsButtonClicked()
    {
        myPage++;
        SetModelsInfos();
    }
     
    void MainWindow::PreviousModelsButtonClicked()
    {
        myPage--;
        SetModelsInfos();
    }

  7. #27
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 860
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 860
    Points : 219 062
    Points
    219 062
    Billets dans le blog
    120
    Par défaut
    Désolé aussi du retard.
    Code c : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    //Initialisation of the QSignalMapper
        QSignalMapper *modelsSignalMapper = new QSignalMapper(this);
     
        //Setting text to button
        QString modelsName;
        for (int n = 0; n < max; n++)
        {
            modelsName = QString::fromStdString(modelsTable[n + (30 * (myPage - 1))]);
            modelsButton[n]->setText(modelsName);
     
            //Connection and mapping of the QSignalMapper
            connect(modelsButton[n], SIGNAL(clicked(bool)), modelsSignalMapper, SLOT(map()));
            modelsSignalMapper->setMapping(modelsButton[n], modelsName);
        }
     
        connect(modelsSignalMapper, SIGNAL(mapped(QString)), this, SIGNAL(modelsClicked(QString)));
    J'imagine qu'il n'y a pas de nettoyage, ni des connexions, ni des variables allouées. Du coup, je pense que le systèmes de signaux/slots et overfloodé par pleins de connexions dans tous les sens, ralentissant l'application.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  8. #28
    Nouveau membre du Club
    Homme Profil pro
    Formateur en informatique
    Inscrit en
    Février 2015
    Messages
    59
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Seine Maritime (Haute Normandie)

    Informations professionnelles :
    Activité : Formateur en informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2015
    Messages : 59
    Points : 34
    Points
    34
    Par défaut
    Encore merci LittleWhite pour toute cette aide, et pas de retard, le plus important est la réponse.

    Vu que ce sujet est marqué comme résolu, j'en ai créé un autre (http://www.developpez.net/forums/d15...ent-programme/).

    Du coup j'ai eu un peu de temps pour chercher, et en effet il s'agit bien d'un problème de "nettoyage" des QSignalMapper.

    Comme indiqué dan la documentation de Qt, le temps que les boutons connectés via le QSignalMapper ne sont pas détruit, ce dernier ne l'est pas non plus, du coup à chaque passage sur la fonction qui génère les connections, plutôt que de réécrire "par-dessus", les nouvelles connections sont ajoutées à celles existantes et du coup des doublons apparaissent de plus en plus à mesure des utilisations.

    J'ai réglé le problème en ajoutant des delete pour supprimer les QSignalMapper et des removeMappings() aux endroits stratégiques de mon code.

    Dans mon autre sujet j'ai mis des exemples de mes modifications (car il y en a à d'autres endroits de mon code), dans le but de montrer le principe si cela peut service à un autre novice comme moi

    Encore Merci.

+ Répondre à la discussion
Cette discussion est résolue.
Page 2 sur 2 PremièrePremière 12

Discussions similaires

  1. fuite de mémoire ?
    Par salseropom dans le forum C
    Réponses: 2
    Dernier message: 12/01/2006, 16h19
  2. Réponses: 1
    Dernier message: 02/12/2005, 14h18
  3. fuite de mémoire
    Par mamag dans le forum MFC
    Réponses: 17
    Dernier message: 19/08/2005, 10h42
  4. Fuite de mémoire en utilisant le template list
    Par schtroumpf_farceur dans le forum Langage
    Réponses: 9
    Dernier message: 18/07/2005, 20h44
  5. Réponses: 8
    Dernier message: 17/10/2002, 12h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo