Commit b239f7aa authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Locator: Cleanup



* Use inline member initialization
* Remove unneeded "using"
* Replace if/else with switch-case

Change-Id: I32589e850f259c6e2d098e623077bec0a6f9eb4b
Reviewed-by: Eike Ziller's avatarEike Ziller <eike.ziller@qt.io>
parent a36a6e0a
......@@ -53,7 +53,7 @@ QList<LocatorFilterEntry> *categorize(const QString &entry, const QString &candi
} // anynoumous namespace
FileSystemFilter::FileSystemFilter(LocatorWidget *locatorWidget)
: m_locatorWidget(locatorWidget), m_includeHidden(true)
: m_locatorWidget(locatorWidget)
{
setId("Files in file system");
setDisplayName(tr("Files in File System"));
......
......@@ -54,7 +54,7 @@ public:
private:
LocatorWidget *m_locatorWidget;
bool m_includeHidden;
bool m_includeHidden = true;
QString m_currentDocumentDirectory;
};
......
......@@ -38,12 +38,7 @@
using namespace Core;
ILocatorFilter::ILocatorFilter(QObject *parent):
QObject(parent),
m_priority(Medium),
m_includedByDefault(false),
m_hidden(false),
m_enabled(true),
m_isConfigurable(true)
QObject(parent)
{
}
......
......@@ -37,10 +37,7 @@ class ILocatorFilter;
struct LocatorFilterEntry
{
LocatorFilterEntry()
: filter(0)
, fileIconResolved(false)
{}
LocatorFilterEntry() = default;
LocatorFilterEntry(ILocatorFilter *fromFilter, const QString &name, const QVariant &data,
const QIcon &icon = QIcon())
......@@ -48,7 +45,6 @@ struct LocatorFilterEntry
, displayName(name)
, internalData(data)
, displayIcon(icon)
, fileIconResolved(false)
{}
bool operator==(const LocatorFilterEntry &other) const {
......@@ -58,7 +54,7 @@ struct LocatorFilterEntry
}
/* backpointer to creating filter */
ILocatorFilter *filter;
ILocatorFilter *filter = nullptr;
/* displayed string */
QString displayName;
/* extra information displayed in light-gray in a second column (optional) */
......@@ -70,7 +66,7 @@ struct LocatorFilterEntry
/* file name, if the entry is related to a file, is used e.g. for resolving a file icon */
QString fileName;
/* internal */
bool fileIconResolved;
bool fileIconResolved = false;
};
class CORE_EXPORT ILocatorFilter : public QObject
......@@ -161,12 +157,12 @@ protected:
private:
Id m_id;
QString m_shortcut;
Priority m_priority;
Priority m_priority = Medium;
QString m_displayName;
bool m_includedByDefault;
bool m_hidden;
bool m_enabled;
bool m_isConfigurable;
bool m_includedByDefault = false;
bool m_hidden = false;
bool m_enabled = true;
bool m_isConfigurable = true;
};
} // namespace Core
......@@ -62,9 +62,7 @@ namespace Core {
namespace Internal {
Locator::Locator()
: m_settingsInitialized(false)
{
m_corePlugin = 0;
m_refreshTimer.setSingleShot(false);
connect(&m_refreshTimer, &QTimer::timeout, this, [this]() { refresh(); });
}
......
......@@ -81,7 +81,7 @@ private:
LocatorWidget *m_locatorWidget;
LocatorSettingsPage *m_settingsPage;
bool m_settingsInitialized;
bool m_settingsInitialized = false;
QList<ILocatorFilter *> m_filters;
QList<ILocatorFilter *> m_customFilters;
int m_refreshInterval;
......@@ -89,7 +89,7 @@ private:
OpenDocumentsFilter *m_openDocumentsFilter;
FileSystemFilter *m_fileSystemFilter;
ExecuteFilter *m_executeFilter;
CorePlugin *m_corePlugin;
CorePlugin *m_corePlugin = nullptr;
ExternalToolsFilter *m_externalToolsFilter;
};
......
......@@ -121,11 +121,6 @@ private:
QSize m_preferredSize;
};
} // namespace Internal
using namespace Core::Internal;
// =========== LocatorModel ===========
void LocatorModel::clear()
......@@ -152,27 +147,35 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() >= mEntries.size())
return QVariant();
if (role == Qt::DisplayRole) {
switch (role) {
case Qt::DisplayRole:
if (index.column() == 0)
return mEntries.at(index.row()).displayName;
else if (index.column() == 1)
return mEntries.at(index.row()).extraInfo;
} else if (role == Qt::ToolTipRole) {
break;
case Qt::ToolTipRole:
if (mEntries.at(index.row()).extraInfo.isEmpty())
return QVariant(mEntries.at(index.row()).displayName);
else
return QVariant(mEntries.at(index.row()).displayName
+ QLatin1String("\n\n") + mEntries.at(index.row()).extraInfo);
} else if (role == Qt::DecorationRole && index.column() == 0) {
LocatorFilterEntry &entry = mEntries[index.row()];
if (!entry.fileIconResolved && !entry.fileName.isEmpty() && entry.displayIcon.isNull()) {
entry.fileIconResolved = true;
entry.displayIcon = FileIconProvider::icon(entry.fileName);
break;
case Qt::DecorationRole:
if (index.column() == 0) {
LocatorFilterEntry &entry = mEntries[index.row()];
if (!entry.fileIconResolved && !entry.fileName.isEmpty() && entry.displayIcon.isNull()) {
entry.fileIconResolved = true;
entry.displayIcon = FileIconProvider::icon(entry.fileName);
}
return entry.displayIcon;
}
return entry.displayIcon;
} else if (role == Qt::ForegroundRole && index.column() == 1) {
return QColor(Qt::darkGray);
} else if (role == Qt::UserRole) {
break;
case Qt::ForegroundRole:
if (index.column() == 1)
return QColor(Qt::darkGray);
break;
case Qt::UserRole:
return qVariantFromValue(mEntries.at(index.row()));
}
......@@ -224,11 +227,7 @@ LocatorWidget::LocatorWidget(Locator *qop) :
m_filterMenu(new QMenu(this)),
m_refreshAction(new QAction(tr("Refresh"), this)),
m_configureAction(new QAction(ICore::msgShowOptionsDialog(), this)),
m_fileLineEdit(new Utils::FancyLineEdit),
m_needsClearResult(true),
m_updateRequested(false),
m_acceptRequested(false),
m_possibleToolTipRequest(false)
m_fileLineEdit(new Utils::FancyLineEdit)
{
// Explicitly hide the completion list popup.
m_completionList->hide();
......@@ -658,4 +657,5 @@ void LocatorWidget::addSearchResults(int firstIndex, int endIndex)
m_completionList->setCurrentIndex(m_locatorModel->index(0, 0));
}
} // namespace Internal
} // namespace Core
......@@ -89,10 +89,10 @@ private:
QFutureWatcher<LocatorFilterEntry> *m_entriesWatcher;
QMap<Id, QAction *> m_filterActionMap;
QString m_requestedCompletionText;
bool m_needsClearResult;
bool m_updateRequested;
bool m_acceptRequested;
bool m_possibleToolTipRequest;
bool m_needsClearResult = true;
bool m_updateRequested = false;
bool m_acceptRequested = false;
bool m_possibleToolTipRequest = false;
QWidget *m_progressIndicator;
QTimer m_showProgressTimer;
};
......
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