Skip to content

Fix#289: Validate subset name for database#448

Merged
davidlatwe merged 4 commits intogetavalon:masterfrom
davidlatwe:Fix#289
Sep 17, 2019
Merged

Fix#289: Validate subset name for database#448
davidlatwe merged 4 commits intogetavalon:masterfrom
davidlatwe:Fix#289

Conversation

@davidlatwe
Copy link
Collaborator

@davidlatwe davidlatwe commented Sep 12, 2019

This PR resolve #289, Creator will ensure the subset name is valid for MongoDB.

What's changed?

  • Validate subset name in Creator, and the GUI will indicate the validation result

@davidlatwe
Copy link
Collaborator Author

Demo

creator

@tokejepsen
Copy link
Collaborator

Maybe this is helping the users too much, but maybe the "Invalid subset name..." message could tell the users which characters are invalid?

@davidlatwe
Copy link
Collaborator Author

Yeah, I thought about that, too. But seems complex to implement 😟

@tokejepsen
Copy link
Collaborator

Hmm since the "Create" button gets invalidated, it might not be a must have. Great work!

@davidlatwe
Copy link
Collaborator Author

Haha, turns out it's not that hard :P
Implemented in commit 79ed093, and here's the demo (Note that the space char will be quoted)

creator

What do you think ?

@tokejepsen
Copy link
Collaborator

Amazing!

@davidlatwe
Copy link
Collaborator Author

Wait, it seems that QLineEdit already has a feature to validate the input text, QLineEdit.setValidator.
Well try this when I get back from 2 days vacation.

@davidlatwe
Copy link
Collaborator Author

I have change to use QValidator to block invalid inputs, also add a tool tip.
Here the result :

creator

Note that the invalid characters will not be accepted at all, so I add a border color transition animation for better feedback.

Please let me know what you think about this change :)

@tokejepsen
Copy link
Collaborator

Looks great!

Copy link
Collaborator

@BigRoy BigRoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From an artist/interface perspective this looks good to me. Code-wise I only had some questions, because it seems quite an amount of lines of code for the visual result. It looks good though.

Separator = "---separator---"


class SubsetNameValidator(QtGui.QRegExpValidator):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be sure, the only reason we require to define our own class is so we can report to the user which characters were invalidated in particular. Correct? If so, then this class is fine. Otherwise, this seems redundant.

Copy link
Collaborator Author

@davidlatwe davidlatwe Sep 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct?

Not entirely, the main reason I subclass the QtGui.QRegExpValidator was to re-implement the function validate, so that I could emit a signal when the input has invalid character. I could not find any built-in way to implement this notification on QLineEdit, it just works silently.

Reporting which characters exactly were invalid was something I picked up on the way :)

Copy link
Collaborator

@BigRoy BigRoy Sep 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. If you only wanted to have the invalid signal, it's QLineEdit.inputRejected but it won't signal what characters were invalid I believe + it's only been introduced since Qt 5.12 so I guess we can't rely on it.

I guess currently subclassing like this really is the only way.

self.setToolTip("Only alphanumeric characters (A-Z a-z 0-9), "
"'_' and '.' are allowed.")

self._cstatus = None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if there's enough reason to abbrevaite _color_status to _cstatus. I don't mind it. Just wondering.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this should be improved for reading.

@mottosso
Copy link
Contributor

I love it!

@davidlatwe
Copy link
Collaborator Author

Well merge this tomorrow !

@davidlatwe davidlatwe merged commit 2bdcb79 into getavalon:master Sep 17, 2019
@davidlatwe davidlatwe deleted the Fix#289 branch September 17, 2019 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creator does not ensure the subset has only alphabetical characters

4 participants