code format
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
#include "qpiconfigwidget.h"
|
||||
|
||||
#include "qalgorithms.h"
|
||||
#include "qpiconfigvaluewidget.h"
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
QPIConfigWidget::QPIConfigWidget(QWidget * parent, QPIConfig * c, bool on): QTreeWidget(parent), actionAddItem(this), actionAddNode(this),
|
||||
actionToItem(this), actionToNode(this), actionRemove(this),
|
||||
actionExpandAll(this), actionCollapseAll(this) {
|
||||
QPIConfigWidget::QPIConfigWidget(QWidget * parent, QPIConfig * c, bool on)
|
||||
: QTreeWidget(parent)
|
||||
, actionAddItem(this)
|
||||
, actionAddNode(this)
|
||||
, actionToItem(this)
|
||||
, actionToNode(this)
|
||||
, actionRemove(this)
|
||||
, actionExpandAll(this)
|
||||
, actionCollapseAll(this) {
|
||||
active = on;
|
||||
if (active) {
|
||||
setColumnCount(4);
|
||||
@@ -32,8 +40,8 @@ QPIConfigWidget::QPIConfigWidget(QWidget * parent, QPIConfig * c, bool on): QTre
|
||||
popupMenu.addAction(&actionExpandAll);
|
||||
popupMenu.addAction(&actionCollapseAll);
|
||||
viewport()->installEventFilter(this);
|
||||
connect(this, SIGNAL(itemClicked(QTreeWidgetItem * , int)), this, SLOT(itemClicked(QTreeWidgetItem * , int)));
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem * , int)), this, SLOT(itemChanged(QTreeWidgetItem * , int)));
|
||||
connect(this, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(itemClicked(QTreeWidgetItem *, int)));
|
||||
connect(this, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(itemChanged(QTreeWidgetItem *, int)));
|
||||
connect(&actionAddItem, SIGNAL(triggered()), this, SLOT(on_actionAddItem_triggered()));
|
||||
connect(&actionAddNode, SIGNAL(triggered()), this, SLOT(on_actionAddNode_triggered()));
|
||||
connect(&actionRemove, SIGNAL(triggered()), this, SLOT(on_actionRemove_triggered()));
|
||||
@@ -58,18 +66,18 @@ void QPIConfigWidget::changeEvent(QEvent * e) {
|
||||
|
||||
bool QPIConfigWidget::eventFilter(QObject * o, QEvent * e) {
|
||||
if (e->type() == QEvent::MouseButtonPress) {
|
||||
if (viewport() == qobject_cast<QWidget * >(o)) {
|
||||
pi = itemAt(((QMouseEvent * )e)->pos());
|
||||
if (((QMouseEvent * )e)->buttons() == Qt::RightButton) {
|
||||
if (viewport() == qobject_cast<QWidget *>(o)) {
|
||||
pi = itemAt(((QMouseEvent *)e)->pos());
|
||||
if (((QMouseEvent *)e)->buttons() == Qt::RightButton) {
|
||||
qApp->processEvents();
|
||||
itemClicked(pi, 1);
|
||||
popupMenu.popup(
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
((QMouseEvent * )e)->globalPos()
|
||||
#else
|
||||
((QMouseEvent * )e)->globalPosition().toPoint()
|
||||
#endif
|
||||
);
|
||||
#if QT_VERSION_MAJOR <= 5
|
||||
((QMouseEvent *)e)->globalPos()
|
||||
#else
|
||||
((QMouseEvent *)e)->globalPosition().toPoint()
|
||||
#endif
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,7 +111,7 @@ void QPIConfigWidget::itemChanged(QTreeWidgetItem * item, int column) {
|
||||
if (item != c_pi) {
|
||||
c_pi = item;
|
||||
if (item) {
|
||||
c_name = item->text(0);
|
||||
c_name = item->text(0);
|
||||
c_comment = item->text(3);
|
||||
}
|
||||
return;
|
||||
@@ -114,7 +122,7 @@ void QPIConfigWidget::itemChanged(QTreeWidgetItem * item, int column) {
|
||||
if (c_name == item->text(0) && c_comment == item->text(3)) {
|
||||
return;
|
||||
}
|
||||
//qDebug() << "change" << item->text(0);
|
||||
// qDebug() << "change" << item->text(0);
|
||||
QPIConfig::Entry * e = itemEntry(item);
|
||||
if (e == nullptr) {
|
||||
return;
|
||||
@@ -123,12 +131,12 @@ void QPIConfigWidget::itemChanged(QTreeWidgetItem * item, int column) {
|
||||
buildFullNames(item);
|
||||
e->setName(item->text(column));
|
||||
conf->buildFullNames(e->parent());
|
||||
//qDebug() << itemCWidget(item)->full_name;
|
||||
// qDebug() << itemCWidget(item)->full_name;
|
||||
}
|
||||
if (column == 3) {
|
||||
e->setComment(item->text(column));
|
||||
}
|
||||
c_name = item->text(0);
|
||||
c_name = item->text(0);
|
||||
c_comment = item->text(3);
|
||||
emit changed();
|
||||
}
|
||||
@@ -164,10 +172,10 @@ void QPIConfigWidget::on_actionAddItem_triggered() {
|
||||
}
|
||||
QPIConfig::Entry * e;
|
||||
if (pi->childCount() == 0) {
|
||||
//qDebug() << "pi empty, remove " << itemCWidget(pi)->full_name;
|
||||
// qDebug() << "pi empty, remove " << itemCWidget(pi)->full_name;
|
||||
conf->removeEntry(itemCWidget(pi)->full_name, false);
|
||||
}
|
||||
//qDebug() << "add " << fp + new_dialog.name();
|
||||
// qDebug() << "add " << fp + new_dialog.name();
|
||||
e = &(conf->addEntry(fp + new_dialog.name(), new_dialog.value().isEmpty() ? "0" : new_dialog.value(), new_dialog.type(), false));
|
||||
expandItem(pi);
|
||||
pi = addEntry(pi, e);
|
||||
@@ -212,18 +220,18 @@ void QPIConfigWidget::on_actionRemove_triggered() {
|
||||
if (conf == nullptr || !active) {
|
||||
return;
|
||||
}
|
||||
QList<QTreeWidgetItem * > si = selectedItems();
|
||||
QList<QTreeWidgetItem *> si = selectedItems();
|
||||
conf->buildFullNames(&(conf->root));
|
||||
QPIConfig::Entry * e;
|
||||
for (QTreeWidgetItem * i : si) {
|
||||
for (QTreeWidgetItem * i: si) {
|
||||
e = itemEntry(i);
|
||||
if (e == nullptr) continue;
|
||||
//qDebug() << "remove " + e->_full_name;
|
||||
// qDebug() << "remove " + e->_full_name;
|
||||
conf->removeEntry(e->_full_name, false);
|
||||
deleteEntry(i);
|
||||
}
|
||||
emit changed();
|
||||
//show();
|
||||
// show();
|
||||
}
|
||||
|
||||
|
||||
@@ -254,7 +262,7 @@ void QPIConfigWidget::buildTree() {
|
||||
|
||||
void QPIConfigWidget::setReadOnlyValue(bool yes) {
|
||||
read_only_value = yes;
|
||||
for (ConfigValueWidget * i : w_values) {
|
||||
for (ConfigValueWidget * i: w_values) {
|
||||
i->setEnabled(!yes);
|
||||
}
|
||||
}
|
||||
@@ -262,7 +270,7 @@ void QPIConfigWidget::setReadOnlyValue(bool yes) {
|
||||
|
||||
void QPIConfigWidget::setReadOnlyType(bool yes) {
|
||||
read_only_type = yes;
|
||||
for (QComboBox * i : w_types) {
|
||||
for (QComboBox * i: w_types) {
|
||||
i->setEnabled(!yes);
|
||||
i->setFrame(!yes);
|
||||
}
|
||||
@@ -270,17 +278,17 @@ void QPIConfigWidget::setReadOnlyType(bool yes) {
|
||||
|
||||
|
||||
void QPIConfigWidget::buildEntry(QTreeWidgetItem * i, QPIConfig::Entry * e) {
|
||||
for (QPIConfig::Entry * j : e->children()) {
|
||||
for (QPIConfig::Entry * j: e->children()) {
|
||||
buildEntry(addEntry(i, j, !j->isLeaf()), j);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::buildFullNames(QTreeWidgetItem * i) {
|
||||
ConfigValueWidget * cw, * pw;
|
||||
ConfigValueWidget *cw, *pw;
|
||||
cw = itemCWidget(i);
|
||||
if (i->parent()) {
|
||||
pw = itemCWidget(i->parent());
|
||||
pw = itemCWidget(i->parent());
|
||||
cw->full_name = pw->full_name + conf->delim + i->text(0);
|
||||
} else {
|
||||
cw->full_name = i->text(0);
|
||||
@@ -315,9 +323,9 @@ QTreeWidgetItem * QPIConfigWidget::addEntry(QTreeWidgetItem * i, QPIConfig::Entr
|
||||
w_types.back()->setProperty("qpic_widget", QVariant(reinterpret_cast<qlonglong>(w_values.back())));
|
||||
w_types.back()->setEnabled(!read_only_type);
|
||||
w_types.back()->setFrame(!read_only_type);
|
||||
connect(w_types.back(), SIGNAL(currentIndexChanged(int, UComboBox * )), this, SLOT(typeChange(int,UComboBox * )));
|
||||
connect(w_types.back(), SIGNAL(currentIndexChanged(int, UComboBox *)), this, SLOT(typeChange(int, UComboBox *)));
|
||||
}
|
||||
connect(w_values.back(), SIGNAL(changed(ConfigValueWidget * , QString)), this, SLOT(valueChange(ConfigValueWidget * , QString)));
|
||||
connect(w_values.back(), SIGNAL(changed(ConfigValueWidget *, QString)), this, SLOT(valueChange(ConfigValueWidget *, QString)));
|
||||
i->addChild(ti);
|
||||
setItemWidget(ti, 1, w_values.back());
|
||||
if (!node) {
|
||||
@@ -338,8 +346,8 @@ void QPIConfigWidget::deleteEntry(QTreeWidgetItem * i) {
|
||||
for (int j = 0; j < cc; ++j) {
|
||||
deleteEntry(i->child(0));
|
||||
}
|
||||
vw = qobject_cast<ConfigValueWidget * >(itemWidget(i, 1));
|
||||
cb = qobject_cast<UComboBox * >(itemWidget(i, 2));
|
||||
vw = qobject_cast<ConfigValueWidget *>(itemWidget(i, 1));
|
||||
cb = qobject_cast<UComboBox *>(itemWidget(i, 2));
|
||||
if (vw) {
|
||||
w_values.remove(w_values.indexOf(vw));
|
||||
delete vw;
|
||||
@@ -373,8 +381,8 @@ bool QPIConfigWidget::filterItem(const QString & f, QTreeWidgetItem * i) {
|
||||
return true;
|
||||
}
|
||||
bool ret = (!isColumnHidden(0) && i->text(0).indexOf(f, 0, Qt::CaseInsensitive) >= 0) ||
|
||||
(!isColumnHidden(1) && itemCWidget(i)->value.indexOf(f, 0, Qt::CaseInsensitive) >= 0) ||
|
||||
(!isColumnHidden(3) && i->text(3).indexOf(f, 0, Qt::CaseInsensitive) >= 0);
|
||||
(!isColumnHidden(1) && itemCWidget(i)->value.indexOf(f, 0, Qt::CaseInsensitive) >= 0) ||
|
||||
(!isColumnHidden(3) && i->text(3).indexOf(f, 0, Qt::CaseInsensitive) >= 0);
|
||||
if (itemTWidget(i)) {
|
||||
ret = ret || (!isColumnHidden(2) && itemTWidget(i)->currentText().indexOf(f, 0, Qt::CaseInsensitive) >= 0);
|
||||
}
|
||||
@@ -434,12 +442,12 @@ void QPIConfigWidget::readFromString(QString str) {
|
||||
}
|
||||
|
||||
|
||||
UComboBox::UComboBox(QWidget *parent) : QComboBox(parent) {
|
||||
UComboBox::UComboBox(QWidget * parent): QComboBox(parent) {
|
||||
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(indexChange(int)));
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::filter(const QString &f) {
|
||||
void QPIConfigWidget::filter(const QString & f) {
|
||||
if (!active) {
|
||||
return;
|
||||
}
|
||||
@@ -499,23 +507,23 @@ void QPIConfigWidget::setReadOnlyName(bool yes) {
|
||||
}
|
||||
|
||||
|
||||
ConfigValueWidget *QPIConfigWidget::itemCWidget(QTreeWidgetItem *i) {
|
||||
ConfigValueWidget * QPIConfigWidget::itemCWidget(QTreeWidgetItem * i) {
|
||||
return qobject_cast<ConfigValueWidget *>(itemWidget(i, 1));
|
||||
}
|
||||
|
||||
|
||||
UComboBox *QPIConfigWidget::itemTWidget(QTreeWidgetItem *i) {
|
||||
UComboBox * QPIConfigWidget::itemTWidget(QTreeWidgetItem * i) {
|
||||
return qobject_cast<UComboBox *>(itemWidget(i, 2));
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::addTrEntry(const QString &s, const QString &f) {
|
||||
void QPIConfigWidget::addTrEntry(const QString & s, const QString & f) {
|
||||
types.insert(s, f);
|
||||
s_types << f;
|
||||
}
|
||||
|
||||
|
||||
void QPIConfigWidget::setQPIConfig(QPIConfig *c) {
|
||||
void QPIConfigWidget::setQPIConfig(QPIConfig * c) {
|
||||
conf = c;
|
||||
buildTree();
|
||||
}
|
||||
@@ -524,4 +532,3 @@ void QPIConfigWidget::setQPIConfig(QPIConfig *c) {
|
||||
void UComboBox::indexChange(int i) {
|
||||
emit currentIndexChanged(i, this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user