A
A
Armen2015-10-08 14:01:05
Qt
Armen, 2015-10-08 14:01:05

How to organize classes in terms of architecture?

Good afternoon! When writing a program in Qt, such a question arose about the architecture.
I am writing an object that represents the login page for the service. I planned to make a LoginScreen class (like a controller), inside which a pointer to an object (LoginScreenForm *form) (view), which contains a ready-made design on the
LoginScreen widgets, should have
QString getID () methods;
QString getPass();
void logIn(QSettings *settings).
login screen

#ifndef LOGINSCREEN_H
#define LOGINSCREEN_H
#include "loginscreenform.h"
#include <QSettings>
class LoginScreen : public QWidget
{
    Q_OBJECT
public:
    LoginScreen(LoginScreenForm *form);
signals:
    void enter();
public slots:
    QString getID();
    QString getPass();
    void logIn(QSettings *settings); //!< Вход на сайт с сохранением ID и пароля в настройки
    void close(); //!< Закрывает (скрывает) текущий QWidget
private:
    LoginScreenForm *form;
};

The enter () signal, which is given when the "Login" button is pressed.
But when writing, I encountered the fact that the LoginScreen class has to go to the LoginScreenForm members for all the data (ID, password), and since they are private, in the LoginScreenForm you will have to do the same methods:
QString getID();
QString getPass()
and signal enter().
LoginScreenForm
#ifndef LOGINSCREENFORM_H
#define LOGINSCREENFORM_H
#include <QWidget>
#include <QApplication>
#include <QDesktopWidget>
#include <QLabel>
#include <QLineEdit>
#include <QPushButton>
#include <QHBoxLayout>
#include <QVBoxLayout>
class LoginScreenForm : public QWidget
{
    Q_OBJECT
public:
    explicit LoginScreenForm(QLabel *id, QLineEdit *idLine, QLabel *password, QLineEdit *passwordLine, QPushButton *enter, QVBoxLayout *box, QHBoxLayout *enterBox, QWidget *parent = 0);
    enum ScreenOrientation {
        ScreenOrientationLockPortrait, //!< Портретная
        ScreenOrientationLockLandscape, //!< Ландшафтная
        ScreenOrientationAuto //!< Автоматическая
    };
    void setOrientation(ScreenOrientation orientation);
    void showExpanded();
    QString getID();
    QString getPass();
signals:
    void enter();
private:
    void resizeEvent(QResizeEvent * event);
    void SetScreenSizeAndPosition();
    QLabel *id; //!< Надпись "Введите ID"
    QLineEdit *idLine; //!< Поле для ввода ID
    QLabel *password; //!< Надпись "Пароль"
    QLineEdit *passwordLine; //!< Поле для ввода пароля
    QPushButton *enter; //!<Кнопка "Войти"
    QVBoxLayout *box; //!< Вертикальный лайоут для всех виджетов
    QHBoxLayout *enterBox; //!< Горизонтальный лайаут для кнопки "Войти" и спейсера

};
#endif // LoginScreenForm_H

That is, it turns out that the internal object redirects data to the parent, and that parent already requests the object.
Is this approach correct from an architectural point of view? If not, how to proceed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jacob E, 2015-10-08
@Zifix

Such a simple thing should be done simply in the form class and not fool around with the architecture where this is not required.

E
Eugene, 2015-10-08
@jk_action

A simple approach is to pass form data to enter enter(LoginData& data).
Difficult to smoke how MVC is implemented in QT (I tried it myself and did not light it up to the end).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question