mirror of
https://github.com/altlinux/admc.git
synced 2024-10-26 17:25:38 +03:00
add length limit to string large edit
This commit is contained in:
parent
3734f41248
commit
c865301eb7
@ -22,6 +22,7 @@
|
||||
|
||||
#include "adldap.h"
|
||||
#include "utils.h"
|
||||
#include "globals.h"
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
@ -29,10 +30,14 @@ StringLargeEdit::StringLargeEdit(QPlainTextEdit *edit_arg, const QString &attrib
|
||||
: AttributeEdit(parent) {
|
||||
attribute = attribute_arg;
|
||||
edit = edit_arg;
|
||||
ignore_on_text_changed = false;
|
||||
|
||||
connect(
|
||||
edit, &QPlainTextEdit::textChanged,
|
||||
this, &AttributeEdit::edited);
|
||||
connect(
|
||||
edit, &QPlainTextEdit::textChanged,
|
||||
this, &StringLargeEdit::on_text_changed);
|
||||
}
|
||||
|
||||
void StringLargeEdit::load(AdInterface &ad, const AdObject &object) {
|
||||
@ -49,3 +54,20 @@ bool StringLargeEdit::apply(AdInterface &ad, const QString &dn) const {
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// NOTE: this is a custom length limit mechanism
|
||||
// because QPlainText doesn't have it built-in
|
||||
void StringLargeEdit::on_text_changed() {
|
||||
ignore_on_text_changed = true;
|
||||
{
|
||||
const int range_upper = g_adconfig->get_attribute_range_upper(attribute);
|
||||
|
||||
const QString value = edit->toPlainText();
|
||||
|
||||
if (value.length() > range_upper) {
|
||||
const QString shortened_value = value.left(range_upper);
|
||||
edit->setPlainText(shortened_value);
|
||||
}
|
||||
}
|
||||
ignore_on_text_changed = false;
|
||||
}
|
||||
|
@ -41,6 +41,9 @@ public:
|
||||
private:
|
||||
QPlainTextEdit *edit;
|
||||
QString attribute;
|
||||
bool ignore_on_text_changed;
|
||||
|
||||
void on_text_changed();
|
||||
};
|
||||
|
||||
#endif /* STRING_LARGE_EDIT_H */
|
||||
|
Loading…
Reference in New Issue
Block a user