PIValueTreeEdit interaction control abilities
This commit is contained in:
@@ -411,6 +411,14 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
|
||||
}
|
||||
|
||||
|
||||
PIValueTreeEdit * PIValueTreeEdit::rootTreeEdit() {
|
||||
PIValueTreeEdit * ret = this;
|
||||
while (ret->parent_tree)
|
||||
ret = ret->parent_tree;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void PIValueTreeEdit::addValueEdit(const PIValueTree & vt) {
|
||||
auto * ve = new PIVariantEdit();
|
||||
applyVariantEdit(ve, vt);
|
||||
@@ -458,7 +466,19 @@ void PIValueTreeEdit::createTabWidget() {
|
||||
|
||||
|
||||
void PIValueTreeEdit::newRequest(NewType type) {
|
||||
PIString nn = Q2PIString(QInputDialog::getText(nullptr, tr("New item"), tr("Input new name:")));
|
||||
PIString nn;
|
||||
if (rootTreeEdit()->allowed_names && (type == NewType::Value)) {
|
||||
QStringList anl = PI2QStringList(rootTreeEdit()->allowed_names());
|
||||
if (anl.isEmpty()) {
|
||||
QMessageBox::warning(nullptr, tr("New item"), tr("No allowed names!"));
|
||||
return;
|
||||
}
|
||||
bool ok = false;
|
||||
nn = Q2PIString(QInputDialog::getItem(nullptr, tr("New item"), tr("Select new name:"), anl, 0, false, &ok));
|
||||
if (!ok) return;
|
||||
} else {
|
||||
nn = Q2PIString(QInputDialog::getText(nullptr, tr("New item"), tr("Input new name:")));
|
||||
}
|
||||
if (nn.isEmpty()) return;
|
||||
for (const auto & c: current.children()) {
|
||||
if (c.name() == nn) {
|
||||
@@ -469,6 +489,9 @@ void PIValueTreeEdit::newRequest(NewType type) {
|
||||
PIValueTree vt;
|
||||
vt.setName(nn);
|
||||
if (type == NewType::Value) {
|
||||
if (rootTreeEdit()->value_by_name) {
|
||||
vt.setValue(rootTreeEdit()->value_by_name(nn));
|
||||
}
|
||||
if (!widget_params->showFor(vt)) return;
|
||||
}
|
||||
if (type == NewType::Array) {
|
||||
|
||||
@@ -61,6 +61,9 @@ public:
|
||||
bool isFullEditMode() const { return is_full_edit; }
|
||||
void setFullEditMode(bool yes);
|
||||
|
||||
void setAllowedNamesFunction(std::function<PIStringList()> f) { allowed_names = f; }
|
||||
void setValueForNameFunction(std::function<PIVariant(PIString)> f) { value_by_name = f; }
|
||||
|
||||
void rollback();
|
||||
void clear();
|
||||
void retranslate();
|
||||
@@ -80,6 +83,7 @@ private:
|
||||
void actionTriggered(QToolButton * button, const PIString & vn, QAction * a);
|
||||
void newRequest(NewType type);
|
||||
PIValueTreeEdit * addTreeEdit(const PIValueTree & vt);
|
||||
PIValueTreeEdit * rootTreeEdit();
|
||||
void addValueEdit(const PIValueTree & vt);
|
||||
void applyArrayAttributes();
|
||||
QLabel * newLabel(const PIValueTree & vt);
|
||||
@@ -137,6 +141,8 @@ private:
|
||||
Grouping cur_grouping = Parent, real_grouping = Indent;
|
||||
mutable PIValueTree source, current;
|
||||
bool is_full_edit = false;
|
||||
std::function<PIStringList()> allowed_names;
|
||||
std::function<PIVariant(PIString)> value_by_name;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user