Bookmarks: Some general code cleanup

Change-Id: Ibaba24af685d733bc3a488b82f2af5212f7ac35d
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2018-05-02 11:59:37 +02:00
parent 436967ebf0
commit eca2f5da53
3 changed files with 20 additions and 47 deletions

View File

@@ -169,33 +169,6 @@ void BookmarkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
0.7 * textColor.greenF() + 0.3 * backgroundColor.greenF(), 0.7 * textColor.greenF() + 0.3 * backgroundColor.greenF(),
0.7 * textColor.blueF() + 0.3 * backgroundColor.blueF()); 0.7 * textColor.blueF() + 0.3 * backgroundColor.blueF());
painter->setPen(mix); painter->setPen(mix);
//
// QString directory = index.data(BookmarkManager::Directory).toString();
// int availableSpace = opt.rect.width() - 12;
// if (fm.width(directory) > availableSpace) {
// // We need a shorter directory
// availableSpace -= fm.width("...");
//
// int pos = directory.size();
// int idx;
// forever {
// idx = directory.lastIndexOf("/", pos-1);
// if (idx == -1) {
// // Can't happen, this means the string did fit after all?
// break;
// }
// int width = fm.width(directory.mid(idx, pos-idx));
// if (width > availableSpace) {
// directory = "..." + directory.mid(pos);
// break;
// } else {
// pos = idx;
// availableSpace -= width;
// }
// }
// }
//
// painter->drawText(3, opt.rect.top() + fm.ascent() + fm.height() + 6, directory);
QString lineText = index.data(BookmarkManager::Note).toString().trimmed(); QString lineText = index.data(BookmarkManager::Note).toString().trimmed();
if (lineText.isEmpty()) if (lineText.isEmpty())
@@ -514,7 +487,7 @@ void BookmarkManager::deleteBookmark(Bookmark *bookmark)
Bookmark *BookmarkManager::bookmarkForIndex(const QModelIndex &index) const Bookmark *BookmarkManager::bookmarkForIndex(const QModelIndex &index) const
{ {
if (!index.isValid() || index.row() >= m_bookmarksList.size()) if (!index.isValid() || index.row() >= m_bookmarksList.size())
return 0; return nullptr;
return m_bookmarksList.at(index.row()); return m_bookmarksList.at(index.row());
} }

View File

@@ -51,7 +51,7 @@ class BookmarkManager : public QAbstractItemModel
public: public:
BookmarkManager(); BookmarkManager();
~BookmarkManager(); ~BookmarkManager() final;
void updateBookmark(Bookmark *bookmark); void updateBookmark(Bookmark *bookmark);
void updateBookmarkFileName(Bookmark *bookmark, const QString &oldFileName); void updateBookmarkFileName(Bookmark *bookmark, const QString &oldFileName);
@@ -63,16 +63,16 @@ public:
State state() const; State state() const;
// Model stuff // Model stuff
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const final;
QModelIndex parent(const QModelIndex &child) const; QModelIndex parent(const QModelIndex &child) const final;
int rowCount(const QModelIndex &parent = QModelIndex()) const; int rowCount(const QModelIndex &parent = QModelIndex()) const final;
int columnCount(const QModelIndex &parent = QModelIndex()) const; int columnCount(const QModelIndex &parent = QModelIndex()) const final;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const final;
Qt::ItemFlags flags(const QModelIndex &index) const; Qt::ItemFlags flags(const QModelIndex &index) const final;
Qt::DropActions supportedDragActions() const; Qt::DropActions supportedDragActions() const final;
QStringList mimeTypes() const; QStringList mimeTypes() const final;
QMimeData *mimeData(const QModelIndexList &indexes) const; QMimeData *mimeData(const QModelIndexList &indexes) const final;
// this QItemSelectionModel is shared by all views // this QItemSelectionModel is shared by all views
QItemSelectionModel *selectionModel() const; QItemSelectionModel *selectionModel() const;
@@ -128,7 +128,7 @@ class BookmarkView : public Utils::ListView
public: public:
explicit BookmarkView(BookmarkManager *manager); explicit BookmarkView(BookmarkManager *manager);
~BookmarkView(); ~BookmarkView() final;
QList<QToolButton *> createToolBarWidgets() const; QList<QToolButton *> createToolBarWidgets() const;
@@ -140,9 +140,9 @@ protected slots:
void removeAll(); void removeAll();
protected: protected:
void contextMenuEvent(QContextMenuEvent *event); void contextMenuEvent(QContextMenuEvent *event) final;
void removeBookmark(const QModelIndex &index); void removeBookmark(const QModelIndex &index);
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event) final;
private: private:
Core::IContext *m_bookmarkContext; Core::IContext *m_bookmarkContext;
@@ -168,11 +168,11 @@ class BookmarkDelegate : public QStyledItemDelegate
Q_OBJECT Q_OBJECT
public: public:
BookmarkDelegate(QObject *parent = 0); BookmarkDelegate(QObject *parent = nullptr);
private: private:
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const final;
QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const final;
void generateGradientPixmap(int width, int height, const QColor &color, bool selected) const; void generateGradientPixmap(int width, int height, const QColor &color, bool selected) const;
mutable QPixmap m_normalPixmap; mutable QPixmap m_normalPixmap;

View File

@@ -141,7 +141,7 @@ BookmarksPluginRunData::BookmarksPluginRunData()
editorManagerContext); editorManagerContext);
mbm->addAction(cmd); mbm->addAction(cmd);
connect(&m_toggleAction, &QAction::triggered, [this] { connect(&m_toggleAction, &QAction::triggered, this, [this] {
BaseTextEditor *editor = BaseTextEditor::currentTextEditor(); BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
if (editor && !editor->document()->isTemporary()) if (editor && !editor->document()->isTemporary())
m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine()); m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine());
@@ -154,7 +154,7 @@ BookmarksPluginRunData::BookmarksPluginRunData()
connect(&m_docNextAction, &QAction::triggered, connect(&m_docNextAction, &QAction::triggered,
&m_bookmarkManager, &BookmarkManager::nextInDocument); &m_bookmarkManager, &BookmarkManager::nextInDocument);
connect(&m_editBookmarkAction, &QAction::triggered, [this] { connect(&m_editBookmarkAction, &QAction::triggered, this, [this] {
m_bookmarkManager.editByFileAndLine(m_marginActionFileName, m_marginActionLineNumber); m_bookmarkManager.editByFileAndLine(m_marginActionFileName, m_marginActionLineNumber);
}); });
@@ -162,7 +162,7 @@ BookmarksPluginRunData::BookmarksPluginRunData()
this, &BookmarksPluginRunData::updateActions); this, &BookmarksPluginRunData::updateActions);
updateActions(false, m_bookmarkManager.state()); updateActions(false, m_bookmarkManager.state());
connect(&m_bookmarkMarginAction, &QAction::triggered, [this] { connect(&m_bookmarkMarginAction, &QAction::triggered, this, [this] {
m_bookmarkManager.toggleBookmark(m_marginActionFileName, m_marginActionLineNumber); m_bookmarkManager.toggleBookmark(m_marginActionFileName, m_marginActionLineNumber);
}); });