diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ProgressWidget.cc | 5 | ||||
-rw-r--r-- | src/ProgressWidget.h | 1 | ||||
-rw-r--r-- | src/func.cc | 14 | ||||
-rw-r--r-- | src/mainwin.cc | 3 | ||||
-rw-r--r-- | src/value.cc | 5 |
5 files changed, 24 insertions, 4 deletions
diff --git a/src/ProgressWidget.cc b/src/ProgressWidget.cc index a386192..112e239 100644 --- a/src/ProgressWidget.cc +++ b/src/ProgressWidget.cc @@ -29,3 +29,8 @@ void ProgressWidget::setValue(int progress) { this->progressBar->setValue(progress); } + +int ProgressWidget::value() const +{ + return this->progressBar->value(); +} diff --git a/src/ProgressWidget.h b/src/ProgressWidget.h index 715272b..83e4d40 100644 --- a/src/ProgressWidget.h +++ b/src/ProgressWidget.h @@ -15,6 +15,7 @@ public: public slots: void setRange(int minimum, int maximum); void setValue(int progress); + int value() const; void cancel(); signals: diff --git a/src/func.cc b/src/func.cc index a9d5948..1138173 100644 --- a/src/func.cc +++ b/src/func.cc @@ -290,6 +290,17 @@ Value builtin_exp(const Context *, const std::vector<std::string>&, const std::v return Value(); } +Value builtin_length(const Context *, const std::vector<std::string>&, const std::vector<Value> &args) +{ + if (args.size() == 1){ + if (args[0].type == Value::VECTOR) + return Value((double) args[0].vec.size()); + if (args[0].type == Value::STRING) + return Value((double) args[0].text.size()); + } + return Value(); +} + Value builtin_log(const Context *, const std::vector<std::string>&, const std::vector<Value> &args) { if (args.size() == 2 && args[0].type == Value::NUMBER && args[1].type == Value::NUMBER) @@ -311,7 +322,7 @@ Value builtin_str(const Context *, const std::vector<std::string>&, const std::v std::stringstream stream; for (size_t i = 0; i < args.size(); i++) { - stream << args[i]; + stream << args[i].toString(); } return Value(stream.str()); } @@ -391,6 +402,7 @@ void register_builtin_functions() Builtins::init("pow", new BuiltinFunction(&builtin_pow)); Builtins::init("sqrt", new BuiltinFunction(&builtin_sqrt)); Builtins::init("exp", new BuiltinFunction(&builtin_exp)); + Builtins::init("len", new BuiltinFunction(&builtin_length)); Builtins::init("log", new BuiltinFunction(&builtin_log)); Builtins::init("ln", new BuiltinFunction(&builtin_ln)); Builtins::init("str", new BuiltinFunction(&builtin_str)); diff --git a/src/mainwin.cc b/src/mainwin.cc index a6f5be6..22fb82c 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -433,7 +433,8 @@ static void report_func(const class AbstractNode*, void *vp, int mark) #ifdef USE_PROGRESSWIDGET ProgressWidget *pw = static_cast<ProgressWidget*>(vp); int v = (int)((mark*100.0) / progress_report_count); - pw->setValue(v < 100 ? v : 99); + int percent = v < 100 ? v : 99; + if (percent > pw->value()) pw->setValue(percent); QApplication::processEvents(); if (pw->wasCanceled()) throw ProgressCancelException(); #else diff --git a/src/value.cc b/src/value.cc index e08b2d8..ab78c2a 100644 --- a/src/value.cc +++ b/src/value.cc @@ -343,7 +343,7 @@ std::string Value::toString() const switch (this->type) { case STRING: - stream << '"' << this->text << '"'; + stream << this->text; break; case VECTOR: stream << '['; @@ -411,7 +411,8 @@ void Value::append(Value *val) std::ostream &operator<<(std::ostream &stream, const Value &value) { - stream << value.toString(); + if (value.type == Value::STRING) stream << QuotedString(value.toString()); + else stream << value.toString(); return stream; } |