forked from qt-creator/qt-creator
Locator: Fix style and reuse LocatorFilterEntries
Fix names of private members of LocatorModel to have one common style. Reuse LocatorFilterEntries where possible. Change-Id: Icca1e396b9fafd165adf35939dd7859032f90c0c Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -30,7 +30,7 @@ bool ResultData::operator==(const ResultData &other) const
|
|||||||
return textColumn1 == other.textColumn1 && textColumn2 == other.textColumn2 && highlightEqual;
|
return textColumn1 == other.textColumn1 && textColumn2 == other.textColumn2 && highlightEqual;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultData::ResultDataList ResultData::fromFilterEntryList(const QList<LocatorFilterEntry> &entries)
|
ResultData::ResultDataList ResultData::fromFilterEntryList(const LocatorFilterEntries &entries)
|
||||||
{
|
{
|
||||||
ResultDataList result;
|
ResultDataList result;
|
||||||
for (const LocatorFilterEntry &entry : entries) {
|
for (const LocatorFilterEntry &entry : entries) {
|
||||||
|
@@ -21,7 +21,7 @@ public:
|
|||||||
|
|
||||||
bool operator==(const ResultData &other) const;
|
bool operator==(const ResultData &other) const;
|
||||||
|
|
||||||
static ResultDataList fromFilterEntryList(const QList<LocatorFilterEntry> &entries);
|
static ResultDataList fromFilterEntryList(const LocatorFilterEntries &entries);
|
||||||
|
|
||||||
/// For debugging and creating reference data
|
/// For debugging and creating reference data
|
||||||
static void printFilterEntries(const ResultDataList &entries, const QString &msg = QString());
|
static void printFilterEntries(const ResultDataList &entries, const QString &msg = QString());
|
||||||
|
@@ -57,8 +57,8 @@ public:
|
|||||||
|
|
||||||
LocatorModel(QObject *parent = nullptr)
|
LocatorModel(QObject *parent = nullptr)
|
||||||
: QAbstractListModel(parent)
|
: QAbstractListModel(parent)
|
||||||
, mBackgroundColor(Utils::creatorTheme()->color(Utils::Theme::TextColorHighlightBackground))
|
, m_backgroundColor(Utils::creatorTheme()->color(Utils::Theme::TextColorHighlightBackground))
|
||||||
, mForegroundColor(Utils::creatorTheme()->color(Utils::Theme::TextColorNormal))
|
, m_foregroundColor(Utils::creatorTheme()->color(Utils::Theme::TextColorNormal))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
@@ -66,13 +66,13 @@ public:
|
|||||||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
void addEntries(const QList<LocatorFilterEntry> &entries);
|
void addEntries(const LocatorFilterEntries &entries);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
mutable QList<LocatorFilterEntry> mEntries;
|
mutable LocatorFilterEntries m_entries;
|
||||||
bool hasExtraInfo = false;
|
bool m_hasExtraInfo = false;
|
||||||
QColor mBackgroundColor;
|
QColor m_backgroundColor;
|
||||||
QColor mForegroundColor;
|
QColor m_foregroundColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CompletionDelegate : public HighlightingItemDelegate
|
class CompletionDelegate : public HighlightingItemDelegate
|
||||||
@@ -134,8 +134,8 @@ protected:
|
|||||||
void LocatorModel::clear()
|
void LocatorModel::clear()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
mEntries.clear();
|
m_entries.clear();
|
||||||
hasExtraInfo = false;
|
m_hasExtraInfo = false;
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,30 +143,30 @@ int LocatorModel::rowCount(const QModelIndex & parent) const
|
|||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
return mEntries.size();
|
return m_entries.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
int LocatorModel::columnCount(const QModelIndex &parent) const
|
int LocatorModel::columnCount(const QModelIndex &parent) const
|
||||||
{
|
{
|
||||||
if (parent.isValid())
|
if (parent.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
return hasExtraInfo ? ColumnCount : 1;
|
return m_hasExtraInfo ? ColumnCount : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant LocatorModel::data(const QModelIndex &index, int role) const
|
QVariant LocatorModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!index.isValid() || index.row() >= mEntries.size())
|
if (!index.isValid() || index.row() >= m_entries.size())
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::DisplayRole:
|
case Qt::DisplayRole:
|
||||||
if (index.column() == DisplayNameColumn)
|
if (index.column() == DisplayNameColumn)
|
||||||
return mEntries.at(index.row()).displayName;
|
return m_entries.at(index.row()).displayName;
|
||||||
else if (index.column() == ExtraInfoColumn)
|
else if (index.column() == ExtraInfoColumn)
|
||||||
return mEntries.at(index.row()).extraInfo;
|
return m_entries.at(index.row()).extraInfo;
|
||||||
break;
|
break;
|
||||||
case Qt::ToolTipRole: {
|
case Qt::ToolTipRole: {
|
||||||
const LocatorFilterEntry &entry = mEntries.at(index.row());
|
const LocatorFilterEntry &entry = m_entries.at(index.row());
|
||||||
QString toolTip = entry.displayName;
|
QString toolTip = entry.displayName;
|
||||||
if (!entry.extraInfo.isEmpty())
|
if (!entry.extraInfo.isEmpty())
|
||||||
toolTip += "\n\n" + entry.extraInfo;
|
toolTip += "\n\n" + entry.extraInfo;
|
||||||
@@ -176,7 +176,7 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
if (index.column() == DisplayNameColumn) {
|
if (index.column() == DisplayNameColumn) {
|
||||||
LocatorFilterEntry &entry = mEntries[index.row()];
|
LocatorFilterEntry &entry = m_entries[index.row()];
|
||||||
if (!entry.displayIcon && !entry.filePath.isEmpty())
|
if (!entry.displayIcon && !entry.filePath.isEmpty())
|
||||||
entry.displayIcon = FileIconProvider::icon(entry.filePath);
|
entry.displayIcon = FileIconProvider::icon(entry.filePath);
|
||||||
return entry.displayIcon ? entry.displayIcon.value() : QIcon();
|
return entry.displayIcon ? entry.displayIcon.value() : QIcon();
|
||||||
@@ -187,10 +187,10 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
|
|||||||
return QColor(Qt::darkGray);
|
return QColor(Qt::darkGray);
|
||||||
break;
|
break;
|
||||||
case LocatorEntryRole:
|
case LocatorEntryRole:
|
||||||
return QVariant::fromValue(mEntries.at(index.row()));
|
return QVariant::fromValue(m_entries.at(index.row()));
|
||||||
case int(HighlightingItemRole::StartColumn):
|
case int(HighlightingItemRole::StartColumn):
|
||||||
case int(HighlightingItemRole::Length): {
|
case int(HighlightingItemRole::Length): {
|
||||||
const LocatorFilterEntry &entry = mEntries[index.row()];
|
const LocatorFilterEntry &entry = m_entries[index.row()];
|
||||||
auto highlights = [&](LocatorFilterEntry::HighlightInfo::DataType type){
|
auto highlights = [&](LocatorFilterEntry::HighlightInfo::DataType type){
|
||||||
const bool startIndexRole = role == int(HighlightingItemRole::StartColumn);
|
const bool startIndexRole = role == int(HighlightingItemRole::StartColumn);
|
||||||
return startIndexRole ? QVariant::fromValue(entry.highlightInfo.starts(type))
|
return startIndexRole ? QVariant::fromValue(entry.highlightInfo.starts(type))
|
||||||
@@ -204,7 +204,7 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
|
|||||||
}
|
}
|
||||||
case int(HighlightingItemRole::DisplayExtra): {
|
case int(HighlightingItemRole::DisplayExtra): {
|
||||||
if (index.column() == LocatorFilterEntry::HighlightInfo::DisplayName) {
|
if (index.column() == LocatorFilterEntry::HighlightInfo::DisplayName) {
|
||||||
LocatorFilterEntry &entry = mEntries[index.row()];
|
LocatorFilterEntry &entry = m_entries[index.row()];
|
||||||
if (!entry.displayExtra.isEmpty())
|
if (!entry.displayExtra.isEmpty())
|
||||||
return QString(" (" + entry.displayExtra + ')');
|
return QString(" (" + entry.displayExtra + ')');
|
||||||
}
|
}
|
||||||
@@ -213,9 +213,9 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
|
|||||||
case int(HighlightingItemRole::DisplayExtraForeground):
|
case int(HighlightingItemRole::DisplayExtraForeground):
|
||||||
return QColor(Qt::darkGray);
|
return QColor(Qt::darkGray);
|
||||||
case int(HighlightingItemRole::Background):
|
case int(HighlightingItemRole::Background):
|
||||||
return mBackgroundColor;
|
return m_backgroundColor;
|
||||||
case int(HighlightingItemRole::Foreground):
|
case int(HighlightingItemRole::Foreground):
|
||||||
return mForegroundColor;
|
return m_foregroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -223,14 +223,14 @@ QVariant LocatorModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
void LocatorModel::addEntries(const QList<LocatorFilterEntry> &entries)
|
void LocatorModel::addEntries(const QList<LocatorFilterEntry> &entries)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), mEntries.size(), mEntries.size() + entries.size() - 1);
|
beginInsertRows(QModelIndex(), m_entries.size(), m_entries.size() + entries.size() - 1);
|
||||||
mEntries.append(entries);
|
m_entries.append(entries);
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
if (hasExtraInfo)
|
if (m_hasExtraInfo)
|
||||||
return;
|
return;
|
||||||
if (Utils::anyOf(entries, [](const LocatorFilterEntry &e) { return !e.extraInfo.isEmpty();})) {
|
if (Utils::anyOf(entries, [](const LocatorFilterEntry &e) { return !e.extraInfo.isEmpty();})) {
|
||||||
beginInsertColumns(QModelIndex(), 1, 1);
|
beginInsertColumns(QModelIndex(), 1, 1);
|
||||||
hasExtraInfo = true;
|
m_hasExtraInfo = true;
|
||||||
endInsertColumns();
|
endInsertColumns();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -556,7 +556,7 @@ void CppModelManager::findUnusedFunctions(const FilePath &folder)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Links links;
|
Links links;
|
||||||
const auto entries = matcher->outputData();
|
const LocatorFilterEntries entries = matcher->outputData();
|
||||||
for (const LocatorFilterEntry &entry : entries) {
|
for (const LocatorFilterEntry &entry : entries) {
|
||||||
static const QStringList prefixBlacklist{"main(", "~", "qHash(", "begin()", "end()",
|
static const QStringList prefixBlacklist{"main(", "~", "qHash(", "begin()", "end()",
|
||||||
"cbegin()", "cend()", "constBegin()", "constEnd()"};
|
"cbegin()", "cend()", "constBegin()", "constEnd()"};
|
||||||
|
Reference in New Issue
Block a user