fragbuts sort of working
This commit is contained in:
parent
18a1c66fbc
commit
a0af5d1260
4 changed files with 94 additions and 18 deletions
|
@ -18,6 +18,7 @@
|
|||
#include "autoconfig.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <QtGui/QHBoxLayout>
|
||||
#include <QtGui/QVBoxLayout>
|
||||
|
@ -34,11 +35,13 @@
|
|||
#include "readfile.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class FragButsParser : public QXmlDefaultHandler {
|
||||
public:
|
||||
FragButsParser(QWidget *_parent)
|
||||
FragButsParser(FragButs *_parent, vector<FragButs::ButFrag>& _buttons)
|
||||
: parent(_parent), vlw(new QVBoxLayout(parent)),
|
||||
vl(new QVBoxLayout()), hl(0), bg(0), radio(false)
|
||||
vl(new QVBoxLayout()), buttons(_buttons),
|
||||
hl(0), bg(0), radio(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -59,20 +62,21 @@ private:
|
|||
QWidget *parent;
|
||||
QVBoxLayout *vlw;
|
||||
QVBoxLayout *vl;
|
||||
vector<FragButs::ButFrag>& buttons;
|
||||
|
||||
// Temporary data while parsing.
|
||||
QHBoxLayout *hl;
|
||||
QButtonGroup *bg;
|
||||
QString currentText;
|
||||
QString label;
|
||||
QString frag;
|
||||
string frag;
|
||||
bool radio;
|
||||
};
|
||||
|
||||
bool FragButsParser::startElement(const QString & /* namespaceURI */,
|
||||
const QString & /* localName */,
|
||||
const QString &qName,
|
||||
const QXmlAttributes &attributes)
|
||||
const QXmlAttributes &/*attributes*/)
|
||||
{
|
||||
currentText = "";
|
||||
if (qName == "buttons") {
|
||||
|
@ -93,21 +97,24 @@ bool FragButsParser::endElement(const QString & /* namespaceURI */,
|
|||
if (qName == "label") {
|
||||
label = currentText;
|
||||
} else if (qName == "frag") {
|
||||
frag = currentText;
|
||||
frag = qs2utf8s(currentText);
|
||||
} else if (qName == "fragbut") {
|
||||
string slab = qs2utf8s(label);
|
||||
trimstring(slab, " \t\n\t");
|
||||
label = QString::fromUtf8(slab.c_str());
|
||||
QAbstractButton *abut;
|
||||
if (radio) {
|
||||
QRadioButton *but = new QRadioButton(label, parent);
|
||||
bg->addButton(but);
|
||||
if (bg->buttons().length() == 1)
|
||||
but->setChecked(true);
|
||||
hl->addWidget(but);
|
||||
abut = but;
|
||||
} else {
|
||||
QCheckBox *but = new QCheckBox(label, parent);
|
||||
hl->addWidget(but);
|
||||
abut = but;
|
||||
}
|
||||
buttons.push_back(FragButs::ButFrag(abut, frag));
|
||||
hl->addWidget(abut);
|
||||
} else if (qName == "buttons" || qName == "radiobuttons") {
|
||||
vl->addLayout(hl);
|
||||
hl = 0;
|
||||
|
@ -128,7 +135,7 @@ FragButs::FragButs(QWidget* parent)
|
|||
return;
|
||||
}
|
||||
|
||||
FragButsParser parser(this);
|
||||
FragButsParser parser(this, m_buttons);
|
||||
QXmlSimpleReader reader;
|
||||
reader.setContentHandler(&parser);
|
||||
reader.setErrorHandler(&parser);
|
||||
|
@ -138,8 +145,30 @@ FragButs::FragButs(QWidget* parent)
|
|||
LOGERR(("FragButs:: parse failed for [%s]\n", conf.c_str()));
|
||||
return;
|
||||
}
|
||||
for (vector<ButFrag>::iterator it = m_buttons.begin();
|
||||
it != m_buttons.end(); it++) {
|
||||
connect(it->button, SIGNAL(clicked(bool)),
|
||||
this, SLOT(onButtonClicked(bool)));
|
||||
}
|
||||
}
|
||||
|
||||
FragButs::~FragButs()
|
||||
{
|
||||
}
|
||||
|
||||
void FragButs::onButtonClicked(bool on)
|
||||
{
|
||||
LOGDEB(("FragButs::onButtonClicked: [%d]\n", int(on)));
|
||||
emit fragmentsChanged();
|
||||
}
|
||||
|
||||
void FragButs::getfrags(std::vector<std::string>& frags)
|
||||
{
|
||||
for (vector<ButFrag>::iterator it = m_buttons.begin();
|
||||
it != m_buttons.end(); it++) {
|
||||
if (it->button->isChecked() && !it->fragment.empty()) {
|
||||
LOGDEB(("FragButs: fragment [%s]\n", it->fragment.c_str()));
|
||||
frags.push_back(it->fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,8 +17,13 @@
|
|||
|
||||
#ifndef _FRAGBUTS_H_INCLUDED_
|
||||
#define _FRAGBUTS_H_INCLUDED_
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QAbstractButton;
|
||||
|
||||
/*
|
||||
* Display a series of user-defined buttons which activate query
|
||||
* language fragments to augment the current search
|
||||
|
@ -32,13 +37,26 @@ class FragButs : public QWidget
|
|||
FragButs(QWidget* parent = 0);
|
||||
virtual ~FragButs();
|
||||
|
||||
public slots:
|
||||
struct ButFrag {
|
||||
QAbstractButton *button;
|
||||
std::string fragment;
|
||||
ButFrag(QAbstractButton *but, const std::string& frag)
|
||||
: button(but), fragment(frag) {
|
||||
}
|
||||
};
|
||||
|
||||
void getfrags(std::vector<std::string>&);
|
||||
|
||||
private slots:
|
||||
void onButtonClicked(bool);
|
||||
|
||||
signals:
|
||||
void fragmentsChanged();
|
||||
|
||||
private:
|
||||
// Detect source file change
|
||||
time_t m_reftime;
|
||||
std::vector<ButFrag> m_buttons;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1059,6 +1059,8 @@ void RclMain::showFragButs()
|
|||
if (fragbuts == 0) {
|
||||
fragbuts = new FragButs(0);
|
||||
fragbuts->show();
|
||||
connect(fragbuts, SIGNAL(fragmentsChanged()),
|
||||
this, SLOT(onFragmentsChanged()));
|
||||
} else {
|
||||
// Close and reopen, in hope that makes us visible...
|
||||
fragbuts->close();
|
||||
|
@ -2248,20 +2250,43 @@ void RclMain::catgFilter(int id)
|
|||
m_filtMN->actions()[id]->setChecked(true);
|
||||
}
|
||||
|
||||
m_catgbutvecidx = id;
|
||||
setFiltSpec();
|
||||
}
|
||||
|
||||
void RclMain::setFiltSpec()
|
||||
{
|
||||
m_filtspec.reset();
|
||||
|
||||
if (id != 0) {
|
||||
string catg = m_catgbutvec[id];
|
||||
// "Category" buttons
|
||||
if (m_catgbutvecidx != 0) {
|
||||
string catg = m_catgbutvec[m_catgbutvecidx];
|
||||
string frag;
|
||||
theconfig->getGuiFilter(catg, frag);
|
||||
m_filtspec.orCrit(DocSeqFiltSpec::DSFS_QLANG, frag);
|
||||
}
|
||||
LOGDEB(("RclMain::catgFilter: calling setFiltSpec\n"));
|
||||
|
||||
// Fragments from the fragbuts buttonbox tool
|
||||
if (fragbuts) {
|
||||
vector<string> frags;
|
||||
fragbuts->getfrags(frags);
|
||||
for (vector<string>::const_iterator it = frags.begin();
|
||||
it != frags.end(); it++) {
|
||||
m_filtspec.orCrit(DocSeqFiltSpec::DSFS_QLANG, *it);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_source.isNotNull())
|
||||
m_source->setFiltSpec(m_filtspec);
|
||||
initiateQuery();
|
||||
}
|
||||
|
||||
|
||||
void RclMain::onFragmentsChanged()
|
||||
{
|
||||
setFiltSpec();
|
||||
}
|
||||
|
||||
void RclMain::toggleFullScreen()
|
||||
{
|
||||
if (isFullScreen())
|
||||
|
|
|
@ -74,6 +74,7 @@ public:
|
|||
m_toolsTB(0), m_resTB(0),
|
||||
m_filtFRM(0), m_filtCMB(0), m_filtBGRP(0), m_filtMN(0),
|
||||
m_idxproc(0),
|
||||
m_catgbutvecidx(0),
|
||||
m_sortspecnochange(false),
|
||||
m_indexerState(IXST_RUNNINGNOTMINE),
|
||||
m_queryActive(false),
|
||||
|
@ -151,6 +152,7 @@ public slots:
|
|||
virtual void adjustPrefsMenu();
|
||||
virtual void catgFilter(int);
|
||||
virtual void catgFilter(QAction *);
|
||||
virtual void onFragmentsChanged();
|
||||
virtual void initDbOpen();
|
||||
virtual void toggleFullScreen();
|
||||
virtual void on_actionSortByDateAsc_toggled(bool on);
|
||||
|
@ -197,6 +199,7 @@ private:
|
|||
ExecCmd *m_idxproc; // Indexing process
|
||||
map<QString, QAction*> m_stemLangToId;
|
||||
vector<string> m_catgbutvec;
|
||||
int m_catgbutvecidx;
|
||||
DocSeqFiltSpec m_filtspec;
|
||||
bool m_sortspecnochange;
|
||||
DocSeqSortSpec m_sortspec;
|
||||
|
@ -226,6 +229,7 @@ private:
|
|||
virtual void updateIdxForDocs(vector<Rcl::Doc>&);
|
||||
virtual void initiateQuery();
|
||||
virtual bool containerUpToDate(Rcl::Doc& doc);
|
||||
virtual void setFiltSpec();
|
||||
};
|
||||
|
||||
#endif // RCLMAIN_W_H
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue