Answer the question
In order to leave comments, you need to log in
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;
};
#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
Answer the question
In order to leave comments, you need to log in
Such a simple thing should be done simply in the form class and not fool around with the architecture where this is not required.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question