forked from qt-creator/qt-creator
Bookmarks: Some general code cleanup
Change-Id: Ibaba24af685d733bc3a488b82f2af5212f7ac35d Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -169,33 +169,6 @@ void BookmarkDelegate::paint(QPainter *painter, const QStyleOptionViewItem &opti
|
||||
0.7 * textColor.greenF() + 0.3 * backgroundColor.greenF(),
|
||||
0.7 * textColor.blueF() + 0.3 * backgroundColor.blueF());
|
||||
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();
|
||||
if (lineText.isEmpty())
|
||||
@@ -514,7 +487,7 @@ void BookmarkManager::deleteBookmark(Bookmark *bookmark)
|
||||
Bookmark *BookmarkManager::bookmarkForIndex(const QModelIndex &index) const
|
||||
{
|
||||
if (!index.isValid() || index.row() >= m_bookmarksList.size())
|
||||
return 0;
|
||||
return nullptr;
|
||||
return m_bookmarksList.at(index.row());
|
||||
}
|
||||
|
||||
|
@@ -51,7 +51,7 @@ class BookmarkManager : public QAbstractItemModel
|
||||
|
||||
public:
|
||||
BookmarkManager();
|
||||
~BookmarkManager();
|
||||
~BookmarkManager() final;
|
||||
|
||||
void updateBookmark(Bookmark *bookmark);
|
||||
void updateBookmarkFileName(Bookmark *bookmark, const QString &oldFileName);
|
||||
@@ -63,16 +63,16 @@ public:
|
||||
State state() const;
|
||||
|
||||
// Model stuff
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
|
||||
QModelIndex parent(const QModelIndex &child) const;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const;
|
||||
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const final;
|
||||
QModelIndex parent(const QModelIndex &child) const final;
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const final;
|
||||
int columnCount(const QModelIndex &parent = QModelIndex()) const final;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const final;
|
||||
Qt::ItemFlags flags(const QModelIndex &index) const final;
|
||||
|
||||
Qt::DropActions supportedDragActions() const;
|
||||
QStringList mimeTypes() const;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const;
|
||||
Qt::DropActions supportedDragActions() const final;
|
||||
QStringList mimeTypes() const final;
|
||||
QMimeData *mimeData(const QModelIndexList &indexes) const final;
|
||||
|
||||
// this QItemSelectionModel is shared by all views
|
||||
QItemSelectionModel *selectionModel() const;
|
||||
@@ -128,7 +128,7 @@ class BookmarkView : public Utils::ListView
|
||||
|
||||
public:
|
||||
explicit BookmarkView(BookmarkManager *manager);
|
||||
~BookmarkView();
|
||||
~BookmarkView() final;
|
||||
|
||||
QList<QToolButton *> createToolBarWidgets() const;
|
||||
|
||||
@@ -140,9 +140,9 @@ protected slots:
|
||||
void removeAll();
|
||||
|
||||
protected:
|
||||
void contextMenuEvent(QContextMenuEvent *event);
|
||||
void contextMenuEvent(QContextMenuEvent *event) final;
|
||||
void removeBookmark(const QModelIndex &index);
|
||||
void keyPressEvent(QKeyEvent *event);
|
||||
void keyPressEvent(QKeyEvent *event) final;
|
||||
|
||||
private:
|
||||
Core::IContext *m_bookmarkContext;
|
||||
@@ -168,11 +168,11 @@ class BookmarkDelegate : public QStyledItemDelegate
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
BookmarkDelegate(QObject *parent = 0);
|
||||
BookmarkDelegate(QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
QSize sizeHint(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 final;
|
||||
void generateGradientPixmap(int width, int height, const QColor &color, bool selected) const;
|
||||
|
||||
mutable QPixmap m_normalPixmap;
|
||||
|
@@ -141,7 +141,7 @@ BookmarksPluginRunData::BookmarksPluginRunData()
|
||||
editorManagerContext);
|
||||
mbm->addAction(cmd);
|
||||
|
||||
connect(&m_toggleAction, &QAction::triggered, [this] {
|
||||
connect(&m_toggleAction, &QAction::triggered, this, [this] {
|
||||
BaseTextEditor *editor = BaseTextEditor::currentTextEditor();
|
||||
if (editor && !editor->document()->isTemporary())
|
||||
m_bookmarkManager.toggleBookmark(editor->document()->filePath(), editor->currentLine());
|
||||
@@ -154,7 +154,7 @@ BookmarksPluginRunData::BookmarksPluginRunData()
|
||||
connect(&m_docNextAction, &QAction::triggered,
|
||||
&m_bookmarkManager, &BookmarkManager::nextInDocument);
|
||||
|
||||
connect(&m_editBookmarkAction, &QAction::triggered, [this] {
|
||||
connect(&m_editBookmarkAction, &QAction::triggered, this, [this] {
|
||||
m_bookmarkManager.editByFileAndLine(m_marginActionFileName, m_marginActionLineNumber);
|
||||
});
|
||||
|
||||
@@ -162,7 +162,7 @@ BookmarksPluginRunData::BookmarksPluginRunData()
|
||||
this, &BookmarksPluginRunData::updateActions);
|
||||
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);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user