默认张数改为-1以与父控制项的默认值一致;添加属性同时对该属性执行恢复默认值操作

This commit is contained in:
gb 2023-11-14 15:30:50 +08:00
parent 1f65d4d014
commit 123e40b648
2 changed files with 21 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@ -990,6 +990,7 @@ void device_option::insert_option(gb_json* opt, sane_opt_provider* from, const c
// second compare position, replace with last insertion
// last, sort by position
gb_json* existing = nullptr;
bool added = true;
origin_->get_value(opt->key().c_str(), existing);
if (existing)
@ -1144,6 +1145,7 @@ void device_option::insert_option(gb_json* opt, sane_opt_provider* from, const c
// disable discarded option
from->enable(existing->key().c_str(), false);
added = false;
}
existing->release();
@ -1160,6 +1162,20 @@ void device_option::insert_option(gb_json* opt, sane_opt_provider* from, const c
src_[opt->key()] = from;
from->add_ref();
}
if (added)
{
// restore to default value ...
int size = 0;
bool can_auto = false;
std::string val(get_option_value(opt->key().c_str(), SANE_ACTION_GET_DEFAULT_VALUE, &size));
if (!opt->get_value("auto", can_auto) || can_auto)
{
val.resize(size);
from->set_value(opt->key().c_str(), &val[0]);
}
}
}
bool device_option::arrange_raw_json(sane_opt_provider* sop)
{
@ -1451,7 +1467,9 @@ bool device_option::to_now(bool init, bool* changed)
int pub = visibility(from);
if (pub == OPT_VISIBLE_HIDE || pub == OPT_VISIBLE_NOT_SUPPORT)
{
if (pub == OPT_VISIBLE_NOT_SUPPORT || !user_ || !user_(USER_PRIVILEGE_DEVLOPER))
int auth = 0;
from->get_value("auth", auth);
if (pub == OPT_VISIBLE_NOT_SUPPORT || !user_ || !user_(auth))
{
from->release();
from = origin_->next_child();
@ -1515,7 +1533,6 @@ bool device_option::to_now(bool init, bool* changed)
}
}
tmp->set_value(name.c_str(), to);
to->release();