PIValueTreeEdit::Permissions feature
add designer plugin for PIValueTreeEdit
This commit is contained in:
BIN
icons/valuetreeeditor.png
Normal file
BIN
icons/valuetreeeditor.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
@@ -122,6 +122,18 @@ void PIValueTreeEdit::setReadOnly(bool yes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIValueTreeEdit::setPermissions(Permissions p) {
|
||||||
|
perm = p;
|
||||||
|
applyPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIValueTreeEdit::setPermission(Permission p, bool on) {
|
||||||
|
perm.setFlag(p, on);
|
||||||
|
applyPermissions();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::rollback() {
|
void PIValueTreeEdit::rollback() {
|
||||||
current = source;
|
current = source;
|
||||||
build();
|
build();
|
||||||
@@ -261,6 +273,38 @@ void PIValueTreeEdit::applyValues() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIValueTreeEdit::applyPermissions() {
|
||||||
|
auto * wp = widget_params;
|
||||||
|
wp->actionValue->setVisible(perm.testFlag(AddValue));
|
||||||
|
wp->actionGroup->setVisible(perm.testFlag(AddGroup));
|
||||||
|
wp->actionArray->setVisible(perm.testFlag(AddArray));
|
||||||
|
wp->actionCut->setVisible(perm.testFlag(CanCut));
|
||||||
|
wp->actionCopy->setVisible(perm.testFlag(CanCopy));
|
||||||
|
wp->actionPaste->setVisible(perm.testFlag(CanPaste));
|
||||||
|
wp->actionPasteAfter->setVisible(perm.testFlag(CanPaste));
|
||||||
|
wp->actionPasteBefore->setVisible(perm.testFlag(CanPaste));
|
||||||
|
wp->checkHidden->setVisible(perm.testFlag(ChangeHidden));
|
||||||
|
wp->checkLabel->setVisible(perm.testFlag(ChangeLabel));
|
||||||
|
wp->checkReadOnly->setVisible(perm.testFlag(ChangeReadOnly));
|
||||||
|
wp->lineComment->setVisible(perm.testFlag(ChangeComment));
|
||||||
|
wp->labelComment->setVisible(perm.testFlag(ChangeComment));
|
||||||
|
wp->comboType->setVisible(perm.testFlag(ChangeType));
|
||||||
|
wp->labelType->setVisible(perm.testFlag(ChangeType));
|
||||||
|
wp->menu_grouping.menuAction()->setVisible(perm.testFlag(ChangeGrouping));
|
||||||
|
wp->actionRename->setVisible(perm.testFlag(CanRename));
|
||||||
|
wp->actionRemove->setVisible(perm.testFlag(CanRemove));
|
||||||
|
wp->actionReorder->setVisible(perm.testFlag(CanReorder));
|
||||||
|
for (auto * c: {wp->checkHidden, wp->checkLabel, wp->checkReadOnly})
|
||||||
|
if (!c->isEnabled()) c->setChecked(false);
|
||||||
|
grid->button_add->setVisible(
|
||||||
|
PIVector<QAction *>({wp->actionValue, wp->actionGroup, wp->actionArray, wp->actionPaste}).any([](QAction * a) {
|
||||||
|
return a->isVisible();
|
||||||
|
}));
|
||||||
|
for (auto c: tree_edits)
|
||||||
|
c.second->setPermissions(perm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PIValueTreeEdit::actionRename(QToolButton * button, const PIString & vn) {
|
void PIValueTreeEdit::actionRename(QToolButton * button, const PIString & vn) {
|
||||||
PIString nn = Q2PIString(QInputDialog::getText(nullptr, tr("Rename"), tr("Input new name:"), QLineEdit::Normal, PI2QString(vn)));
|
PIString nn = Q2PIString(QInputDialog::getText(nullptr, tr("Rename"), tr("Input new name:"), QLineEdit::Normal, PI2QString(vn)));
|
||||||
if (nn.isEmpty() || (nn == vn)) return;
|
if (nn.isEmpty() || (nn == vn)) return;
|
||||||
@@ -475,6 +519,7 @@ PIValueTreeEdit * PIValueTreeEdit::addTreeEdit(const PIValueTree & vt) {
|
|||||||
ve->m_read_only = m_read_only;
|
ve->m_read_only = m_read_only;
|
||||||
ve->setGrouping((Grouping)vt.attribute(Attribute::grouping, PIVariantEditorBase::createGrouping()).toEnum().selectedValue());
|
ve->setGrouping((Grouping)vt.attribute(Attribute::grouping, PIVariantEditorBase::createGrouping()).toEnum().selectedValue());
|
||||||
ve->setFullEditMode(is_full_edit);
|
ve->setFullEditMode(is_full_edit);
|
||||||
|
ve->setPermissions(permissions());
|
||||||
ve->setValue(vt);
|
ve->setValue(vt);
|
||||||
switch (cur_grouping) {
|
switch (cur_grouping) {
|
||||||
case Indent: grid->add(vt, vt.name(), ve, vt.comment(), true); break;
|
case Indent: grid->add(vt, vt.name(), ve, vt.comment(), true); break;
|
||||||
|
|||||||
@@ -40,7 +40,10 @@ class PIValueTreeEditArray;
|
|||||||
|
|
||||||
class QAD_PIQT_UTILS_EXPORT PIValueTreeEdit: public QWidget {
|
class QAD_PIQT_UTILS_EXPORT PIValueTreeEdit: public QWidget {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_ENUMS(Grouping)
|
Q_PROPERTY(Grouping grouping READ grouping WRITE setGrouping)
|
||||||
|
Q_PROPERTY(bool fullEditMode READ isFullEditMode WRITE setFullEditMode)
|
||||||
|
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
|
||||||
|
Q_PROPERTY(Permissions permissions READ permissions WRITE setPermissions)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PIValueTreeEdit(QWidget * parent = nullptr);
|
PIValueTreeEdit(QWidget * parent = nullptr);
|
||||||
@@ -51,17 +54,46 @@ public:
|
|||||||
Groups,
|
Groups,
|
||||||
Tabs
|
Tabs
|
||||||
};
|
};
|
||||||
|
Q_ENUM(Grouping)
|
||||||
|
|
||||||
|
enum Permission {
|
||||||
|
AddValue = 0x1,
|
||||||
|
AddGroup = 0x2,
|
||||||
|
AddArray = 0x4,
|
||||||
|
ChangeHidden = 0x8,
|
||||||
|
ChangeLabel = 0x10,
|
||||||
|
ChangeReadOnly = 0x20,
|
||||||
|
ChangeComment = 0x40,
|
||||||
|
ChangeType = 0x80,
|
||||||
|
ChangeGrouping = 0x100,
|
||||||
|
CanCut = 0x200,
|
||||||
|
CanCopy = 0x400,
|
||||||
|
CanPaste = 0x800,
|
||||||
|
CanRename = 0x1000,
|
||||||
|
CanRemove = 0x2000,
|
||||||
|
CanReorder = 0x4000,
|
||||||
|
PermissionsAll = 0xFFFFFFFF
|
||||||
|
};
|
||||||
|
Q_ENUM(Permission)
|
||||||
|
Q_DECLARE_FLAGS(Permissions, Permission)
|
||||||
|
Q_FLAG(Permissions)
|
||||||
|
|
||||||
void setValue(const PIValueTree & v);
|
void setValue(const PIValueTree & v);
|
||||||
PIValueTree value() const;
|
PIValueTree value() const;
|
||||||
|
|
||||||
Grouping grouping() const { return cur_grouping; }
|
Grouping grouping() const { return cur_grouping; }
|
||||||
void setGrouping(Grouping g);
|
void setGrouping(Grouping g);
|
||||||
|
|
||||||
bool isFullEditMode() const { return is_full_edit; }
|
bool isFullEditMode() const { return is_full_edit; }
|
||||||
void setFullEditMode(bool yes);
|
void setFullEditMode(bool yes);
|
||||||
|
|
||||||
bool isReadOnly() const { return m_read_only; }
|
bool isReadOnly() const { return m_read_only; }
|
||||||
void setReadOnly(bool yes);
|
void setReadOnly(bool yes);
|
||||||
|
|
||||||
|
Permissions permissions() const { return perm; }
|
||||||
|
void setPermissions(Permissions p);
|
||||||
|
void setPermission(Permission p, bool on);
|
||||||
|
|
||||||
void setAllowedNamesFunction(std::function<PIStringList()> f) { allowed_names = f; }
|
void setAllowedNamesFunction(std::function<PIStringList()> f) { allowed_names = f; }
|
||||||
void setValueForNameFunction(std::function<PIVariant(PIString)> f) { value_by_name = f; }
|
void setValueForNameFunction(std::function<PIVariant(PIString)> f) { value_by_name = f; }
|
||||||
|
|
||||||
@@ -81,6 +113,7 @@ private:
|
|||||||
void removeAll();
|
void removeAll();
|
||||||
void build();
|
void build();
|
||||||
void applyValues() const;
|
void applyValues() const;
|
||||||
|
void applyPermissions();
|
||||||
void actionRename(QToolButton * button, const PIString & vn);
|
void actionRename(QToolButton * button, const PIString & vn);
|
||||||
void actionRemove(QToolButton * button, const PIString & vn);
|
void actionRemove(QToolButton * button, const PIString & vn);
|
||||||
void actionChange(QToolButton * button, const PIString & vn);
|
void actionChange(QToolButton * button, const PIString & vn);
|
||||||
@@ -145,10 +178,11 @@ private:
|
|||||||
PIMap<PIString, PIVariantEdit *> value_edits;
|
PIMap<PIString, PIVariantEdit *> value_edits;
|
||||||
PIMap<PIString, PIValueTreeEdit *> tree_edits;
|
PIMap<PIString, PIValueTreeEdit *> tree_edits;
|
||||||
PIMap<PIString, QLabel *> comm_labels, label_labels;
|
PIMap<PIString, QLabel *> comm_labels, label_labels;
|
||||||
QTabWidget * tab_widget = nullptr;
|
QTabWidget * tab_widget = nullptr;
|
||||||
Ui::PIValueTreeEditArray * ui_array = nullptr;
|
Ui::PIValueTreeEditArray * ui_array = nullptr;
|
||||||
GridWidgets * grid = nullptr;
|
GridWidgets * grid = nullptr;
|
||||||
Grouping cur_grouping = Groups;
|
Grouping cur_grouping = Groups;
|
||||||
|
Permissions perm = PermissionsAll;
|
||||||
mutable PIValueTree source, current;
|
mutable PIValueTree source, current;
|
||||||
bool is_full_edit = false, m_read_only = false;
|
bool is_full_edit = false, m_read_only = false;
|
||||||
std::function<PIStringList()> allowed_names;
|
std::function<PIStringList()> allowed_names;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="3" column="0">
|
<item row="3" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="labelType">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Type:</string>
|
<string>Type:</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -48,7 +48,7 @@
|
|||||||
<widget class="EComboBox" name="comboType"/>
|
<widget class="EComboBox" name="comboType"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="4" column="0">
|
<item row="4" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="labelComment">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Comment:</string>
|
<string>Comment:</string>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
1
libs/piqt_utils/plugin/CMakeLists.txt
Normal file
1
libs/piqt_utils/plugin/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
qad_plugin(piqt_utils "Gui;Widgets" "")
|
||||||
70
libs/piqt_utils/plugin/pivaluetree_edit_plugin.cpp
Normal file
70
libs/piqt_utils/plugin/pivaluetree_edit_plugin.cpp
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#include "pivaluetree_edit_plugin.h"
|
||||||
|
|
||||||
|
#include "pivaluetree_edit.h"
|
||||||
|
|
||||||
|
#include <QtCore/QtPlugin>
|
||||||
|
|
||||||
|
|
||||||
|
PIValueTreeEditPlugin::PIValueTreeEditPlugin(QObject * parent): QObject(parent) {
|
||||||
|
m_initialized = m_designer = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void PIValueTreeEditPlugin::initialize(QDesignerFormEditorInterface * /* core */) {
|
||||||
|
m_designer = true;
|
||||||
|
if (m_initialized) return;
|
||||||
|
|
||||||
|
// Add extension registrations, etc. here
|
||||||
|
|
||||||
|
m_initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIValueTreeEditPlugin::isInitialized() const {
|
||||||
|
return m_initialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QWidget * PIValueTreeEditPlugin::createWidget(QWidget * parent) {
|
||||||
|
return new PIValueTreeEdit(parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString PIValueTreeEditPlugin::name() const {
|
||||||
|
return QLatin1String("PIValueTreeEdit");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString PIValueTreeEditPlugin::group() const {
|
||||||
|
return QLatin1String("Editor Widgets");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QIcon PIValueTreeEditPlugin::icon() const {
|
||||||
|
return QIcon(":/icons/valuetreeeditor.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString PIValueTreeEditPlugin::toolTip() const {
|
||||||
|
return QLatin1String(""); // QLatin1String("Widget for display any math graphics with grid and navigation");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString PIValueTreeEditPlugin::whatsThis() const {
|
||||||
|
return QLatin1String("");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool PIValueTreeEditPlugin::isContainer() const {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString PIValueTreeEditPlugin::domXml() const {
|
||||||
|
return QLatin1String("<widget class=\"PIValueTreeEdit\" name=\"valueTreeEdit\">\n</widget>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString PIValueTreeEditPlugin::includeFile() const {
|
||||||
|
return QLatin1String("pivaluetree_edit.h");
|
||||||
|
}
|
||||||
36
libs/piqt_utils/plugin/pivaluetree_edit_plugin.h
Normal file
36
libs/piqt_utils/plugin/pivaluetree_edit_plugin.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#ifndef pivaluetree_edit_plugin_H
|
||||||
|
#define pivaluetree_edit_plugin_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
# include <QtUiPlugin/QDesignerCustomWidgetInterface>
|
||||||
|
#else
|
||||||
|
# include <QDesignerCustomWidgetInterface>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class PIValueTreeEditPlugin
|
||||||
|
: public QObject
|
||||||
|
, public QDesignerCustomWidgetInterface {
|
||||||
|
Q_OBJECT
|
||||||
|
Q_INTERFACES(QDesignerCustomWidgetInterface)
|
||||||
|
|
||||||
|
public:
|
||||||
|
PIValueTreeEditPlugin(QObject * parent = 0);
|
||||||
|
|
||||||
|
bool isContainer() const;
|
||||||
|
bool isInitialized() const;
|
||||||
|
QIcon icon() const;
|
||||||
|
QString domXml() const;
|
||||||
|
QString group() const;
|
||||||
|
QString includeFile() const;
|
||||||
|
QString name() const;
|
||||||
|
QString toolTip() const;
|
||||||
|
QString whatsThis() const;
|
||||||
|
QWidget * createWidget(QWidget * parent);
|
||||||
|
void initialize(QDesignerFormEditorInterface * core);
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_initialized, m_designer;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
17
libs/piqt_utils/plugin/qad_piqt_utils.cpp
Normal file
17
libs/piqt_utils/plugin/qad_piqt_utils.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include "qad_piqt_utils.h"
|
||||||
|
|
||||||
|
#include "pivaluetree_edit_plugin.h"
|
||||||
|
|
||||||
|
QADPiQtUtils::QADPiQtUtils(QObject * parent): QObject(parent) {
|
||||||
|
m_widgets.append(new PIValueTreeEditPlugin(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QList<QDesignerCustomWidgetInterface *> QADPiQtUtils::customWidgets() const {
|
||||||
|
return m_widgets;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if QT_VERSION < 0x050000
|
||||||
|
Q_EXPORT_PLUGIN2(qad_piqt_utils_plugin, QADPiQtUtils)
|
||||||
|
#endif
|
||||||
24
libs/piqt_utils/plugin/qad_piqt_utils.h
Normal file
24
libs/piqt_utils/plugin/qad_piqt_utils.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef qad_piqt_utils_H
|
||||||
|
#define qad_piqt_utils_H
|
||||||
|
|
||||||
|
#include <QtCore/qplugin.h>
|
||||||
|
#include <QtDesigner/QtDesigner>
|
||||||
|
|
||||||
|
class QADPiQtUtils
|
||||||
|
: public QObject
|
||||||
|
, public QDesignerCustomWidgetCollectionInterface {
|
||||||
|
Q_OBJECT
|
||||||
|
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
||||||
|
#if QT_VERSION >= 0x050000
|
||||||
|
Q_PLUGIN_METADATA(IID "qad.piqt_utils")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit QADPiQtUtils(QObject * parent = 0);
|
||||||
|
virtual QList<QDesignerCustomWidgetInterface *> customWidgets() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<QDesignerCustomWidgetInterface *> m_widgets;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -13,5 +13,6 @@
|
|||||||
<file>../../icons/document-edit.png</file>
|
<file>../../icons/document-edit.png</file>
|
||||||
<file>../../icons/layer-visible-off.png</file>
|
<file>../../icons/layer-visible-off.png</file>
|
||||||
<file>../../icons/layer-visible-on.png</file>
|
<file>../../icons/layer-visible-on.png</file>
|
||||||
|
<file>../../icons/valuetreeeditor.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|||||||
Reference in New Issue
Block a user