Commit 2a014eae authored by Tobias Hunger's avatar Tobias Hunger
Browse files

Gerrit: No need to subclass FancyLineEdit



Change-Id: I9b25c1e0a72e8a7e5ba268e539cf71f5b28d420b
Reviewed-by: default avatarTobias Hunger <tobias.hunger@theqtcompany.com>
parent 0aad5fac
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/fancylineedit.h> #include <utils/fancylineedit.h>
#include <utils/itemviews.h> #include <utils/itemviews.h>
#include <utils/theme/theme.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <QVBoxLayout> #include <QVBoxLayout>
...@@ -59,57 +60,6 @@ namespace Internal { ...@@ -59,57 +60,6 @@ namespace Internal {
static const int layoutSpacing = 5; static const int layoutSpacing = 5;
static const int maxTitleWidth = 350; static const int maxTitleWidth = 350;
class QueryValidatingLineEdit : public Utils::FancyLineEdit
{
Q_OBJECT
public:
explicit QueryValidatingLineEdit(QWidget *parent = 0);
void setTextColor(const QColor &c);
public slots:
void setValid();
void setInvalid();
private:
bool m_valid;
const QColor m_okTextColor;
const QColor m_errorTextColor;
};
QueryValidatingLineEdit::QueryValidatingLineEdit(QWidget *parent)
: Utils::FancyLineEdit(parent)
, m_valid(true)
, m_okTextColor(palette().color(QPalette::Active, QPalette::Text))
, m_errorTextColor(Qt::red)
{
setFiltering(true);
connect(this, &QLineEdit::textChanged, this, &QueryValidatingLineEdit::setValid);
}
void QueryValidatingLineEdit::setTextColor(const QColor &c)
{
QPalette pal;
pal.setColor(QPalette::Active, QPalette::Text, c);
setPalette(pal);
}
void QueryValidatingLineEdit::setValid()
{
if (!m_valid) {
m_valid = true;
setTextColor(m_okTextColor);
}
}
void QueryValidatingLineEdit::setInvalid()
{
if (m_valid) {
m_valid = false;
setTextColor(m_errorTextColor);
}
}
GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p, GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
QWidget *parent) QWidget *parent)
: QDialog(parent) : QDialog(parent)
...@@ -119,7 +69,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p, ...@@ -119,7 +69,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
, m_queryModel(new QStringListModel(this)) , m_queryModel(new QStringListModel(this))
, m_treeView(new Utils::TreeView) , m_treeView(new Utils::TreeView)
, m_detailsBrowser(new QTextBrowser) , m_detailsBrowser(new QTextBrowser)
, m_queryLineEdit(new QueryValidatingLineEdit) , m_queryLineEdit(new Utils::FancyLineEdit)
, m_filterLineEdit(new Utils::FancyLineEdit) , m_filterLineEdit(new Utils::FancyLineEdit)
, m_repositoryChooser(new Utils::PathChooser) , m_repositoryChooser(new Utils::PathChooser)
, m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Close)) , m_buttonBox(new QDialogButtonBox(QDialogButtonBox::Close))
...@@ -141,6 +91,11 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p, ...@@ -141,6 +91,11 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
QCompleter *completer = new QCompleter(this); QCompleter *completer = new QCompleter(this);
completer->setModel(m_queryModel); completer->setModel(m_queryModel);
m_queryLineEdit->setSpecialCompleter(completer); m_queryLineEdit->setSpecialCompleter(completer);
m_queryLineEdit->setOkColor(Utils::creatorTheme()->color(Utils::Theme::TextColorNormal));
m_queryLineEdit->setErrorColor(Utils::creatorTheme()->color(Utils::Theme::TextColorError));
m_queryLineEdit->setValidationFunction([this](Utils::FancyLineEdit *, QString *) {
return m_model->state() != GerritModel::Error;
});
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));
...@@ -150,7 +105,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p, ...@@ -150,7 +105,7 @@ GerritDialog::GerritDialog(const QSharedPointer<GerritParameters> &p,
connect(m_filterLineEdit, &Utils::FancyLineEdit::filterChanged, connect(m_filterLineEdit, &Utils::FancyLineEdit::filterChanged,
m_filterModel, &QSortFilterProxyModel::setFilterFixedString); m_filterModel, &QSortFilterProxyModel::setFilterFixedString);
connect(m_queryLineEdit, &QLineEdit::returnPressed, this, &GerritDialog::slotRefresh); connect(m_queryLineEdit, &QLineEdit::returnPressed, this, &GerritDialog::slotRefresh);
connect(m_model, &GerritModel::queryError, m_queryLineEdit, &QueryValidatingLineEdit::setInvalid); connect(m_model, &GerritModel::stateChanged, m_queryLineEdit, &Utils::FancyLineEdit::validate);
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
changesLayout->addLayout(filterLayout); changesLayout->addLayout(filterLayout);
changesLayout->addWidget(m_treeView); changesLayout->addWidget(m_treeView);
...@@ -339,5 +294,3 @@ void GerritDialog::fetchFinished() ...@@ -339,5 +294,3 @@ void GerritDialog::fetchFinished()
} // namespace Internal } // namespace Internal
} // namespace Gerrit } // namespace Gerrit
#include "gerritdialog.moc"
...@@ -100,7 +100,7 @@ private: ...@@ -100,7 +100,7 @@ private:
QStringListModel *m_queryModel; QStringListModel *m_queryModel;
Utils::TreeView *m_treeView; Utils::TreeView *m_treeView;
QTextBrowser *m_detailsBrowser; QTextBrowser *m_detailsBrowser;
QueryValidatingLineEdit *m_queryLineEdit; Utils::FancyLineEdit *m_queryLineEdit;
Utils::FancyLineEdit *m_filterLineEdit; Utils::FancyLineEdit *m_filterLineEdit;
Utils::PathChooser *m_repositoryChooser; Utils::PathChooser *m_repositoryChooser;
QDialogButtonBox *m_buttonBox; QDialogButtonBox *m_buttonBox;
......
...@@ -409,7 +409,6 @@ void QueryContext::timeout() ...@@ -409,7 +409,6 @@ void QueryContext::timeout()
GerritModel::GerritModel(const QSharedPointer<GerritParameters> &p, QObject *parent) GerritModel::GerritModel(const QSharedPointer<GerritParameters> &p, QObject *parent)
: QStandardItemModel(0, ColumnCount, parent) : QStandardItemModel(0, ColumnCount, parent)
, m_parameters(p) , m_parameters(p)
, m_query(0)
{ {
QStringList headers; // Keep in sync with GerritChange::toHtml() QStringList headers; // Keep in sync with GerritChange::toHtml()
headers << QLatin1String("#") << tr("Subject") << tr("Owner") headers << QLatin1String("#") << tr("Subject") << tr("Owner")
...@@ -546,6 +545,7 @@ void GerritModel::refresh(const QString &query) ...@@ -546,6 +545,7 @@ void GerritModel::refresh(const QString &query)
connect(m_query, &QueryContext::finished, this, &GerritModel::queriesFinished); connect(m_query, &QueryContext::finished, this, &GerritModel::queriesFinished);
emit refreshStateChanged(true); emit refreshStateChanged(true);
m_query->start(); m_query->start();
setState(Running);
} }
void GerritModel::clearData() void GerritModel::clearData()
...@@ -554,6 +554,14 @@ void GerritModel::clearData() ...@@ -554,6 +554,14 @@ void GerritModel::clearData()
removeRows(0, rows); removeRows(0, rows);
} }
void GerritModel::setState(GerritModel::QueryState s)
{
if (s == m_state)
return;
m_state = s;
emit stateChanged();
}
/* Parse gerrit query Json output. /* Parse gerrit query Json output.
* See http://gerrit.googlecode.com/svn/documentation/2.1.5/cmd-query.html * See http://gerrit.googlecode.com/svn/documentation/2.1.5/cmd-query.html
* Note: The url will be present only if "canonicalWebUrl" is configured * Note: The url will be present only if "canonicalWebUrl" is configured
...@@ -746,8 +754,8 @@ bool gerritChangeLessThan(const GerritChangePtr &c1, const GerritChangePtr &c2) ...@@ -746,8 +754,8 @@ bool gerritChangeLessThan(const GerritChangePtr &c1, const GerritChangePtr &c2)
void GerritModel::queryFinished(const QByteArray &output) void GerritModel::queryFinished(const QByteArray &output)
{ {
QList<GerritChangePtr> changes; QList<GerritChangePtr> changes;
if (!parseOutput(m_parameters, output, changes)) setState(parseOutput(m_parameters, output, changes) ? Ok : Error);
emit queryError();
// Populate a hash with indices for faster access. // Populate a hash with indices for faster access.
QHash<QString, int> idIndexHash; QHash<QString, int> idIndexHash;
const int count = changes.size(); const int count = changes.size();
...@@ -813,6 +821,7 @@ void GerritModel::queriesFinished() ...@@ -813,6 +821,7 @@ void GerritModel::queriesFinished()
{ {
m_query->deleteLater(); m_query->deleteLater();
m_query = 0; m_query = 0;
setState(Idle);
emit refreshStateChanged(false); emit refreshStateChanged(false);
} }
......
...@@ -125,25 +125,29 @@ public: ...@@ -125,25 +125,29 @@ public:
QStandardItem *itemForId(const QString &id) const; QStandardItem *itemForId(const QString &id) const;
public slots: enum QueryState { Idle, Running, Ok, Error };
QueryState state() const { return m_state; }
void refresh(const QString &query); void refresh(const QString &query);
signals: signals:
void refreshStateChanged(bool isRefreshing); // For disabling the "Refresh" button. void refreshStateChanged(bool isRefreshing); // For disabling the "Refresh" button.
void queryError(); void stateChanged();
private slots: private:
void queryFinished(const QByteArray &); void queryFinished(const QByteArray &);
void queriesFinished(); void queriesFinished();
void clearData(); void clearData();
private: void setState(QueryState s);
QString dependencyHtml(const QString &header, const QString &changeId, QString dependencyHtml(const QString &header, const QString &changeId,
const QString &serverPrefix) const; const QString &serverPrefix) const;
QList<QStandardItem *> changeToRow(const GerritChangePtr &c) const; QList<QStandardItem *> changeToRow(const GerritChangePtr &c) const;
const QSharedPointer<GerritParameters> m_parameters; const QSharedPointer<GerritParameters> m_parameters;
QueryContext *m_query; QueryContext *m_query = 0;
QueryState m_state = Idle;
QString m_userName; QString m_userName;
}; };
......
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