Skip to content

Commit

Permalink
plugin-dom: added all widget's properties view
Browse files Browse the repository at this point in the history
  • Loading branch information
palinek committed Mar 10, 2015
1 parent 33a689e commit 6f2ccd3
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 20 deletions.
32 changes: 32 additions & 0 deletions plugin-dom/treewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "domtreeitem.h"
#include <QDebug>
#include <QTableWidget>
#include <QMetaProperty>

#define PROP_OBJECT_NAME 0
#define PROP_CLASS_NAME 1
Expand Down Expand Up @@ -68,6 +69,10 @@ TreeWindow::TreeWindow(QWidget *parent) :
connect(ui->tree, SIGNAL(itemSelectionChanged()), this, SLOT(updatePropertiesView()));
item->setSelected(true);

QHeaderView* h = new QHeaderView(Qt::Horizontal);
h->setStretchLastSection(true);
ui->allPropertiesView->setHorizontalHeader(h);
connect(h, &QHeaderView::sectionDoubleClicked, this, &TreeWindow::sectionDoubleClickedSlot);
}


Expand Down Expand Up @@ -126,11 +131,38 @@ void TreeWindow::updatePropertiesView()
ui->propertiesView->item(PROP_CLASS_NAME, 1)->setText(treeItem->widgetClassName());
ui->propertiesView->item(PROP_TEXT, 1)->setText(treeItem->widgetText());
ui->propertiesView->item(PROP_CLASS_HIERARCY, 1)->setText(treeItem->widgetClassHierarcy().join(" :: "));

QMetaObject const * const m = treeItem->widget()->metaObject();
const int curr_cnt = ui->allPropertiesView->rowCount();
ui->allPropertiesView->setRowCount(m->propertyCount());
for (int i = 0, cnt = m->propertyCount(); cnt > i; ++i)
{
if (curr_cnt <= i)
{
ui->allPropertiesView->setItem(i, 0, new QTableWidgetItem);
ui->allPropertiesView->setItem(i, 1, new QTableWidgetItem);
ui->allPropertiesView->setItem(i, 2, new QTableWidgetItem);
}
QMetaProperty const & prop = m->property(i);
ui->allPropertiesView->item(i, 0)->setText(prop.name());
ui->allPropertiesView->item(i, 1)->setText(prop.typeName());
ui->allPropertiesView->item(i, 2)->setText(prop.read(treeItem->widget()).toString());
}
for (int i = m->propertyCount(); curr_cnt > i; ++i)
ui->allPropertiesView->removeRow(i);
}


void TreeWindow::clearPropertiesView()
{
for (int i=0; i<ui->propertiesView->rowCount(); ++i)
ui->propertiesView->item(i, 1)->setText("");
for (int i = ui->allPropertiesView->rowCount(); 0 <= i; --i)
ui->allPropertiesView->removeRow(i);
ui->allPropertiesView->setRowCount(0);
}

void TreeWindow::sectionDoubleClickedSlot(int column)
{
ui->allPropertiesView->sortByColumn(column, Qt::AscendingOrder);
}
1 change: 1 addition & 0 deletions plugin-dom/treewindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class TreeWindow : public QMainWindow
private slots:
void updatePropertiesView();
void clearPropertiesView();
void sectionDoubleClickedSlot(int column);

private:
Ui::TreeWindow *ui;
Expand Down
97 changes: 77 additions & 20 deletions plugin-dom/treewindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>601</width>
<width>800</width>
<height>424</height>
</rect>
</property>
Expand All @@ -33,26 +33,83 @@
</property>
</column>
</widget>
<widget class="QTableWidget" name="propertiesView">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="gridStyle">
<enum>Qt::DotLine</enum>
<widget class="QWidget" name="propWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>Property</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
</column>
<layout class="QVBoxLayout" name="propLayout">
<item>
<widget class="QTableWidget" name="propertiesView">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="gridStyle">
<enum>Qt::DotLine</enum>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>Property</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QLabel" name="prop2Label">
<property name="text">
<string>All properties</string>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="allPropertiesView">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="gridStyle">
<enum>Qt::DotLine</enum>
</property>
<column>
<property name="text">
<string>Property</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>String value</string>
</property>
</column>
</widget>
</item>
</layout>

</widget>
</widget>
</item>
Expand Down

0 comments on commit 6f2ccd3

Please sign in to comment.