Index config GUI: add skippedPaths entries through file browser dialog and let user edit them after

This commit is contained in:
Jean-Francois Dockes 2019-09-22 19:56:08 +02:00
parent 7f2dd3cd8b
commit fe3b8d78c7
3 changed files with 59 additions and 23 deletions

View File

@ -197,10 +197,9 @@ ConfParamW *ConfTabsW::addParam(
ConfParamW *ConfTabsW::findParamW(const QString& varname) ConfParamW *ConfTabsW::findParamW(const QString& varname)
{ {
for (vector<ConfParamW *>::iterator it = m_params.begin(); for (const auto& param : m_params) {
it != m_params.end(); it++) { if (!varname.compare(param->getVarName())) {
if (!varname.compare((*it)->getVarName())) { return param;
return *it;
} }
} }
return 0; return 0;
@ -216,7 +215,7 @@ void ConfTabsW::endOfList(int tabindex)
bool ConfTabsW::enableLink(ConfParamW* boolw, ConfParamW* otherw, bool revert) bool ConfTabsW::enableLink(ConfParamW* boolw, ConfParamW* otherw, bool revert)
{ {
if (std::find(m_params.begin(), m_params.end(), boolw) == m_params.end() || if (std::find(m_params.begin(), m_params.end(), boolw) == m_params.end() ||
std::find(m_params.begin(), m_params.end(), otherw) == std::find(m_params.begin(), m_params.end(), otherw) ==
m_params.end()) { m_params.end()) {
cerr << "ConfTabsW::enableLink: param not found\n"; cerr << "ConfTabsW::enableLink: param not found\n";
return false; return false;
@ -259,21 +258,18 @@ void ConfPanelW::endOfList()
void ConfPanelW::storeValues() void ConfPanelW::storeValues()
{ {
for (vector<QWidget *>::iterator it = m_widgets.begin(); for (auto& widgetp : m_widgets) {
it != m_widgets.end(); it++) { ((ConfParamW*)widgetp)->storeValue();
ConfParamW *p = (ConfParamW*)*it;
p->storeValue();
} }
} }
void ConfPanelW::loadValues() void ConfPanelW::loadValues()
{ {
for (vector<QWidget *>::iterator it = m_widgets.begin(); for (auto& widgetp : m_widgets) {
it != m_widgets.end(); it++) { ((ConfParamW*)widgetp)->loadValue();
ConfParamW *p = (ConfParamW*)*it;
p->loadValue();
} }
} }
static QString myGetFileName(bool isdir, QString caption = QString(), static QString myGetFileName(bool isdir, QString caption = QString(),
bool filenosave = false); bool filenosave = false);
@ -615,19 +611,34 @@ ConfParamSLW::ConfParamSLW(
QPushButton *pbA = new QPushButton(this); QPushButton *pbA = new QPushButton(this);
QString text = tr("+"); QString text = tr("+");
pbA->setText(text); pbA->setText(text);
pbA->setToolTip(tr("Add entry"));
int width = pbA->fontMetrics().boundingRect(text).width() + 15; int width = pbA->fontMetrics().boundingRect(text).width() + 15;
pbA->setMaximumWidth(width); pbA->setMaximumWidth(width);
setSzPol(pbA, QSizePolicy::Minimum, QSizePolicy::Fixed, 0, 0); setSzPol(pbA, QSizePolicy::Minimum, QSizePolicy::Fixed, 0, 0);
hl1->addWidget(pbA); hl1->addWidget(pbA);
QObject::connect(pbA, SIGNAL(clicked()), this, SLOT(showInputDialog()));
QPushButton *pbD = new QPushButton(this); QPushButton *pbD = new QPushButton(this);
text = tr("-"); text = tr("-");
pbD->setText(text); pbD->setText(text);
pbD->setToolTip(tr("Delete selected entries"));
width = pbD->fontMetrics().boundingRect(text).width() + 15; width = pbD->fontMetrics().boundingRect(text).width() + 15;
pbD->setMaximumWidth(width); pbD->setMaximumWidth(width);
setSzPol(pbD, QSizePolicy::Minimum, QSizePolicy::Fixed, 0, 0); setSzPol(pbD, QSizePolicy::Minimum, QSizePolicy::Fixed, 0, 0);
hl1->addWidget(pbD); hl1->addWidget(pbD);
QObject::connect(pbD, SIGNAL(clicked()), this, SLOT(deleteSelected()));
m_pbE = new QPushButton(this);
text = tr("~");
m_pbE->setText(text);
m_pbE->setToolTip(tr("Edit selected entries"));
width = m_pbE->fontMetrics().boundingRect(text).width() + 15;
m_pbE->setMaximumWidth(width);
setSzPol(m_pbE, QSizePolicy::Minimum, QSizePolicy::Fixed, 0, 0);
hl1->addWidget(m_pbE);
QObject::connect(m_pbE, SIGNAL(clicked()), this, SLOT(editSelected()));
m_pbE->hide();
vl1->addLayout(hl1); vl1->addLayout(hl1);
m_hl->addLayout(vl1); m_hl->addLayout(vl1);
@ -638,8 +649,15 @@ ConfParamSLW::ConfParamSLW(
setSzPol(this, QSizePolicy::Preferred, QSizePolicy::Preferred, 1, 1); setSzPol(this, QSizePolicy::Preferred, QSizePolicy::Preferred, 1, 1);
loadValue(); loadValue();
QObject::connect(pbA, SIGNAL(clicked()), this, SLOT(showInputDialog())); }
QObject::connect(pbD, SIGNAL(clicked()), this, SLOT(deleteSelected()));
void ConfParamSLW::setEditable(bool onoff)
{
if (onoff) {
m_pbE->show();
} else {
m_pbE->hide();
}
} }
void ConfParamSLW::storeValue() void ConfParamSLW::storeValue()
@ -670,11 +688,11 @@ void ConfParamSLW::loadValue()
vector<string> ls; vector<string> ls;
stringToStrings(m_origvalue, ls); stringToStrings(m_origvalue, ls);
QStringList qls; QStringList qls;
for (vector<string>::const_iterator it = ls.begin(); it != ls.end(); it++) { for (const auto& str : ls) {
if (m_fsencoding) { if (m_fsencoding) {
qls.push_back(QString::fromLocal8Bit(it->c_str())); qls.push_back(QString::fromLocal8Bit(str.c_str()));
} else { } else {
qls.push_back(QString::fromUtf8(it->c_str())); qls.push_back(QString::fromUtf8(str.c_str()));
} }
} }
m_lb->clear(); m_lb->clear();
@ -720,13 +738,27 @@ void ConfParamSLW::deleteSelected()
} }
} }
for (vector<int>::reverse_iterator it = idxes.rbegin(); for (vector<int>::reverse_iterator it = idxes.rbegin();
it != idxes.rend(); it++) { it != idxes.rend(); it++) {
QListWidgetItem *item = m_lb->takeItem(*it); QListWidgetItem *item = m_lb->takeItem(*it);
emit entryDeleted(item->text()); emit entryDeleted(item->text());
delete item; delete item;
} }
} }
void ConfParamSLW::editSelected()
{
for (int i = 0; i < m_lb->count(); i++) {
if (m_lb->item(i)->isSelected()) {
bool ok;
QString s = QInputDialog::getText(
this, "", "", QLineEdit::Normal, m_lb->item(i)->text(), &ok);
if (ok && !s.isEmpty()) {
m_lb->item(i)->setText(s);
}
}
}
}
// "Add entry" dialog for a file name list // "Add entry" dialog for a file name list
void ConfParamDNLW::showInputDialog() void ConfParamDNLW::showInputDialog()
{ {
@ -738,9 +770,9 @@ void ConfParamDNLW::showInputDialog()
m_lb->insertItem(0, s); m_lb->insertItem(0, s);
m_lb->sortItems(); m_lb->sortItems();
QList<QListWidgetItem *>items = QList<QListWidgetItem *>items =
m_lb->findItems(s, Qt::MatchFixedString | Qt::MatchCaseSensitive); m_lb->findItems(s, Qt::MatchFixedString|Qt::MatchCaseSensitive);
if (m_lb->selectionMode() == QAbstractItemView::SingleSelection && if (m_lb->selectionMode() == QAbstractItemView::SingleSelection &&
!items.empty()) { !items.empty()) {
m_lb->setCurrentItem(*items.begin()); m_lb->setCurrentItem(*items.begin());
} }
} }
@ -947,7 +979,7 @@ ConfTabsW *xmlToConfGUI(const string& xml, string& toptext,
string nvarname = looksLikeAssign(data); string nvarname = looksLikeAssign(data);
if (!nvarname.empty() && nvarname.compare(m_curvar)) { if (!nvarname.empty() && nvarname.compare(m_curvar)) {
cerr << "Var assigned [" << nvarname << "] mismatch " cerr << "Var assigned [" << nvarname << "] mismatch "
"with current variable [" << m_curvar << "]\n"; "with current variable [" << m_curvar << "]\n";
} }
m_toptext += data; m_toptext += data;
} }

View File

@ -343,6 +343,7 @@ public:
QListWidget *getListBox() { QListWidget *getListBox() {
return m_lb; return m_lb;
} }
virtual void setEditable(bool onoff);
public slots: public slots:
virtual void setEnabled(bool i) { virtual void setEnabled(bool i) {
@ -353,12 +354,14 @@ public slots:
protected slots: protected slots:
virtual void showInputDialog(); virtual void showInputDialog();
void deleteSelected(); void deleteSelected();
void editSelected();
signals: signals:
void entryDeleted(QString); void entryDeleted(QString);
protected: protected:
QListWidget *m_lb; QListWidget *m_lb;
void listToConf(); void listToConf();
std::string m_origvalue; std::string m_origvalue;
QPushButton *m_pbE;
}; };
// Dir name list // Dir name list

View File

@ -234,7 +234,7 @@ bool ConfIndexW::setupTopPanel(int idx)
"indexing starts. Default: your home.")); "indexing starts. Default: your home."));
ConfParamW *cparam = m_w->addParam( ConfParamW *cparam = m_w->addParam(
idx, ConfTabsW::CFPT_STRL, "skippedPaths", tr("Skipped paths"), idx, ConfTabsW::CFPT_DNL, "skippedPaths", tr("Skipped paths"),
tr("These are pathnames of directories which indexing " tr("These are pathnames of directories which indexing "
"will not enter.<br>Path elements may contain wildcards. " "will not enter.<br>Path elements may contain wildcards. "
"The entries must match the paths seen by the indexer " "The entries must match the paths seen by the indexer "
@ -242,6 +242,7 @@ bool ConfIndexW::setupTopPanel(int idx)
"actually a link to '/usr/home', a correct skippedPath entry " "actually a link to '/usr/home', a correct skippedPath entry "
"would be '/home/me/tmp*', not '/usr/home/me/tmp*')")); "would be '/home/me/tmp*', not '/usr/home/me/tmp*')"));
cparam->setFsEncoding(true); cparam->setFsEncoding(true);
((confgui::ConfParamSLW*)cparam)->setEditable(true);
if (m_stemlangs.empty()) { if (m_stemlangs.empty()) {
vector<string> cstemlangs = Rcl::Db::getStemmerNames(); vector<string> cstemlangs = Rcl::Db::getStemmerNames();