21 #include "ui/configurationwidget.h"
22 #include <QVBoxLayout>
23 #include <QHeaderView>
28 QSplitter(Qt::Horizontal, parent),
29 m_configurationParameters(NULL),
32 m_valuesChanged(false),
37 m_treeWidget =
new QTreeWidget(
this);
38 addWidget(m_treeWidget);
40 m_treeWidget->setColumnCount(1);
41 m_treeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
42 m_treeWidget->setHeaderLabel(
"Groups");
43 m_treeWidget->header()->setClickable(
false);
44 setStretchFactor(0, 1);
47 m_tableWidget =
new QTableWidget(
this);
48 addWidget(m_tableWidget);
50 m_tableWidget->setColumnCount(2);
51 m_tableWidget->setHorizontalHeaderLabels(QStringList() <<
"Parameters" <<
"Value");
52 m_tableWidget->horizontalHeader()->setClickable(
false);
53 m_tableWidget->verticalHeader()->setClickable(
false);
54 setStretchFactor(1, 2);
57 connect(m_treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *,
int)),
this, SLOT(changeTableContent(QTreeWidgetItem *,
int)));
58 connect(m_tableWidget, SIGNAL(itemChanged(QTableWidgetItem *)),
this, SLOT(storeChangedItem(QTableWidgetItem *)));
68 m_configurationParameters = conf;
73 void ConfigurationWidget::fillWidgetTree( QString groupName, QString groupFullPath, QTreeWidgetItem* root) {
75 QTreeWidgetItem *widgetRoot =
new QTreeWidgetItem(root, QStringList() << groupName);
77 widgetRoot->setData( 0, Qt::UserRole, groupFullPath );
78 QStringList groupList = m_tmpParameters.getGroupsList( groupFullPath );
79 foreach( QString group, groupList ) {
80 fillWidgetTree( group, groupFullPath + ConfigurationParameters::GroupSeparator() + group, widgetRoot );
86 if (m_configurationParameters == NULL) {
91 m_valuesChanged =
false;
94 m_tmpParameters = *m_configurationParameters;
97 m_treeWidget->clear();
100 QTreeWidgetItem *widgetRoot =
new QTreeWidgetItem(QStringList() <<
"root");
101 widgetRoot->setData(0, Qt::UserRole,
"");
102 m_treeWidget->insertTopLevelItem(0, widgetRoot);
104 QStringList groupList = m_tmpParameters.getGroupsList(
"" );
105 foreach( QString group, groupList ) {
106 fillWidgetTree( group, group, widgetRoot );
109 m_treeWidget->setCurrentItem(m_treeWidget->topLevelItem(0));
111 m_treeWidget->update();
113 changeTableContent(m_treeWidget->currentItem(), 0);
121 for (
int r = 0; r < m_tableWidget->rowCount(); r++) {
122 QTableWidgetItem *
const item = m_tableWidget->item(r, 1);
124 item->setFlags(item->flags() & ~Qt::ItemIsEditable);
126 item->setFlags(item->flags() | Qt::ItemIsEditable);
131 m_tableWidget->update();
136 if (m_configurationParameters == NULL) {
140 *m_configurationParameters = m_tmpParameters;
143 m_valuesChanged =
false;
148 if (m_configurationParameters == NULL) {
152 m_tmpParameters = *m_configurationParameters;
158 void ConfigurationWidget::changeTableContent(QTreeWidgetItem *item,
int)
161 m_tableWidget->blockSignals(
true);
164 m_tableWidget->clearContents();
167 QString groupFullPath = item->data(0, Qt::UserRole).toString();
170 QStringList paramList = m_tmpParameters.getParametersList( groupFullPath );
171 m_tableWidget->setRowCount( paramList.size() );
172 for (
int i = 0; i < paramList.size(); i++) {
174 QTableWidgetItem *parameter =
new QTableWidgetItem( paramList[i] );
175 parameter->setFlags(Qt::ItemIsEnabled);
176 m_tableWidget->setItem(i, 0, parameter);
178 QString fullName = groupFullPath + ConfigurationParameters::GroupSeparator() + paramList[i];
179 QTableWidgetItem *value =
new QTableWidgetItem( m_tmpParameters.getValue( fullName ) );
180 value->setData( Qt::UserRole, fullName );
182 value->setFlags(Qt::ItemIsEnabled);
184 value->setFlags(Qt::ItemIsEnabled | Qt::ItemIsEditable);
186 m_tableWidget->setItem(i, 1, value);
190 m_tableWidget->blockSignals(
false);
193 m_tableWidget->update();
196 void ConfigurationWidget::storeChangedItem(QTableWidgetItem *item)
199 if (item->column() != 1) {
204 QString paramFullName = item->data( Qt::UserRole ).toString();
207 QString parameter = m_tableWidget->item(item->row(), 0)->text();
208 QString oldValue = m_tmpParameters.getValue( paramFullName );
209 QString newValue = item->text();
212 m_tmpParameters.setValue(paramFullName, newValue);
215 m_valuesChanged =
true;