Commit 4f81a645 authored by Ahmad Samir's avatar Ahmad Samir Committed by Kurt Hindenburg
Browse files

Code cleanup

- More range-for
- Reverse iterators instead of java-style ones with toBack/hasPrevious
- Don't use a QSet (which is based on QHash) to hold a few items
parent 1defe4f6
Pipeline #88044 passed with stage
in 1 minute and 53 seconds
......@@ -364,12 +364,12 @@ void Application::createTabFromArgs(MainWindow *window, const QHash<QString, QSt
MainWindow *Application::processWindowArgs(bool &createdNewMainWindow)
{
MainWindow *window = nullptr;
if (m_parser->isSet(QStringLiteral("new-tab"))) {
QListIterator<QWidget *> iter(QApplication::topLevelWidgets());
iter.toBack();
while (iter.hasPrevious()) {
window = qobject_cast<MainWindow *>(iter.previous());
if (window != nullptr) {
const QList<QWidget *> list = QApplication::topLevelWidgets();
for (auto it = list.crbegin(), endIt = list.crend(); it != endIt; ++it) {
window = qobject_cast<MainWindow *>(*it);
if (window) {
break;
}
}
......
......@@ -114,9 +114,9 @@ QString ProcessInfo::validCurrentDir() const
return dir;
}
QSet<QString> ProcessInfo::_commonDirNames;
QStringList ProcessInfo::_commonDirNames;
QSet<QString> ProcessInfo::commonDirNames()
QStringList ProcessInfo::commonDirNames()
{
static bool forTheFirstTime = true;
......@@ -124,8 +124,8 @@ QSet<QString> ProcessInfo::commonDirNames()
const KSharedConfigPtr &config = KSharedConfig::openConfig();
const KConfigGroup &configGroup = config->group("ProcessInfo");
// Need to make a local copy so the begin() and end() point to the same QList
const QStringList commonDirsList = configGroup.readEntry("CommonDirNames", QStringList());
_commonDirNames = QSet<QString>(commonDirsList.begin(), commonDirsList.end());
_commonDirNames = configGroup.readEntry("CommonDirNames", QStringList());
_commonDirNames.removeDuplicates();
forTheFirstTime = false;
}
......@@ -135,26 +135,22 @@ QSet<QString> ProcessInfo::commonDirNames()
QString ProcessInfo::formatShortDir(const QString &input) const
{
if (input == QStringLiteral("/")) {
if (input == QLatin1Char('/')) {
return QStringLiteral("/");
}
QString result;
const QStringList &parts = input.split(QDir::separator());
const QStringList parts = input.split(QDir::separator());
QSet<QString> dirNamesToShorten = commonDirNames();
QListIterator<QString> iter(parts);
iter.toBack();
QStringList dirNamesToShorten = commonDirNames();
// go backwards through the list of the path's parts
// adding abbreviations of common directory names
// and stopping when we reach a dir name which is not
// in the commonDirNames set
while (iter.hasPrevious()) {
const QString &part = iter.previous();
for (auto it = parts.crbegin(), endIt = parts.crend(); it != endIt; ++it) {
const QString &part = *it;
if (dirNamesToShorten.contains(part)) {
result.prepend(QDir::separator() + part[0]);
} else {
......
......@@ -270,8 +270,8 @@ private:
QVector<QString> _arguments;
static QSet<QString> commonDirNames();
static QSet<QString> _commonDirNames;
static QStringList commonDirNames();
static QStringList _commonDirNames;
};
Q_DECLARE_OPERATORS_FOR_FLAGS(ProcessInfo::Fields)
......
Supports Markdown
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