Added echoMode to QLineEdit (#187)

This commit is contained in:
Mikko Sairio 2019-11-10 17:29:59 +02:00 committed by Atul R
parent 21e5e78876
commit 88cd9d430f
4 changed files with 22 additions and 1 deletions

View File

@ -25,6 +25,7 @@ class QLineEditWrap : public Napi::ObjectWrap<QLineEditWrap> {
Napi::Value setPlaceholderText(const Napi::CallbackInfo& info);
Napi::Value setReadOnly(const Napi::CallbackInfo& info);
Napi::Value clear(const Napi::CallbackInfo& info);
Napi::Value setEchoMode(const Napi::CallbackInfo& info);
QWIDGET_WRAPPED_METHODS_DECLARATION
};

View File

@ -18,6 +18,7 @@ Napi::Object QLineEditWrap::init(Napi::Env env, Napi::Object exports) {
InstanceMethod("text", &QLineEditWrap::text),
InstanceMethod("setReadOnly", &QLineEditWrap::setReadOnly),
InstanceMethod("clear", &QLineEditWrap::clear),
InstanceMethod("setEchoMode", &QLineEditWrap::setEchoMode),
QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QLineEditWrap)});
constructor = Napi::Persistent(func);
exports.Set(CLASSNAME, func);
@ -81,9 +82,19 @@ Napi::Value QLineEditWrap::setPlaceholderText(const Napi::CallbackInfo& info) {
this->instance->setPlaceholderText(text.Utf8Value().c_str());
return env.Null();
}
Napi::Value QLineEditWrap::clear(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
this->instance->clear();
return env.Null();
}
Napi::Value QLineEditWrap::setEchoMode(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Number mode = info[0].As<Napi::Number>();
this->instance->setEchoMode(
static_cast<QLineEdit::EchoMode>(mode.Int32Value()));
return env.Null();
}

View File

@ -23,7 +23,7 @@ export { QWidget, QWidgetEvents } from './lib/QtWidgets/QWidget';
export { QCheckBox, QCheckBoxEvents } from './lib/QtWidgets/QCheckBox';
export { QLabel, QLabelEvents } from './lib/QtWidgets/QLabel';
export { QDial, QDialEvents } from './lib/QtWidgets/QDial';
export { QLineEdit, QLineEditEvents } from './lib/QtWidgets/QLineEdit';
export { QLineEdit, QLineEditEvents, EchoMode } from './lib/QtWidgets/QLineEdit';
export { QMainWindow, QMainWindowEvents } from './lib/QtWidgets/QMainWindow';
export { QProgressBar, QProgressBarEvents } from './lib/QtWidgets/QProgressBar';
export { QPushButton, QPushButtonEvents } from './lib/QtWidgets/QPushButton';

View File

@ -3,6 +3,12 @@ import { NodeWidget } from './QWidget';
import { BaseWidgetEvents } from '../core/EventWidget';
import { NativeElement } from '../core/Component';
export enum EchoMode {
Normal,
NoEcho,
Password,
PasswordEchoOnEdit,
};
export const QLineEditEvents = Object.freeze({
...BaseWidgetEvents,
cursorPositionChanged: 'cursorPositionChanged',
@ -48,4 +54,7 @@ export class QLineEdit extends NodeWidget {
// react:✓
this.native.clear();
}
setEchoMode(mode: EchoMode): void {
this.native.setEchoMode(mode);
}
}