4
0
mirror of https://github.com/QuasarApp/QMLLoginView.git synced 2025-05-03 04:59:40 +00:00

added new iptions for control the qml view page.

This commit is contained in:
Andrei Yankovich 2021-01-17 14:09:26 +03:00
parent 9b4842846a
commit 3a056d66c5
7 changed files with 254 additions and 40 deletions

3
.gitignore vendored

@ -46,6 +46,9 @@ target_wrapper.*
# QtCreator CMake # QtCreator CMake
CMakeLists.txt.user* CMakeLists.txt.user*
CMakeFiles
*_autogen
cmake_install.cmake
# QtCreator 4.8< compilation database # QtCreator 4.8< compilation database
compile_commands.json compile_commands.json

@ -29,6 +29,10 @@ Page {
property bool firstName: (lognViewModel)? lognViewModel.fFirstName: false property bool firstName: (lognViewModel)? lognViewModel.fFirstName: false
property bool nickName: (lognViewModel)? lognViewModel.fNickname: false property bool nickName: (lognViewModel)? lognViewModel.fNickname: false
property bool email: (lognViewModel)? lognViewModel.fEMail: false property bool email: (lognViewModel)? lognViewModel.fEMail: false
property bool password: (lognViewModel)? lognViewModel.fPassword: false
property bool loginPage: (lognViewModel)? lognViewModel.fLogin: false
property bool registerPage: (lognViewModel)? lognViewModel.fRegister: false
property string acceptButtonText: (lognViewModel)? lognViewModel.acceptButtonText: false
property var lognViewModel: null property var lognViewModel: null
property bool registerNewUser: true property bool registerNewUser: true
@ -189,6 +193,7 @@ Page {
onTextChanged: { onTextChanged: {
content.paswordValidation() content.paswordValidation()
} }
visible: password
echoMode: TextInput.Password echoMode: TextInput.Password
} }
@ -198,7 +203,7 @@ Page {
placeholderText: qsTr("Confirm pasword") placeholderText: qsTr("Confirm pasword")
Layout.columnSpan: (content.width > 350)? 1 : 2; Layout.columnSpan: (content.width > 350)? 1 : 2;
Layout.fillWidth: true Layout.fillWidth: true
visible: conntent.isRegisterNewUser visible: conntent.isRegisterNewUser && password
onTextChanged: { onTextChanged: {
content.paswordValidation() content.paswordValidation()
@ -227,7 +232,12 @@ Page {
} }
LVMButton { LVMButton {
text: (conntent.isRegisterNewUser)? qsTr("SignUp") : qsTr("LogIn") text: acceptButtonText.length?
acceptButtonText:
(conntent.isRegisterNewUser)?
qsTr("SignUp"):
qsTr("LogIn")
visible: true visible: true
enabled: (conntent.errors && conntent.errors.noError) && enabled: (conntent.errors && conntent.errors.noError) &&
((conntent.isRegisterNewUser)? !pass2.hasError && termOfUse.checked: true) ((conntent.isRegisterNewUser)? !pass2.hasError && termOfUse.checked: true)

@ -31,7 +31,7 @@ LVMainModel::~LVMainModel() {
} }
} }
bool LVMainModel::setCounrySource(const QString &path) { bool LVMainModel::setCountriesSource(const QString &path) {
if (!m_countrysParser) { if (!m_countrysParser) {
m_countrysParser = new CountrysParser(); m_countrysParser = new CountrysParser();
@ -103,6 +103,14 @@ void LVMainModel::setData(const UserData& data) {
emit dataChanged(m_data); emit dataChanged(m_data);
} }
void LVMainModel::setAcceptButtonText(const QString &acceptButtonText) {
if (m_acceptButtonText == acceptButtonText)
return;
m_acceptButtonText = acceptButtonText;
emit acceptButtonTextChanged(m_acceptButtonText);
}
void LVMainModel::setPasswordError(QString passwordError) { void LVMainModel::setPasswordError(QString passwordError) {
if (m_passwordError == passwordError) if (m_passwordError == passwordError)
return; return;
@ -138,15 +146,31 @@ bool LVMainModel::fNickname() const {
return _components & ShowExtraComponent::Nickname; return _components & ShowExtraComponent::Nickname;
} }
bool LVMainModel::fPassword() const {
return _components & ShowExtraComponent::Password;
}
bool LVMainModel::fEMail() const { bool LVMainModel::fEMail() const {
return _components & ShowExtraComponent::EMail; return _components & ShowExtraComponent::EMail;
} }
bool LVMainModel::fRegister() const {
return _components & ShowExtraComponent::RegisterPage;
}
bool LVMainModel::fLogin() const {
return _components & ShowExtraComponent::LoginPage;
}
void LVMainModel::clear() { void LVMainModel::clear() {
emit clearView(); emit clearView();
setData({}); setData({});
} }
QString LVMainModel::acceptButtonText() const {
return m_acceptButtonText;
}
void LVMainModel::setValidData(UserViewValidationData validationData) { void LVMainModel::setValidData(UserViewValidationData validationData) {
if (m_validationData == validationData) if (m_validationData == validationData)
return; return;
@ -191,6 +215,7 @@ void LVMainModel::checkValid(const UserData& data) {
bool passwordValidation = true; bool passwordValidation = true;
if (fPassword()) {
if (m_validLvl & PasswordValidationLvl::Size8andMore) { if (m_validLvl & PasswordValidationLvl::Size8andMore) {
passwordValidation = passwordValidation && passwordValidation = passwordValidation &&
data.rawPassword().length() >= 8; data.rawPassword().length() >= 8;
@ -216,6 +241,8 @@ void LVMainModel::checkValid(const UserData& data) {
data.rawPassword().contains(QRegularExpression("[!@#$%^&*]")); data.rawPassword().contains(QRegularExpression("[!@#$%^&*]"));
} }
}
result.setRawPassword(!passwordValidation); result.setRawPassword(!passwordValidation);
setValidData(result); setValidData(result);

@ -28,29 +28,51 @@ namespace LoginView {
* by default: Size8andMore | LitinSmallChars | LatinLargeChars * by default: Size8andMore | LitinSmallChars | LatinLargeChars
*/ */
enum PasswordValidationLvl { enum PasswordValidationLvl {
/// Skip all validation of password
NoValidation = 0x00, NoValidation = 0x00,
/// Check size. Size must be large than 8 chars.
Size8andMore = 0x01, Size8andMore = 0x01,
/// Check chars. Password must be contains a numbers.
NumberChars = 0x02, NumberChars = 0x02,
/// Check chars. Password must be contains small chars.
LitinSmallChars = 0x04, LitinSmallChars = 0x04,
/// Check chars. Password must be contains large chars.
LatinLargeChars = 0x08, LatinLargeChars = 0x08,
/// Check chars. Password must be contains extra chars. Example: (%.~*^#).
ExtraChars = 0x10 ExtraChars = 0x10
}; };
/** /**
* @brief The ShowExtraComponent enum * @brief The ShowExtraComponent enum used for control of the components view.
* default Title | FirstName | LastName * default is All
*/ */
enum ShowExtraComponent { enum ShowExtraComponent {
/// No show any componets.
NoShow = 0x00, NoShow = 0x00,
/// Show Title of the qml page.
Title = 0x01, Title = 0x01,
/// Show first name input widget.
FirstName = 0x02, FirstName = 0x02,
/// Show last name input widget.
LastName = 0x04, LastName = 0x04,
/// Show email name input widget.
EMail = 0x08, EMail = 0x08,
/// Show nickname input widget.
Nickname = 0x10, Nickname = 0x10,
/// Show password input widget.
All = EMail | Title | FirstName | LastName | Nickname Password = 0x20,
/// Show register page.
RegisterPage = 0x40,
/// Show login page.
LoginPage = 0x80,
/// Show all widgets and pages.
All = EMail | Title | FirstName | LastName | Nickname | Password | RegisterPage | LoginPage
}; };
/**
* @brief The LVMainModel class is main model of the qml login view.
*/
class LOGINVIEW_EXPORT LVMainModel: public QObject class LOGINVIEW_EXPORT LVMainModel: public QObject
{ {
Q_OBJECT Q_OBJECT
@ -68,17 +90,18 @@ class LOGINVIEW_EXPORT LVMainModel: public QObject
Q_PROPERTY(UserData data READ data WRITE setData NOTIFY dataChanged) Q_PROPERTY(UserData data READ data WRITE setData NOTIFY dataChanged)
Q_PROPERTY(UserViewValidationData validationData READ validData WRITE setValidData NOTIFY validDataChanged) Q_PROPERTY(UserViewValidationData validationData READ validData WRITE setValidData NOTIFY validDataChanged)
Q_PROPERTY(QString passwordError READ passwordError WRITE setPasswordError NOTIFY passwordErrorChanged) Q_PROPERTY(QString passwordError READ passwordError WRITE setPasswordError NOTIFY passwordErrorChanged)
Q_PROPERTY(QString acceptButtonText READ acceptButtonText WRITE setAcceptButtonText NOTIFY acceptButtonTextChanged)
public: public:
explicit LVMainModel(const QString modelName, explicit LVMainModel(const QString modelName,
QObject *parent = nullptr); QObject *parent = nullptr);
~LVMainModel(); ~LVMainModel();
/** /**
* @brief setCounrySource - sets path to xml source file and extract list of countrys * @brief setCountriesSource This method sets path to xml source file and extract list of countrys
* @param path * @param path This is path to xml sources of countries
* @return true if the function finished successful * @return true if the function finished successful
*/ */
Q_INVOKABLE bool setCounrySource(const QString &path); Q_INVOKABLE bool setCountriesSource(const QString &path);
/** /**
* @brief init - prepare all items for use on qml. * @brief init - prepare all items for use on qml.
@ -86,84 +109,228 @@ public:
* @return true if the function finished successful * @return true if the function finished successful
*/ */
bool init(QQmlApplicationEngine *engine); bool init(QQmlApplicationEngine *engine);
/**
* @brief country This method return current country id.
* @return current country id.
*/
int country() const; int country() const;
/**
* @brief countryList This method retun list of availabel countries.
* @return string list of available countries.
*/
QStringList countryList() const; QStringList countryList() const;
/**
* @brief data This method return information of created or lofined user.
* @return return information of created or lofined user.
*/
UserData data() const; UserData data() const;
/**
* @brief validData This method return structure that display valid data.
* @return information about last validation.
*/
UserViewValidationData validData() const; UserViewValidationData validData() const;
/**
* @brief passwordError This method return text message about last password error.
* For get more information about password errors see the PasswordValidationLvl enum.
* @return Error message.
*/
QString passwordError() const; QString passwordError() const;
/**
* @brief countryCodeList This method return the list of ids of the countries.
* @return countries ids.
*/
QList<int> countryCodeList() const; QList<int> countryCodeList() const;
/**
* @brief loginRequest This method invoked wjet user click the login button.
*/
Q_INVOKABLE void loginRequest(); Q_INVOKABLE void loginRequest();
/**
* @brief rememberPasswordRequest This method invoked when user click the forgetpassword button.
*/
Q_INVOKABLE void rememberPasswordRequest(); Q_INVOKABLE void rememberPasswordRequest();
/**
* @brief registerRequest This method invoked when user click the signUp button.
*/
Q_INVOKABLE void registerRequest(); Q_INVOKABLE void registerRequest();
/**
* @brief showTermOfUseRequest This method invoked when user click the "show temr of use" button.
*/
Q_INVOKABLE void showTermOfUseRequest(); Q_INVOKABLE void showTermOfUseRequest();
/**
* @brief components This method return visible comonents of this model.
* @return return information about visible companents of Qml View. for more information see the ShowExtraComponent enum.
*/
ShowExtraComponent components() const; ShowExtraComponent components() const;
/**
* @brief setComponents This method sets visibel companents of the qml view.
* @param components This is enum with visible companents. For get more information see Thee ShowExtraComponent enum class.
*/
void setComponents(const ShowExtraComponent &components); void setComponents(const ShowExtraComponent &components);
/**
* @brief fTitle This method return Title visible state.
* @return Title visible state.
*/
bool fTitle() const; bool fTitle() const;
/**
* @brief fFirstName This method return first name visible state.
* @return first name visible state.
*/
bool fFirstName() const; bool fFirstName() const;
/**
* @brief fLastName This method return last name visible state.
* @return last name visible state.
*/
bool fLastName() const; bool fLastName() const;
/**
* @brief fNickname This method return nickname visible state.
* @return nickname visible state.
*/
bool fNickname() const; bool fNickname() const;
/**
* @brief fPassword This method return password visible state.
* @return password visible state.
*/
bool fPassword() const;
/**
* @brief fEMail This method return email visible state.
* @return email visible state.
*/
bool fEMail() const; bool fEMail() const;
/**
* @brief fRegister This method return register page visible state.
* @return register page visible state.
*/
bool fRegister() const;
/**
* @brief fLogin This method return login page visible state.
* @return login page visible state.
*/
bool fLogin() const;
/** /**
* @brief clear - clear all data from view * @brief clear - clear all data from view
*/ */
void clear(); void clear();
/**
* @brief acceptButtonText This method return alternative text of the accept button.
* @return alternative text of the accept button
*/
QString acceptButtonText() const;
public slots: public slots:
/**
* @brief setCountry This slot sets current contry. This method work with qml View and invoked when user change own country.
* @param country This is new country id.
*/
void setCountry(int country); void setCountry(int country);
/** /**
* @brief setData set new data for view * @brief setData sets new data for view on qml page.
* @param data * @param data new user data.
*/ */
void setData(const UserData &data); void setData(const UserData &data);
/**
* @brief setAcceptButtonText This method sets new test of the accept button. Use this method if you wnat change test on main button.
* @param acceptButtonText new text of the accept button.
*/
void setAcceptButtonText(const QString& acceptButtonText);
signals: signals:
/**
* @brief countryChanged This signal emited when country on page is will be changed.
* @param country new country id.
*/
void countryChanged(int country); void countryChanged(int country);
/**
* @brief countryListChanged This method emited when available country list will be changed.
*/
void countryListChanged(); void countryListChanged();
/**
* @brief countryCodeListChanged This method emited when available country list will be changed.
*/
void countryCodeListChanged(); void countryCodeListChanged();
/** /**
* @brief sigLoginRequest * @brief sigLoginRequest
* emited when user try login * emited when user try login.
*/ */
void sigLoginRequest(const UserData&); void sigLoginRequest(const UserData&);
/** /**
* @brief sigRegisterRequest * @brief sigRegisterRequest
* emited when user try create new accaunt * emited when user try create new accaunt.
*/ */
void sigRegisterRequest(const UserData&); void sigRegisterRequest(const UserData&);
/** /**
* @brief sigForgotPasswordRequest * @brief sigForgotPasswordRequest
* emited when user forgot own password * emited when user forgot own password.
*/ */
void sigForgotPasswordRequest(const UserData&); void sigForgotPasswordRequest(const UserData&);
/** /**
* @brief sigShowTermOfUseRequest * @brief sigShowTermOfUseRequest
* emited when user click on "Show term of use" button * emited when user click on "Show term of use" button.
*/ */
void sigShowTermOfUseRequest(); void sigShowTermOfUseRequest();
/**
* @brief dataChanged emited when data of qml form will be changed.
* @param data new data of qml form.
*/
void dataChanged(UserData data); void dataChanged(UserData data);
/**
* @brief validDataChanged This method emited when model is finished validation of the accepted user data.
* @param validationData this is validation results.
*/
void validDataChanged(UserViewValidationData validationData); void validDataChanged(UserViewValidationData validationData);
/**
* @brief passwordErrorChanged This method will be emoted when user password have a any error.
* @param passwordError This is new erro message of user password.
*/
void passwordErrorChanged(QString passwordError); void passwordErrorChanged(QString passwordError);
/** /**
* @brief showChanged - emited when show components changed * @brief showChanged This signal emited when rules of shows components will be changed
* @param ftitle
*/ */
void showChanged(); void showChanged();
/**
* @brief clearView This signal emited when need to clear a view. for more ifnformation see The clear method.
*/
void clearView(); void clearView();
/**
* @brief acceptButtonTextChanged This signal emited when text of the accept button will be changed.
* @param acceptButtonText Tihs is new test of the accept button.
*/
void acceptButtonTextChanged(QString acceptButtonText);
private: private:
void checkValid(const UserData &data); void checkValid(const UserData &data);
void setValidData(UserViewValidationData validationData); void setValidData(UserViewValidationData validationData);
@ -179,6 +346,7 @@ private:
UserViewValidationData m_validationData; UserViewValidationData m_validationData;
QString m_passwordError; QString m_passwordError;
ShowExtraComponent _components = ShowExtraComponent::All; ShowExtraComponent _components = ShowExtraComponent::All;
QString m_acceptButtonText;
}; };
} }

@ -12,6 +12,9 @@
namespace LoginView { namespace LoginView {
/**
* @brief The UserData class This is base class for save user data.
*/
class LOGINVIEW_EXPORT UserData class LOGINVIEW_EXPORT UserData
{ {
Q_GADGET Q_GADGET

@ -12,6 +12,9 @@
namespace LoginView { namespace LoginView {
/**
* @brief The UserViewValidationData class contains data of the last validation.
*/
class UserViewValidationData class UserViewValidationData
{ {
Q_GADGET Q_GADGET

@ -32,7 +32,7 @@ int main(int argc, char *argv[])
pathXML = QString(argv[1]); pathXML = QString(argv[1]);
} }
if (!loginModel.setCounrySource(pathXML)) { if (!loginModel.setCountriesSource(pathXML)) {
return -2; return -2;
} }