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
View File

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

View File

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

View File

@ -31,7 +31,7 @@ LVMainModel::~LVMainModel() {
}
}
bool LVMainModel::setCounrySource(const QString &path) {
bool LVMainModel::setCountriesSource(const QString &path) {
if (!m_countrysParser) {
m_countrysParser = new CountrysParser();
@ -103,6 +103,14 @@ void LVMainModel::setData(const UserData& 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) {
if (m_passwordError == passwordError)
return;
@ -138,15 +146,31 @@ bool LVMainModel::fNickname() const {
return _components & ShowExtraComponent::Nickname;
}
bool LVMainModel::fPassword() const {
return _components & ShowExtraComponent::Password;
}
bool LVMainModel::fEMail() const {
return _components & ShowExtraComponent::EMail;
}
bool LVMainModel::fRegister() const {
return _components & ShowExtraComponent::RegisterPage;
}
bool LVMainModel::fLogin() const {
return _components & ShowExtraComponent::LoginPage;
}
void LVMainModel::clear() {
emit clearView();
setData({});
}
QString LVMainModel::acceptButtonText() const {
return m_acceptButtonText;
}
void LVMainModel::setValidData(UserViewValidationData validationData) {
if (m_validationData == validationData)
return;
@ -191,29 +215,32 @@ void LVMainModel::checkValid(const UserData& data) {
bool passwordValidation = true;
if (m_validLvl & PasswordValidationLvl::Size8andMore) {
passwordValidation = passwordValidation &&
data.rawPassword().length() >= 8;
}
if (fPassword()) {
if (m_validLvl & PasswordValidationLvl::Size8andMore) {
passwordValidation = passwordValidation &&
data.rawPassword().length() >= 8;
}
if (m_validLvl & PasswordValidationLvl::NumberChars) {
passwordValidation = passwordValidation &&
data.rawPassword().contains(QRegularExpression("[0-9]"));
}
if (m_validLvl & PasswordValidationLvl::NumberChars) {
passwordValidation = passwordValidation &&
data.rawPassword().contains(QRegularExpression("[0-9]"));
}
if (m_validLvl & PasswordValidationLvl::LitinSmallChars) {
passwordValidation = passwordValidation &&
data.rawPassword().contains(QRegularExpression("[a-z]"));
}
if (m_validLvl & PasswordValidationLvl::LitinSmallChars) {
passwordValidation = passwordValidation &&
data.rawPassword().contains(QRegularExpression("[a-z]"));
}
if (m_validLvl & PasswordValidationLvl::LatinLargeChars) {
passwordValidation = passwordValidation &&
data.rawPassword().contains(QRegularExpression("[A-Z]"));
}
if (m_validLvl & PasswordValidationLvl::LatinLargeChars) {
passwordValidation = passwordValidation &&
data.rawPassword().contains(QRegularExpression("[A-Z]"));
}
if (m_validLvl & PasswordValidationLvl::ExtraChars) {
passwordValidation = passwordValidation &&
data.rawPassword().contains(QRegularExpression("[!@#$%^&*]"));
}
if (m_validLvl & PasswordValidationLvl::ExtraChars) {
passwordValidation = passwordValidation &&
data.rawPassword().contains(QRegularExpression("[!@#$%^&*]"));
}
result.setRawPassword(!passwordValidation);

View File

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

View File

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

View File

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

View File

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