Commit 7c77331e authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Friedemann Kleint
Browse files

Gerrit: Replace 'additional queries' with a query completer



Change-Id: Idbc3f0a0dc47c63eb02ee105965ec52fda712f84
Reviewed-by: default avatarFriedemann Kleint <Friedemann.Kleint@nokia.com>
parent cb8c8ca1
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "gerritparameters.h" #include "gerritparameters.h"
#include <utils/filterlineedit.h> #include <utils/filterlineedit.h>
#include <coreplugin/icore.h>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QHBoxLayout> #include <QHBoxLayout>
...@@ -53,6 +54,8 @@ ...@@ -53,6 +54,8 @@
#include <QClipboard> #include <QClipboard>
#include <QApplication> #include <QApplication>
#include <QProcess> #include <QProcess>
#include <QStringListModel>
#include <QCompleter>
namespace Gerrit { namespace Gerrit {
namespace Internal { namespace Internal {
...@@ -98,6 +101,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p, ...@@ -98,6 +101,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
, m_parameters(p) , m_parameters(p)
, m_filterModel(new QSortFilterProxyModel(this)) , m_filterModel(new QSortFilterProxyModel(this))
, m_model(new GerritModel(p, this)) , m_model(new GerritModel(p, this))
, m_queryModel(new QStringListModel(this))
, m_treeView(new QTreeView) , m_treeView(new QTreeView)
, m_detailsBrowser(new QTextBrowser) , m_detailsBrowser(new QTextBrowser)
, m_queryLineEdit(new QueryValidatingLineEdit) , m_queryLineEdit(new QueryValidatingLineEdit)
...@@ -115,6 +119,10 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p, ...@@ -115,6 +119,10 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
queryLabel->setBuddy(m_queryLineEdit); queryLabel->setBuddy(m_queryLineEdit);
m_queryLineEdit->setFixedWidth(400); m_queryLineEdit->setFixedWidth(400);
m_queryLineEdit->setPlaceholderText(tr("Change #, SHA-1, tr:id, owner:email or reviewer:email")); m_queryLineEdit->setPlaceholderText(tr("Change #, SHA-1, tr:id, owner:email or reviewer:email"));
m_queryModel->setStringList(m_parameters->savedQueries);
QCompleter *completer = new QCompleter(this);
completer->setModel(m_queryModel);
m_queryLineEdit->setCompleter(completer);
filterLayout->addWidget(queryLabel); filterLayout->addWidget(queryLabel);
filterLayout->addWidget(m_queryLineEdit); filterLayout->addWidget(m_queryLineEdit);
filterLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored)); filterLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored));
...@@ -185,6 +193,17 @@ QPushButton *GerritDialog::addActionButton(const QString &text, const char *butt ...@@ -185,6 +193,17 @@ QPushButton *GerritDialog::addActionButton(const QString &text, const char *butt
return button; return button;
} }
void GerritDialog::updateCompletions(const QString &query)
{
if (query.isEmpty())
return;
QStringList &queries = m_parameters->savedQueries;
queries.removeAll(query);
queries.prepend(query);
m_queryModel->setStringList(queries);
m_parameters->saveQueries(Core::ICore::instance()->settings());
}
GerritDialog::~GerritDialog() GerritDialog::~GerritDialog()
{ {
} }
...@@ -225,7 +244,9 @@ void GerritDialog::slotFetchCheckout() ...@@ -225,7 +244,9 @@ void GerritDialog::slotFetchCheckout()
void GerritDialog::slotRefresh() void GerritDialog::slotRefresh()
{ {
m_model->refresh(m_queryLineEdit->text()); const QString &query = m_queryLineEdit->text().trimmed();
updateCompletions(query);
m_model->refresh(query);
} }
const QStandardItem *GerritDialog::itemAt(const QModelIndex &i, int column) const const QStandardItem *GerritDialog::itemAt(const QModelIndex &i, int column) const
......
...@@ -44,6 +44,7 @@ class QLabel; ...@@ -44,6 +44,7 @@ class QLabel;
class QModelIndex; class QModelIndex;
class QSortFilterProxyModel; class QSortFilterProxyModel;
class QStandardItem; class QStandardItem;
class QStringListModel;
class QPushButton; class QPushButton;
class QDialogButtonBox; class QDialogButtonBox;
class QTextBrowser; class QTextBrowser;
...@@ -99,10 +100,12 @@ private: ...@@ -99,10 +100,12 @@ private:
const QStandardItem *itemAt(const QModelIndex &i, int column = 0) const; const QStandardItem *itemAt(const QModelIndex &i, int column = 0) const;
const QStandardItem *currentItem(int column = 0) const; const QStandardItem *currentItem(int column = 0) const;
QPushButton *addActionButton(const QString &text, const char *buttonSlot); QPushButton *addActionButton(const QString &text, const char *buttonSlot);
void updateCompletions(const QString &query);
const QSharedPointer<GerritParameters> m_parameters; const QSharedPointer<GerritParameters> m_parameters;
QSortFilterProxyModel *m_filterModel; QSortFilterProxyModel *m_filterModel;
GerritModel *m_model; GerritModel *m_model;
QStringListModel *m_queryModel;
QTreeView *m_treeView; QTreeView *m_treeView;
QTextBrowser *m_detailsBrowser; QTextBrowser *m_detailsBrowser;
QueryValidatingLineEdit *m_queryLineEdit; QueryValidatingLineEdit *m_queryLineEdit;
......
...@@ -434,13 +434,6 @@ void GerritModel::refresh(const QString &query) ...@@ -434,13 +434,6 @@ void GerritModel::refresh(const QString &query)
// For Review by: // For Review by:
queries.push_back(statusOpenQuery + QLatin1String(" reviewer:") + m_parameters->user); queries.push_back(statusOpenQuery + QLatin1String(" reviewer:") + m_parameters->user);
} }
// Any custom queries?
if (!m_parameters->additionalQueries.isEmpty()) {
foreach (const QString &customQuery, m_parameters->additionalQueries.split(QString::SkipEmptyParts)) {
if (!customQuery.trimmed().isEmpty())
queries.push_back(customQuery);
}
}
} }
m_query = new QueryContext(queries, m_parameters, this); m_query = new QueryContext(queries, m_parameters, this);
......
...@@ -93,7 +93,6 @@ GerritOptionsWidget::GerritOptionsWidget(QWidget *parent) ...@@ -93,7 +93,6 @@ GerritOptionsWidget::GerritOptionsWidget(QWidget *parent)
, m_userLineEdit(new QLineEdit(this)) , m_userLineEdit(new QLineEdit(this))
, m_sshChooser(new Utils::PathChooser) , m_sshChooser(new Utils::PathChooser)
, m_portSpinBox(new QSpinBox(this)) , m_portSpinBox(new QSpinBox(this))
, m_additionalQueriesLineEdit(new QLineEdit(this))
, m_httpsCheckBox(new QCheckBox(tr("HTTPS"))) , m_httpsCheckBox(new QCheckBox(tr("HTTPS")))
{ {
QFormLayout *formLayout = new QFormLayout(this); QFormLayout *formLayout = new QFormLayout(this);
...@@ -106,12 +105,6 @@ GerritOptionsWidget::GerritOptionsWidget(QWidget *parent) ...@@ -106,12 +105,6 @@ GerritOptionsWidget::GerritOptionsWidget(QWidget *parent)
m_portSpinBox->setMinimum(1); m_portSpinBox->setMinimum(1);
m_portSpinBox->setMaximum(65535); m_portSpinBox->setMaximum(65535);
formLayout->addRow(tr("&Port: "), m_portSpinBox); formLayout->addRow(tr("&Port: "), m_portSpinBox);
formLayout->addRow(tr("&Additional queries: "), m_additionalQueriesLineEdit);
m_additionalQueriesLineEdit->setToolTip(tr(
"A comma-separated list of additional queries.\n"
"For example \"status:staged,status:integrating\""
" can be used to show the status of the Continuous Integration\n"
"of the Qt project."));
formLayout->addRow(tr("P&rotocol:"), m_httpsCheckBox); formLayout->addRow(tr("P&rotocol:"), m_httpsCheckBox);
m_httpsCheckBox->setToolTip(tr( m_httpsCheckBox->setToolTip(tr(
"Determines the protocol used to form a URL in case\n" "Determines the protocol used to form a URL in case\n"
...@@ -126,7 +119,6 @@ GerritParameters GerritOptionsWidget::parameters() const ...@@ -126,7 +119,6 @@ GerritParameters GerritOptionsWidget::parameters() const
result.user = m_userLineEdit->text().trimmed(); result.user = m_userLineEdit->text().trimmed();
result.ssh = m_sshChooser->path(); result.ssh = m_sshChooser->path();
result.port = m_portSpinBox->value(); result.port = m_portSpinBox->value();
result.additionalQueries = m_additionalQueriesLineEdit->text().trimmed();
result.https = m_httpsCheckBox->isChecked(); result.https = m_httpsCheckBox->isChecked();
return result; return result;
} }
...@@ -137,7 +129,6 @@ void GerritOptionsWidget::setParameters(const GerritParameters &p) ...@@ -137,7 +129,6 @@ void GerritOptionsWidget::setParameters(const GerritParameters &p)
m_userLineEdit->setText(p.user); m_userLineEdit->setText(p.user);
m_sshChooser->setPath(p.ssh); m_sshChooser->setPath(p.ssh);
m_portSpinBox->setValue(p.port); m_portSpinBox->setValue(p.port);
m_additionalQueriesLineEdit->setText(p.additionalQueries);
m_httpsCheckBox->setChecked(p.https); m_httpsCheckBox->setChecked(p.https);
} }
......
...@@ -67,7 +67,6 @@ private: ...@@ -67,7 +67,6 @@ private:
QLineEdit *m_userLineEdit; QLineEdit *m_userLineEdit;
Utils::PathChooser *m_sshChooser; Utils::PathChooser *m_sshChooser;
QSpinBox *m_portSpinBox; QSpinBox *m_portSpinBox;
QLineEdit *m_additionalQueriesLineEdit;
QCheckBox *m_httpsCheckBox; QCheckBox *m_httpsCheckBox;
}; };
......
...@@ -55,7 +55,7 @@ static const char sshKeyC[] = "Ssh"; ...@@ -55,7 +55,7 @@ static const char sshKeyC[] = "Ssh";
static const char httpsKeyC[] = "Https"; static const char httpsKeyC[] = "Https";
static const char defaultHostC[] = "codereview.qt-project.org"; static const char defaultHostC[] = "codereview.qt-project.org";
static const char defaultSshC[] = "ssh"; static const char defaultSshC[] = "ssh";
static const char additionalQueriesKeyC[] = "AdditionalQueries"; static const char savedQueriesKeyC[] = "SavedQueries";
static const char defaultPortFlag[] = "-p"; static const char defaultPortFlag[] = "-p";
...@@ -121,8 +121,7 @@ QString GerritParameters::sshHostArgument() const ...@@ -121,8 +121,7 @@ QString GerritParameters::sshHostArgument() const
bool GerritParameters::equals(const GerritParameters &rhs) const bool GerritParameters::equals(const GerritParameters &rhs) const
{ {
return port == rhs.port && host == rhs.host && user == rhs.user return port == rhs.port && host == rhs.host && user == rhs.user
&& ssh == rhs.ssh && additionalQueries == rhs.additionalQueries && ssh == rhs.ssh && https == rhs.https;
&& https == rhs.https;
} }
void GerritParameters::toSettings(QSettings *s) const void GerritParameters::toSettings(QSettings *s) const
...@@ -133,11 +132,17 @@ void GerritParameters::toSettings(QSettings *s) const ...@@ -133,11 +132,17 @@ void GerritParameters::toSettings(QSettings *s) const
s->setValue(QLatin1String(portKeyC), port); s->setValue(QLatin1String(portKeyC), port);
s->setValue(QLatin1String(portFlagKeyC), portFlag); s->setValue(QLatin1String(portFlagKeyC), portFlag);
s->setValue(QLatin1String(sshKeyC), ssh); s->setValue(QLatin1String(sshKeyC), ssh);
s->setValue(QLatin1String(additionalQueriesKeyC), additionalQueries);
s->setValue(QLatin1String(httpsKeyC), https); s->setValue(QLatin1String(httpsKeyC), https);
s->endGroup(); s->endGroup();
} }
void GerritParameters::saveQueries(QSettings *s) const
{
s->beginGroup(QLatin1String(settingsGroupC));
s->setValue(QLatin1String(savedQueriesKeyC), savedQueries.join(QLatin1String(",")));
s->endGroup();
}
void GerritParameters::fromSettings(const QSettings *s) void GerritParameters::fromSettings(const QSettings *s)
{ {
const QString rootKey = QLatin1String(settingsGroupC) + QLatin1Char('/'); const QString rootKey = QLatin1String(settingsGroupC) + QLatin1Char('/');
...@@ -146,7 +151,8 @@ void GerritParameters::fromSettings(const QSettings *s) ...@@ -146,7 +151,8 @@ void GerritParameters::fromSettings(const QSettings *s)
ssh = s->value(rootKey + QLatin1String(sshKeyC), QString()).toString(); ssh = s->value(rootKey + QLatin1String(sshKeyC), QString()).toString();
port = s->value(rootKey + QLatin1String(portKeyC), QVariant(int(defaultPort))).toInt(); port = s->value(rootKey + QLatin1String(portKeyC), QVariant(int(defaultPort))).toInt();
portFlag = s->value(rootKey + QLatin1String(portFlagKeyC), QLatin1String(defaultPortFlag)).toString(); portFlag = s->value(rootKey + QLatin1String(portFlagKeyC), QLatin1String(defaultPortFlag)).toString();
additionalQueries = s->value(rootKey + QLatin1String(additionalQueriesKeyC), QString()).toString(); savedQueries = s->value(rootKey + QLatin1String(savedQueriesKeyC), QString()).toString()
.split(QLatin1String(","));
https = s->value(rootKey + QLatin1String(httpsKeyC), QVariant(true)).toBool(); https = s->value(rootKey + QLatin1String(httpsKeyC), QVariant(true)).toBool();
if (ssh.isEmpty()) if (ssh.isEmpty())
ssh = detectSsh(); ssh = detectSsh();
......
...@@ -50,6 +50,7 @@ public: ...@@ -50,6 +50,7 @@ public:
bool isValid() const; bool isValid() const;
bool equals(const GerritParameters &rhs) const; bool equals(const GerritParameters &rhs) const;
void toSettings(QSettings *) const; void toSettings(QSettings *) const;
void saveQueries(QSettings *) const;
void fromSettings(const QSettings *); void fromSettings(const QSettings *);
void setPortFlagBySshType(); void setPortFlagBySshType();
...@@ -57,7 +58,7 @@ public: ...@@ -57,7 +58,7 @@ public:
unsigned short port; unsigned short port;
QString user; QString user;
QString ssh; QString ssh;
QString additionalQueries; QStringList savedQueries;
bool https; bool https;
QString portFlag; QString portFlag;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment