Files
qad/libs/piqt_widgets/pivaluetree_edit.h

126 lines
3.3 KiB
C++

/*
PIQt Utils - Qt utilites for PIP
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef pivaluetree_edit_H
#define pivaluetree_edit_H
#include "pivaluetree.h"
#include "qad_piqt_utils_export.h"
#include <QIcon>
#include <QLabel>
#include <QMenu>
#include <QWidget>
class QGridLayout;
class QToolButton;
class PIVariantEdit;
class PIValueTreeEditParameters;
class PIValueTreeEditReorder;
namespace Ui {
class PIValueTreeEditArray;
}
class QAD_PIQT_UTILS_EXPORT PIValueTreeEdit: public QWidget {
Q_OBJECT
public:
PIValueTreeEdit(QWidget * parent = nullptr);
~PIValueTreeEdit();
enum TreeStyle {
Label
};
void setValue(const PIValueTree & v);
PIValueTree value() const;
bool isGroupingEnabled() const { return is_grouping; }
void setGroupingEnabled(bool yes);
bool isFullEditMode() const { return is_full_edit; }
void setFullEditMode(bool yes);
void rollback();
void clear();
private:
enum class NewType {
Value,
Group,
Array
};
void changeEvent(QEvent * e) override;
void removeAll();
void build();
void applyValues() const;
void actionTriggered(QToolButton * button, const PIString & vn, QAction * a);
void newRequest(NewType type);
PIValueTreeEdit * addTreeEdit(const PIValueTree & vt);
void addValueEdit(const PIValueTree & vt);
void applyArrayAttributes();
class GridWidgets: public QWidget {
public:
GridWidgets(PIValueTreeEdit * p);
~GridWidgets();
int rowCount() const { return row_count; }
int getRow(QWidget * w) const;
void removeRow(int index);
void add(const PIValueTree & vt, QString label, QWidget * w, const QString & comment, bool is_group = false);
void add(const PIValueTree & vt, QWidget * w, bool is_group = false);
int beginRow(const PIValueTree & vt, bool is_group);
void rename(QString prev_name, QString new_name);
void reorder(const PIMap<int, int> & map) { simplify(map); }
void clear();
void changed();
bool create_edit_buttons = false;
QToolButton * button_add;
private:
void simplify(const PIMap<int, int> & map = PIMap<int, int>());
int row_count = 0;
QGridLayout * lay = nullptr;
PIValueTreeEdit * parent;
QMenu menu_group, menu_conf, menu_new;
QWidgetList widgets;
QList<QLabel *> labels;
QIcon icon_conf;
};
QWidget * widget_array = nullptr;
PIValueTreeEditParameters * widget_params;
PIValueTreeEditReorder * widget_reorder;
PIStringList root_path;
PIVector<PIVariantEdit *> array_edits;
PIMap<PIString, PIVariantEdit *> value_edits;
PIMap<PIString, PIValueTreeEdit *> tree_edits;
PIMap<PIString, QLabel *> comm_labels;
Ui::PIValueTreeEditArray * ui_array;
GridWidgets * grid = nullptr;
mutable PIValueTree source;
bool is_grouping = true, is_full_edit = false;
};
#endif