diff --git a/src/svnfrontend/blamedisplay.cpp b/src/svnfrontend/blamedisplay.cpp index 44b575a0..a2c93375 100644 --- a/src/svnfrontend/blamedisplay.cpp +++ b/src/svnfrontend/blamedisplay.cpp @@ -1,437 +1,428 @@ /*************************************************************************** * Copyright (C) 2006-2009 by Rajko Albrecht * * ral@alwins-world.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #include "blamedisplay.h" #include "ui_blamedisplay.h" #include "simple_logcb.h" #include "settings/kdesvnsettings.h" #include "svnqt/log_entry.h" #include "fronthelpers/cursorstack.h" #include "ksvnwidgets/encodingselector_impl.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define COL_LINENR 0 #define COL_REV 1 #define COL_DATE 2 #define COL_AUT 3 #define COL_LINE 4 #define TREE_ITEM_TYPE QTreeWidgetItem::UserType+1 #define BORDER 4 class LocalizedAnnotatedLine: public svn::AnnotateLine { public: explicit LocalizedAnnotatedLine(const svn::AnnotateLine &al) : svn::AnnotateLine(al) {} void localeChanged() { if (!codec_searched) { cc = QTextCodec::codecForName(Kdesvnsettings::locale_for_blame().toLocal8Bit()); codec_searched = true; } if (cc) { m_tLine = cc->toUnicode(line().data(), line().size()); m_tAuthor = cc->toUnicode(author().data(), author().size()); } else { m_tLine = QString::fromUtf8(line().data(), line().size()); m_tAuthor = QString::fromUtf8(author().data(), author().size()); } } const QString &tAuthor()const { return m_tAuthor; } const QString &tLine()const { return m_tLine; } static void reset_codec() { codec_searched = false; cc = nullptr; } protected: QString m_tAuthor, m_tLine; static bool codec_searched; static QTextCodec *cc; }; QTextCodec *LocalizedAnnotatedLine::cc = nullptr; bool LocalizedAnnotatedLine::codec_searched = false; class BlameTreeItem: public QTreeWidgetItem { public: BlameTreeItem(const svn::AnnotateLine &al, bool disp) : QTreeWidgetItem(TREE_ITEM_TYPE) , m_Content(al) , m_disp(disp) { for (int i = 0; i <= COL_LINE; ++i) { setTextAlignment(i, Qt::AlignLeft | Qt::AlignVCenter); setFont(i, QFontDatabase::systemFont(QFontDatabase::FixedFont)); } display(); } qlonglong lineNumber() const { return m_Content.lineNumber(); } svn_revnum_t rev() const { return m_Content.revision(); } void localeChanged() { m_Content.localeChanged(); if (m_disp) { setText(COL_AUT, m_Content.tAuthor()); } QString _line = m_Content.tLine(); _line.replace(QLatin1Char('\t'), QLatin1String(" ")); setText(COL_LINE, _line); } protected: LocalizedAnnotatedLine m_Content; bool m_disp; void display(); }; void BlameTreeItem::display() { setTextAlignment(COL_LINENR, Qt::AlignRight | Qt::AlignVCenter); if (m_disp) { setTextAlignment(COL_REV, Qt::AlignRight | Qt::AlignVCenter); setText(COL_REV, QString::number(m_Content.revision())); if (m_Content.date().isValid()) { setText(COL_DATE, m_Content.date().toString(Qt::SystemLocaleShortDate)); } } setText(COL_LINENR, QString::number(m_Content.lineNumber() + 1)); localeChanged(); } -class BlameDisplayData +struct BlameDisplayData { -public: - BlameDisplayData() - : max(-1) - , min(INT_MAX - 1) - , rev_count(0) - , up(false) - , m_cb(nullptr) - , m_pbGoToLine(nullptr) - , m_pbShowLog(nullptr) - {} - - svn_revnum_t max, min; - QMap m_shadingMap; - QMap m_logCache; + QHash m_shadingMap; + QHash m_logCache; QColor m_lastCalcColor; - unsigned int rev_count; - bool up; - SimpleLogCb *m_cb; + SimpleLogCb *m_cb = nullptr; QString m_File; QString reposRoot; - QPushButton *m_pbGoToLine; - QPushButton *m_pbShowLog; + QPushButton *m_pbGoToLine = nullptr; + QPushButton *m_pbShowLog = nullptr; + svn_revnum_t max = -1; + svn_revnum_t min = std::numeric_limits::max() - 1; + unsigned int rev_count = 0; + bool up = false; }; BlameDisplay::BlameDisplay(const QString &what, const svn::AnnotatedFile &blame, SimpleLogCb *cb, QWidget *parent) : KSvnDialog(QLatin1String("blame_display_dlg"), parent) , m_ui(new Ui::BlameDisplay) , m_Data(new BlameDisplayData) { m_ui->setupUi(this); m_Data->m_cb = cb; m_Data->m_pbShowLog = new QPushButton(QIcon::fromTheme(QStringLiteral("kdesvnlog")), i18n("Log message for revision"), this); connect(m_Data->m_pbShowLog, &QAbstractButton::clicked, this, &BlameDisplay::slotShowCurrentCommit); m_ui->buttonBox->addButton(m_Data->m_pbShowLog, QDialogButtonBox::ActionRole); m_Data->m_pbGoToLine = new QPushButton(i18n("Go to line"), this); connect(m_Data->m_pbGoToLine, &QAbstractButton::clicked, this, &BlameDisplay::slotGoLine); m_ui->buttonBox->addButton(m_Data->m_pbGoToLine, QDialogButtonBox::ActionRole); connect(m_ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::accept); QAction *ac = new QAction(QIcon::fromTheme(QStringLiteral("kdesvnlog")), i18n("Log message for revision"), this); connect(ac, &QAction::triggered, this, &BlameDisplay::slotShowCurrentCommit); m_ui->m_BlameTree->addAction(ac); KTreeWidgetSearchLine *searchLine = m_ui->m_TreeSearch->searchLine(); searchLine->addTreeWidget(m_ui->m_BlameTree); connect(m_ui->m_BlameTree, &QTreeWidget::itemDoubleClicked, this, &BlameDisplay::slotItemDoubleClicked); connect(m_ui->m_BlameTree, &QTreeWidget::currentItemChanged, this, &BlameDisplay::slotCurrentItemChanged); connect(m_ui->m_encodingSel, &EncodingSelector_impl::TextCodecChanged, this, &BlameDisplay::slotTextCodecChanged); setContent(what, blame); } BlameDisplay::~BlameDisplay() { delete m_Data; delete m_ui; } void BlameDisplay::setContent(const QString &what, const svn::AnnotatedFile &blame) { m_Data->m_File = what; m_Data->m_pbShowLog->setEnabled(false); - svn::AnnotatedFile::const_iterator bit; //m_BlameList->setSorting(COL_LINENR,false); m_Data->max = -1; svn_revnum_t lastRev(-1); QColor a(160, 160, 160); int offset = 10; int r = 0; int g = 0; int b = 0; uint colinc = 0; QTime t; t.start(); QList _list; _list.reserve(blame.size()); QBrush _b, _bt, _bb; bool _b_init = false, _bt_init = false; - for (bit = blame.begin(); bit != blame.end(); ++bit) { - bool disp = (*bit).revision() != lastRev || bit == blame.begin() ; + for (auto bit = blame.begin(); bit != blame.end(); ++bit) { + const svn::AnnotateLine &line = *bit; + bool disp = line.revision() != lastRev || bit == blame.begin(); - if ((*bit).revision() > m_Data->max) { - m_Data->max = (*bit).revision(); + if (line.revision() > m_Data->max) { + m_Data->max = line.revision(); ++(m_Data->rev_count); } - if ((*bit).revision() < m_Data->min) { - m_Data->min = (*bit).revision(); + if (line.revision() < m_Data->min) { + m_Data->min = line.revision(); } - BlameTreeItem *item = new BlameTreeItem((*bit), disp); + BlameTreeItem *item = new BlameTreeItem(line, disp); _list.append(item); if (disp) { - lastRev = (*bit).revision(); + lastRev = line.revision(); } if (Kdesvnsettings::self()->colored_blame()) { - if (m_Data->m_shadingMap.find((*bit).revision()) == m_Data->m_shadingMap.end()) { + auto it = m_Data->m_shadingMap.find(line.revision()); + if (it == m_Data->m_shadingMap.end()) { a.setRgb(a.red() + offset, a.green() + offset, a.blue() + offset); - m_Data->m_shadingMap[(*bit).revision()] = a; + m_Data->m_shadingMap.insert(line.revision(), a); if (a.red() > 245 || a.green() > 245 || a.blue() > 245) { if (colinc == 0) { ++colinc; } else if (r >= 50 || g >= 50 || b >= 50) { if (++colinc > 6) { colinc = 0; r = g = b = 0; } else { r = g = b = -10; } } if (colinc & 0x1) { r += 10; } if (colinc & 0x2) { g += 10; } if (colinc & 0x4) { b += 10; } a.setRgb(160 + r, 160 + g, 160 + b); } } if (!_b_init) { _b_init = true; _b = item->foreground(COL_LINENR); _b.setColor(KColorScheme(QPalette::Active, KColorScheme::Selection).foreground().color()); _bb = item->background(COL_LINENR); _b.setStyle(Qt::SolidPattern); _bb.setStyle(Qt::SolidPattern); _bb.setColor(KColorScheme(QPalette::Active, KColorScheme::Selection).background().color()); } item->setForeground(COL_LINENR, _b); item->setBackground(COL_LINENR, _bb); if (!_bt_init) { _bt_init = true; _bt = item->background(COL_REV); _bt.setStyle(Qt::SolidPattern); } - _bt.setColor(m_Data->m_shadingMap.value((*bit).revision())); + _bt.setColor(m_Data->m_shadingMap.value(line.revision())); item->setBackground(COL_REV, _bt); item->setBackground(COL_DATE, _bt); item->setBackground(COL_AUT, _bt); item->setBackground(COL_LINE, _bt); } else { - m_Data->m_shadingMap[(*bit).revision()] = QColor(); + m_Data->m_shadingMap[line.revision()] = QColor(); } } m_ui->m_BlameTree->addTopLevelItems(_list); qDebug("Time elapsed: %d ms", t.elapsed()); m_ui->m_BlameTree->resizeColumnToContents(COL_REV); m_ui->m_BlameTree->resizeColumnToContents(COL_DATE); m_ui->m_BlameTree->resizeColumnToContents(COL_AUT); m_ui->m_BlameTree->resizeColumnToContents(COL_LINENR); m_ui->m_BlameTree->resizeColumnToContents(COL_LINE); } void BlameDisplay::slotGoLine() { bool ok = true; int line = QInputDialog::getInt(this, i18n("Show line"), i18n("Show line number"), 1, 1, m_ui->m_BlameTree->topLevelItemCount(), 1, &ok); if (!ok) { return; } QTreeWidgetItemIterator it(m_ui->m_BlameTree); --line; while (*it) { BlameTreeItem *_it = static_cast((*it)); if (_it->lineNumber() == line) { m_ui->m_BlameTree->scrollToItem(*it); m_ui->m_BlameTree->setCurrentItem(*it); return; } ++it; } } void BlameDisplay::showCommit(BlameTreeItem *bti) { if (!bti) { return; } QString text; - const QMap::const_iterator it = m_Data->m_logCache.constFind(bti->rev()); + const auto it = m_Data->m_logCache.constFind(bti->rev()); if (it != m_Data->m_logCache.constEnd()) { text = it.value().message; } else { CursorStack a(Qt::BusyCursor); svn::LogEntry t; if (m_Data->m_cb && m_Data->m_cb->getSingleLog(t, bti->rev(), m_Data->m_File, m_Data->max, m_Data->reposRoot)) { m_Data->m_logCache[bti->rev()] = t; text = t.message; } } QPointer dlg(new KSvnDialog(QLatin1String("simplelog_display"), this)); dlg->setWindowTitle(i18nc("@title:window", "Log Message for Revision %1", bti->rev())); QVBoxLayout *vbox = new QVBoxLayout(dlg); KTextEdit *textEdit = new KTextEdit(dlg); vbox->addWidget(textEdit); textEdit->setFont(QFontDatabase::systemFont(QFontDatabase::FixedFont)); textEdit->setReadOnly(true); textEdit->setWordWrapMode(QTextOption::NoWrap); textEdit->setPlainText(text); QDialogButtonBox *bbox = new QDialogButtonBox(dlg); bbox->setStandardButtons(QDialogButtonBox::Close); vbox->addWidget(bbox); // QDialogButtonBox::Close is a reject role connect(bbox, &QDialogButtonBox::rejected, dlg.data(), &QDialog::accept); dlg->exec(); delete dlg; } void BlameDisplay::slotShowCurrentCommit() { QTreeWidgetItem *item = m_ui->m_BlameTree->currentItem(); if (item == nullptr || item->type() != TREE_ITEM_TYPE) { return; } BlameTreeItem *bit = static_cast(item); showCommit(bit); } void BlameDisplay::slotCurrentItemChanged(QTreeWidgetItem *item, QTreeWidgetItem *) { const bool enabled = item && item->type() == TREE_ITEM_TYPE; m_Data->m_pbShowLog->setEnabled(enabled); } void BlameDisplay::displayBlame(SimpleLogCb *_cb, const QString &item, const svn::AnnotatedFile &blame, QWidget *parent) { QPointer dlg(new BlameDisplay(item, blame, _cb, parent ? parent : QApplication::activeModalWidget())); dlg->exec(); delete dlg; } void BlameDisplay::slotItemDoubleClicked(QTreeWidgetItem *item, int) { if (item == nullptr || item->type() != TREE_ITEM_TYPE) { return; } BlameTreeItem *bit = static_cast(item); showCommit(bit); } void BlameDisplay::slotTextCodecChanged(const QString &what) { if (Kdesvnsettings::locale_for_blame() != what) { Kdesvnsettings::setLocale_for_blame(what); Kdesvnsettings::self()->save(); LocalizedAnnotatedLine::reset_codec(); QTreeWidgetItemIterator it(m_ui->m_BlameTree); while (*it) { BlameTreeItem *_it = static_cast((*it)); _it->localeChanged(); ++it; } } } diff --git a/src/svnfrontend/blamedisplay.h b/src/svnfrontend/blamedisplay.h index d30ca112..f8cb5a63 100644 --- a/src/svnfrontend/blamedisplay.h +++ b/src/svnfrontend/blamedisplay.h @@ -1,58 +1,58 @@ /*************************************************************************** * Copyright (C) 2006-2009 by Rajko Albrecht * * ral@alwins-world.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #pragma once #include "ksvnwidgets/ksvndialog.h" #include "svnqt/client.h" namespace Ui { class BlameDisplay; } class BlameTreeItem; -class BlameDisplayData; +struct BlameDisplayData; class QTreeWidgetItem; class SimpleLogCb; class BlameDisplay: public KSvnDialog { Q_OBJECT private: explicit BlameDisplay(const QString &what, const svn::AnnotatedFile &blame, SimpleLogCb *cb, QWidget *parent = nullptr); ~BlameDisplay(); void setContent(const QString &what, const svn::AnnotatedFile &blame); void showCommit(BlameTreeItem *bti); public: static void displayBlame(SimpleLogCb *_cb, const QString &item, const svn::AnnotatedFile &blame, QWidget *parent); private Q_SLOTS: void slotGoLine(); void slotShowCurrentCommit(); void slotItemDoubleClicked(QTreeWidgetItem *item, int); void slotCurrentItemChanged(QTreeWidgetItem *item, QTreeWidgetItem *); void slotTextCodecChanged(const QString &what); private: Ui::BlameDisplay *m_ui; BlameDisplayData *m_Data; }; diff --git a/src/svnfrontend/cacheentry.h b/src/svnfrontend/cacheentry.h index ad5bbff8..79fa9aaa 100644 --- a/src/svnfrontend/cacheentry.h +++ b/src/svnfrontend/cacheentry.h @@ -1,541 +1,532 @@ /*************************************************************************** * Copyright (C) 2005-2009 by Rajko Albrecht * * ral@alwins-world.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef HELPERSCACHEENTRY_H #define HELPERSCACHEENTRY_H #include "svnqt/svnqttypes.h" #include "svnqt/status.h" // std::map 'cause QMap isn't usable, it don't work with with the typenames in class #include #include #include #include #include #include #include namespace helpers { /** Class for fast search of path based items. @author Rajko Albrecht */ template class cacheEntry { public: typedef cacheEntry cache_type; typedef typename std::map cache_map_type; - typedef typename cache_map_type::const_iterator citer; - typedef typename cache_map_type::iterator iter; protected: QString m_key; bool m_isValid; C m_content; cache_map_type m_subMap; public: cacheEntry(); cacheEntry(const QString &key); cacheEntry(const cacheEntry &other); - virtual ~cacheEntry() {}; + virtual ~cacheEntry() = default; virtual bool find(QStringList &, QList &)const; //! Checks if cache contains a specific item /*! * the keylist will manipulated - so copy-operations aren't needed. * \param what Stringlist containing the components to search for * \return true if found (may or may not valid!) otherwise false */ virtual bool find(QStringList &what)const; //! Checks if cache contains a specific valid item /*! * if yes, the content will stored in st * \param what the keylist to search for * \param st target status to store content if found * \return true if found */ virtual bool findSingleValid(QStringList &what, C &st)const; //! Checks if cache contains a specific valid item /*! * in difference to virtual bool find(QStringList&,svn::StatusEntries&)const no copy operations * are made inside so it works much faster for simple find. * \param what the keylist to search for * \param check_valid_subs if true, return true if a subitem is valid even the item isn't valid * \return true if found */ virtual bool findSingleValid(QStringList &what, bool check_valid_subs)const; template void listsubs_if(QStringList &_what, T &oper)const; virtual void appendValidSub(QList &)const; virtual bool isValid()const { return m_isValid; } virtual const C &content()const { return m_content; } virtual bool deleteKey(QStringList &, bool exact); virtual void insertKey(QStringList &, const C &); virtual void setValidContent(const QString &key, const C &st) { m_key = key; m_isValid = true; m_content = st; } virtual bool hasValidSubs()const; virtual void markInvalid() { m_content = C(); m_isValid = false; } const QString &key()const { return m_key; } cacheEntry &operator=(const cacheEntry &other); #if 0 void dump_tree(int level = 0)const { QString pre; pre.fill('-', level); - std::map::const_iterator it; - for (it = m_subMap.begin(); it != m_subMap.end(); ++it) { + for (auto it = m_subMap.begin(); it != m_subMap.end(); ++it) { std::cout << pre.latin1() << it->first.latin1() << " (" << it->second.m_key.latin1() << ")" << std::endl; it->second.dump_tree(level + 1); } } #endif }; typedef cacheEntry statusEntry; template inline cacheEntry::cacheEntry() : m_key(), m_isValid(false), m_content() { } template inline cacheEntry::cacheEntry(const QString &key) : m_key(key), m_isValid(false), m_content() { } template inline cacheEntry::cacheEntry(const cacheEntry &other) : m_key(other.m_key), m_isValid(other.m_isValid), m_content(other.m_content), m_subMap(other.m_subMap) { } template inline cacheEntry &cacheEntry::operator=(const cacheEntry &other) { m_key = other.m_key; m_isValid = other.m_isValid; m_content = other.m_content; m_subMap = other.m_subMap; return *this; } -template inline bool cacheEntry::find(QStringList &what, QList &t)const +template inline bool cacheEntry::find(QStringList &what, QList &t) const { if (what.empty()) { return false; } - citer it = m_subMap.find(what.at(0)); + const auto it = m_subMap.find(what.at(0)); if (it == m_subMap.end()) { return false; } if (what.count() == 1) { if (it->second.isValid()) { t.append(it->second.content()); } it->second.appendValidSub(t); return true; } what.erase(what.begin()); return it->second.find(what, t); } -template inline bool cacheEntry::find(QStringList &what)const +template inline bool cacheEntry::find(QStringList &what) const { if (what.isEmpty()) { return false; } - citer it = m_subMap.find(what.at(0)); + const auto it = m_subMap.find(what.at(0)); if (it == m_subMap.end()) { return false; } if (what.count() == 1) { return true; } what.erase(what.begin()); return it->second.find(what); } -template inline bool cacheEntry::findSingleValid(QStringList &what, C &t)const +template inline bool cacheEntry::findSingleValid(QStringList &what, C &t) const { if (what.isEmpty()) { return false; } - citer it = m_subMap.find(what.at(0)); + const auto it = m_subMap.find(what.at(0)); if (it == m_subMap.end()) { return false; } if (what.count() == 1) { t = it->second.content(); return it->second.isValid(); } what.erase(what.begin()); return it->second.findSingleValid(what, t); } -template inline bool cacheEntry::findSingleValid(QStringList &what, bool check_valid_subs)const +template inline bool cacheEntry::findSingleValid(QStringList &what, bool check_valid_subs) const { if (what.isEmpty()) { return false; } - citer it = m_subMap.find(what.at(0)); + const auto it = m_subMap.find(what.at(0)); if (it == m_subMap.end()) { return false; } if (what.count() == 1) { return it->second.isValid() || (check_valid_subs && it->second.hasValidSubs()); } what.erase(what.begin()); return it->second.findSingleValid(what, check_valid_subs); } -template inline void cacheEntry::appendValidSub(QList &t)const +template inline void cacheEntry::appendValidSub(QList &t) const { - citer it; - for (it = m_subMap.begin(); it != m_subMap.end(); ++it) { - if (it->second.isValid()) { - t.append(it->second.content()); + for (const auto &it : m_subMap) { + if (it.second.isValid()) { + t.append(it.second.content()); } - it->second.appendValidSub(t); + it.second.appendValidSub(t); } } template inline bool cacheEntry::deleteKey(QStringList &what, bool exact) { if (what.isEmpty()) { return true; } - iter it = m_subMap.find(what.at(0)); + const auto it = m_subMap.find(what.at(0)); if (it == m_subMap.end()) { return true; } bool caller_must_check = false; /* first stage - we are the one holding the right key */ if (what.count() == 1) { if (!exact || !it->second.hasValidSubs()) { m_subMap.erase(it); caller_must_check = true; } else { it->second.markInvalid(); } } else { /* otherwise go trough tree */ what.erase(what.begin()); bool b = it->second.deleteKey(what, exact); if (b && !it->second.hasValidSubs()) { m_subMap.erase(it); caller_must_check = true; } } return caller_must_check; } -template inline bool cacheEntry::hasValidSubs()const +template inline bool cacheEntry::hasValidSubs() const { - citer it; - for (it = m_subMap.begin(); it != m_subMap.end(); ++it) { - if (it->second.isValid() || it->second.hasValidSubs()) { + for (const auto &it : m_subMap) { + if (it.second.isValid() || it.second.hasValidSubs()) { return true; } } return false; } template inline void cacheEntry::insertKey(QStringList &what, const C &st) { if (what.isEmpty()) { return; } const QString m = what.at(0); if (m_subMap.find(m) == m_subMap.end()) { m_subMap[m].m_key = m; } if (what.count() == 1) { m_subMap[m].setValidContent(m, st); return; } what.erase(what.begin()); m_subMap[m].insertKey(what, st); } -template template inline void cacheEntry::listsubs_if(QStringList &what, T &oper)const +template template inline void cacheEntry::listsubs_if(QStringList &what, T &oper) const { if (what.isEmpty()) { /* we are the one to get the list for*/ oper = for_each(m_subMap.begin(), m_subMap.end(), oper); return; } /* otherwise find next */ - citer it = m_subMap.find(what.at(0)); + const auto it = m_subMap.find(what.at(0)); if (it == m_subMap.end()) { /* not found */ return; } what.erase(what.begin()); it->second.listsubs_if(what, oper); } template class itemCache { public: typedef cacheEntry cache_type; typedef typename std::map cache_map_type; - typedef typename cache_map_type::const_iterator citer; - typedef typename cache_map_type::iterator iter; protected: cache_map_type m_contentMap; mutable QReadWriteLock m_RWLock; public: - itemCache(): m_contentMap(), m_RWLock() {} - virtual ~itemCache() {} + itemCache() = default; + virtual ~itemCache() = default; void clear() { QWriteLocker locker(&m_RWLock); m_contentMap.clear(); } //! Checks if cache contains a specific item /*! * the keylist will manipulated - so copy-operations aren't needed. * \param what Stringlist containing the components to search for * \return true if found (may or may not valid!) otherwise false */ virtual bool find(const QString &what)const; virtual void deleteKey(const QString &what, bool exact); virtual void insertKey(const C &, const QString &path); virtual bool findSingleValid(const QString &what, C &)const; virtual bool findSingleValid(const QString &what, bool check_valid_subs)const; templatevoid listsubs_if(const QString &what, T &oper)const; void dump_tree(); }; template inline void itemCache::insertKey(const C &st, const QString &path) { QStringList _keys = path.split(QLatin1Char('/')); if (_keys.isEmpty()) { return; } QWriteLocker locker(&m_RWLock); - const QString m = _keys.at(0); - citer it = m_contentMap.find(m); + const QString &m = _keys.at(0); + const auto it = m_contentMap.find(m); if (it == m_contentMap.end()) { m_contentMap[m] = cache_type(m); } if (_keys.count() == 1) { m_contentMap[m].setValidContent(m, st); } else { _keys.erase(_keys.begin()); m_contentMap[m].insertKey(_keys, st); } } template inline bool itemCache::find(const QString &what)const { QReadLocker locker(&m_RWLock); if (m_contentMap.empty()) { return false; } QStringList _keys = what.split(QLatin1Char('/')); if (_keys.isEmpty()) { return false; } - citer it = m_contentMap.find(_keys.at(0)); + const auto it = m_contentMap.find(_keys.at(0)); if (it == m_contentMap.end()) { return false; } if (_keys.count() == 1) { return true; } _keys.erase(_keys.begin()); return it->second.find(_keys); } template inline void itemCache::deleteKey(const QString &_what, bool exact) { QWriteLocker locker(&m_RWLock); if (m_contentMap.empty()) { return; } QStringList what = _what.split(QLatin1Char('/')); if (what.isEmpty()) { return; } - iter it = m_contentMap.find(what.at(0)); + const auto it = m_contentMap.find(what.at(0)); if (it == m_contentMap.end()) { return; } /* first stage - we are the one holding the right key */ if (what.count() == 1) { if (!exact || !it->second.hasValidSubs()) { /* if it has no valid subs delete it */ m_contentMap.erase(it); } else { /* otherwise mark as invalid */ it->second.markInvalid(); } return; } else { /* otherwise go trough tree */ what.erase(what.begin()); bool b = it->second.deleteKey(what, exact); if (b && !it->second.hasValidSubs()) { m_contentMap.erase(it); } } } template inline void itemCache::dump_tree() { QReadLocker locker(&m_RWLock); - citer it; - for (it = m_contentMap.begin(); it != m_contentMap.end(); ++it) { + for (auto it = m_contentMap.begin(); it != m_contentMap.end(); ++it) { // std::cout<first.latin1() << " (" << it->second.key().latin1() << ")"<second.dump_tree(1); } } template inline bool itemCache::findSingleValid(const QString &_what, C &st)const { QReadLocker locker(&m_RWLock); if (m_contentMap.empty()) { return false; } QStringList what = _what.split(QLatin1Char('/')); if (what.isEmpty()) { return false; } - citer it = m_contentMap.find(what.at(0)); + const auto it = m_contentMap.find(what.at(0)); if (it == m_contentMap.end()) { return false; } if (what.count() == 1) { if (it->second.isValid()) { st = it->second.content(); return true; } return false; } what.erase(what.begin()); return it->second.findSingleValid(what, st); } template inline bool itemCache::findSingleValid(const QString &_what, bool check_valid_subs)const { QReadLocker locker(&m_RWLock); if (m_contentMap.empty()) { return false; } QStringList what = _what.split(QLatin1Char('/')); if (what.isEmpty()) { return false; } - citer it = m_contentMap.find(what.at(0)); + const auto it = m_contentMap.find(what.at(0)); if (it == m_contentMap.end()) { return false; } if (what.count() == 1) { return it->second.isValid() || (check_valid_subs && it->second.hasValidSubs()); } what.erase(what.begin()); return it->second.findSingleValid(what, check_valid_subs); } template template inline void itemCache::listsubs_if(const QString &_what, T &oper)const { QReadLocker locker(&m_RWLock); if (m_contentMap.empty()) { return; } QStringList what = _what.split(QLatin1Char('/')); if (what.isEmpty()) { return; } - citer it = m_contentMap.find(what.at(0)); - + const auto it = m_contentMap.find(what.at(0)); if (it == m_contentMap.end()) { return; } if (what.count() == 1) { oper = for_each(m_contentMap.begin(), m_contentMap.end(), oper); return; } what.erase(what.begin()); it->second.listsubs_if(what, oper); } typedef cacheEntry ptrEntry; typedef itemCache statusCache; class ValidRemoteOnly { svn::StatusEntries m_List; public: ValidRemoteOnly(): m_List() {} void operator()(const std::pair &_data) { if (_data.second.isValid() && _data.second.content()->validReposStatus() && !_data.second.content()->validLocalStatus()) { m_List.push_back(_data.second.content()); } } const svn::StatusEntries &liste()const { return m_List; } }; } #endif