Skip to content

Commit

Permalink
Added a context menu option to the inspector to filter on a certain a…
Browse files Browse the repository at this point in the history
…ttribute.
  • Loading branch information
jelmervdl committed May 27, 2011
1 parent 1da0904 commit 1bb9e1b
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ SET(dact_SRCS
src/TreeNodeInspector.cpp
src/XPathValidator.cpp
src/XSLTransformer.cpp
src/generateQuery.cpp
src/main.cpp
src/validityColor.cpp
)
Expand Down Expand Up @@ -134,6 +135,7 @@ SET(dact_HDRS
include/PopupItem.hh
include/PreferencesWindow.hh
include/QtIOCompressor.hh
include/Query.hh
include/QueryModel.hh
include/StatisticsWindow.hh
include/TreeNode.hh
Expand Down
4 changes: 3 additions & 1 deletion include/MainWindow.hh
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ private slots:
\sa addFiles
*/
void filterChanged();


void filterOnInspectorSelection();

/*!
Focusses on the first node and zooms in on that node.
\sa forcusTreeNode
Expand Down
8 changes: 8 additions & 0 deletions include/Query.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef QUERY_HH
#define QUERY_HH

#include <QString>

QString generateQuery(QString const &base, QString const &attribute, QString const &value);

#endif // QUERY_HH
2 changes: 2 additions & 0 deletions include/TreeNodeInspector.hh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class TreeNode;
class TreeNodeInspector : public QDockWidget
{
Q_OBJECT

public:
TreeNodeInspector(QWidget *parent = 0);
QMap<QString,QString> selectedAttributes() const;

public slots:
void inspect(TreeNode const *);
Expand Down
18 changes: 18 additions & 0 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <XSLTransformer.hh>
#include "ValidityColor.hh"
#include <ui_MainWindow.h>
#include <Query.hh>

namespace ac = alpinocorpus;

Expand Down Expand Up @@ -290,6 +291,8 @@ void MainWindow::createActions()
SLOT(focusFilter()));
connect(d_ui->focusHighlightAction, SIGNAL(triggered(bool)),
SLOT(focusHighlight()));
connect(d_ui->filterOnAttributeAction, SIGNAL(triggered()),
SLOT(filterOnInspectorSelection()));
}

void MainWindow::entryFound(QString) {
Expand All @@ -313,6 +316,21 @@ void MainWindow::entrySelected(QItemSelection const &current, QItemSelection con
focusFitTree();
}

void MainWindow::filterOnInspectorSelection()
{
QString query = d_filter.isEmpty() ? "//node" : d_filter;
QMap<QString,QString> attributes = d_ui->inspector->selectedAttributes();

if (attributes.size() < 1)
return;

for (QMap<QString,QString>::const_iterator itr(attributes.constBegin()),
end(attributes.constEnd()); itr != end; itr++)
query = ::generateQuery(query, itr.key(), itr.value());

setFilter(query);
}

void MainWindow::help()
{
static QUrl const usage("http://rug-compling.github.com/dact/Usage.html");
Expand Down
26 changes: 2 additions & 24 deletions src/StatisticsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "StatisticsWindow.hh"
#include "DactMacrosModel.hh"
#include "Query.hh"
#include "QueryModel.hh"
#include "PercentageCellDelegate.hh"
#include "ValidityColor.hh"
Expand Down Expand Up @@ -153,35 +154,12 @@ void StatisticsWindow::keyPressEvent(QKeyEvent *event)
QWidget::keyPressEvent(event);
}

QString StatisticsWindow::generateQuery(QString const &base, QString const &attribute, QString const &value) const
{
int subSelectionPos = base.lastIndexOf('/');

if (!subSelectionPos)
return QString();

//qWarning() << base.mid(subSelectionPos);

int closingBracketPos = base.mid(subSelectionPos).lastIndexOf(']');

QString condition = QString("@%1=\"%2\"").arg(attribute).arg(value);

if (closingBracketPos == -1)
return QString("%1[%2]").arg(base).arg(condition);
else
return QString("%1 and %2%3").arg(
base.left(subSelectionPos + closingBracketPos),
condition,
base.mid(subSelectionPos + closingBracketPos));
}


void StatisticsWindow::generateQuery(QModelIndex const &index)
{
// Get the text from the first column, that is the found value
QString data = index.sibling(index.row(), 0).data(Qt::UserRole).toString();

QString query = generateQuery(
QString query = ::generateQuery(
d_filter,
d_ui->attributeComboBox->currentText(),
data);
Expand Down
12 changes: 12 additions & 0 deletions src/TreeNodeInspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ TreeNodeInspector::TreeNodeInspector(QWidget *parent)
d_ui->attributesTree->sortByColumn(0, Qt::AscendingOrder);
}

QMap<QString, QString> TreeNodeInspector::selectedAttributes() const
{
QMap<QString,QString> pairs;
QList<QTreeWidgetItem *> selection = d_ui->attributesTree->selectedItems();

foreach (QTreeWidgetItem *attribute, selection)
pairs[attribute->data(0, Qt::DisplayRole).toString()]
= attribute->data(1, Qt::DisplayRole).toString();

return pairs;
}

void TreeNodeInspector::inspect(TreeNode const *node)
{
// Clear the table
Expand Down
23 changes: 23 additions & 0 deletions src/generateQuery.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "Query.hh"

QString generateQuery(QString const &base, QString const &attribute, QString const &value)
{
int subSelectionPos = base.lastIndexOf('/');

if (!subSelectionPos)
return QString();

//qWarning() << base.mid(subSelectionPos);

int closingBracketPos = base.mid(subSelectionPos).lastIndexOf(']');

QString condition = QString("@%1=\"%2\"").arg(attribute).arg(value);

if (closingBracketPos == -1)
return QString("%1[%2]").arg(base).arg(condition);
else
return QString("%1 and %2%3").arg(
base.left(subSelectionPos + closingBracketPos),
condition,
base.mid(subSelectionPos + closingBracketPos));
}
9 changes: 9 additions & 0 deletions ui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@
<attribute name="dockWidgetArea">
<number>2</number>
</attribute>
<property name="contextMenuPolicy">
<enum>Qt::ActionsContextMenu</enum>
</property>
<addaction name="filterOnAttributeAction"/>
</widget>
<action name="quitAction">
<property name="text">
Expand Down Expand Up @@ -571,6 +575,11 @@
<string>Ctrl+G</string>
</property>
</action>
<action name="filterOnAttributeAction">
<property name="text">
<string>Filter on attribute</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
Expand Down

0 comments on commit 1bb9e1b

Please sign in to comment.