2011-10-25 23:14:27 +03:00
|
|
|
/**************************************************************************
|
|
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 Dmitry Savchenko
|
|
|
|
|
** Copyright (C) 2015 Vasiliy Sorokin
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2011-10-25 23:14:27 +03:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2011-10-25 23:14:27 +03:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2012-02-14 22:43:26 +04:00
|
|
|
#include "todooutputpane.h"
|
2011-10-25 23:14:27 +03:00
|
|
|
#include "constants.h"
|
2012-02-24 09:43:52 +01:00
|
|
|
#include "todoitemsmodel.h"
|
2012-12-13 07:16:25 +04:00
|
|
|
#include "todooutputtreeview.h"
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2012-02-14 22:43:26 +04:00
|
|
|
#include <QIcon>
|
2011-10-25 23:14:27 +03:00
|
|
|
#include <QHeaderView>
|
2012-02-24 09:43:52 +01:00
|
|
|
#include <QToolButton>
|
|
|
|
|
#include <QButtonGroup>
|
2012-02-14 22:43:26 +04:00
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
namespace Todo {
|
|
|
|
|
namespace Internal {
|
2012-02-14 22:43:26 +04:00
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
TodoOutputPane::TodoOutputPane(TodoItemsModel *todoItemsModel, QObject *parent) :
|
|
|
|
|
IOutputPane(parent),
|
|
|
|
|
m_todoItemsModel(todoItemsModel)
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
createTreeView();
|
|
|
|
|
createScopeButtons();
|
|
|
|
|
setScanningScope(ScanningScopeCurrentFile); // default
|
2015-01-29 10:42:16 +01:00
|
|
|
connect(m_todoItemsModel, &TodoItemsModel::layoutChanged,
|
|
|
|
|
this, &TodoOutputPane::navigateStateUpdate);
|
|
|
|
|
connect(m_todoItemsModel, &TodoItemsModel::layoutChanged,
|
|
|
|
|
this, &TodoOutputPane::updateTodoCount);
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TodoOutputPane::~TodoOutputPane()
|
|
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
freeTreeView();
|
|
|
|
|
freeScopeButtons();
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
QWidget *TodoOutputPane::outputWidget(QWidget *parent)
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
Q_UNUSED(parent)
|
|
|
|
|
return m_todoTreeView;
|
|
|
|
|
}
|
2012-02-14 22:43:26 +04:00
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
QList<QWidget*> TodoOutputPane::toolBarWidgets() const
|
|
|
|
|
{
|
|
|
|
|
return QList<QWidget*>()
|
|
|
|
|
<< m_spacer
|
|
|
|
|
<< m_currentFileButton
|
2015-05-30 08:54:39 +02:00
|
|
|
<< m_wholeProjectButton
|
|
|
|
|
<< m_subProjectButton;
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
2012-02-14 22:43:26 +04:00
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
QString TodoOutputPane::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return tr(Constants::OUTPUT_PANE_TITLE);
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
int TodoOutputPane::priorityInStatusBar() const
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
return 1;
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::clearContents()
|
|
|
|
|
{
|
|
|
|
|
}
|
2012-02-14 22:43:26 +04:00
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::visibilityChanged(bool visible)
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
Q_UNUSED(visible)
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::setFocus()
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
m_todoTreeView->setFocus();
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
bool TodoOutputPane::hasFocus() const
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2014-11-07 15:48:36 +01:00
|
|
|
return m_todoTreeView->window()->focusWidget() == m_todoTreeView;
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
bool TodoOutputPane::canFocus() const
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
return true;
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
bool TodoOutputPane::canNavigate() const
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
return true;
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
bool TodoOutputPane::canNext() const
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
return m_todoTreeView->model()->rowCount() > 1;
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
bool TodoOutputPane::canPrevious() const
|
|
|
|
|
{
|
|
|
|
|
return m_todoTreeView->model()->rowCount() > 1;
|
|
|
|
|
}
|
2012-02-14 22:43:26 +04:00
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::goToNext()
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2013-12-03 11:01:46 +02:00
|
|
|
const QModelIndex nextIndex = nextModelIndex();
|
|
|
|
|
m_todoTreeView->selectionModel()->setCurrentIndex(nextIndex, QItemSelectionModel::SelectCurrent
|
|
|
|
|
| QItemSelectionModel::Rows);
|
|
|
|
|
todoTreeViewClicked(nextIndex);
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::goToPrev()
|
|
|
|
|
{
|
2013-12-03 11:01:46 +02:00
|
|
|
const QModelIndex prevIndex = previousModelIndex();
|
|
|
|
|
m_todoTreeView->selectionModel()->setCurrentIndex(prevIndex, QItemSelectionModel::SelectCurrent
|
|
|
|
|
| QItemSelectionModel::Rows);
|
|
|
|
|
todoTreeViewClicked(prevIndex);
|
2011-10-25 23:14:27 +03:00
|
|
|
}
|
2012-02-14 22:43:26 +04:00
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::setScanningScope(ScanningScope scanningScope)
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
if (scanningScope == ScanningScopeCurrentFile)
|
|
|
|
|
m_currentFileButton->setChecked(true);
|
2015-05-30 08:54:39 +02:00
|
|
|
else if (scanningScope == ScanningScopeSubProject)
|
|
|
|
|
m_subProjectButton->setChecked(true);
|
2011-10-25 23:14:27 +03:00
|
|
|
else if (scanningScope == ScanningScopeProject)
|
|
|
|
|
m_wholeProjectButton->setChecked(true);
|
|
|
|
|
else
|
|
|
|
|
Q_ASSERT_X(false, "Updating scanning scope buttons", "Unknown scanning scope enum value");
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::scopeButtonClicked(QAbstractButton* button)
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
if (button == m_currentFileButton)
|
|
|
|
|
emit scanningScopeChanged(ScanningScopeCurrentFile);
|
2015-05-30 08:54:39 +02:00
|
|
|
else if (button == m_subProjectButton)
|
|
|
|
|
emit scanningScopeChanged(ScanningScopeSubProject);
|
2011-10-25 23:14:27 +03:00
|
|
|
else if (button == m_wholeProjectButton)
|
|
|
|
|
emit scanningScopeChanged(ScanningScopeProject);
|
2012-06-14 16:33:10 +02:00
|
|
|
setBadgeNumber(m_todoItemsModel->rowCount());
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2012-02-24 09:43:52 +01:00
|
|
|
void TodoOutputPane::todoTreeViewClicked(const QModelIndex &index)
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
// Create a to-do item and notify that it was clicked on
|
|
|
|
|
|
|
|
|
|
int row = index.row();
|
|
|
|
|
|
|
|
|
|
TodoItem item;
|
|
|
|
|
item.text = index.sibling(row, Constants::OUTPUT_COLUMN_TEXT).data().toString();
|
|
|
|
|
item.file = index.sibling(row, Constants::OUTPUT_COLUMN_FILE).data().toString();
|
|
|
|
|
item.line = index.sibling(row, Constants::OUTPUT_COLUMN_LINE).data().toInt();
|
|
|
|
|
item.color = index.data(Qt::BackgroundColorRole).value<QColor>();
|
|
|
|
|
item.iconResource = index.sibling(row, Constants::OUTPUT_COLUMN_TEXT).data(Qt::DecorationRole).toString();
|
|
|
|
|
|
|
|
|
|
emit todoItemClicked(item);
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2012-06-14 16:33:10 +02:00
|
|
|
void TodoOutputPane::updateTodoCount()
|
|
|
|
|
{
|
|
|
|
|
setBadgeNumber(m_todoItemsModel->rowCount());
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::createTreeView()
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2012-12-13 07:16:25 +04:00
|
|
|
m_todoTreeView = new TodoOutputTreeView();
|
2011-10-25 23:14:27 +03:00
|
|
|
m_todoTreeView->setModel(m_todoItemsModel);
|
|
|
|
|
|
2015-01-29 10:42:16 +01:00
|
|
|
connect(m_todoTreeView, &TodoOutputTreeView::activated, this, &TodoOutputPane::todoTreeViewClicked);
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::freeTreeView()
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
delete m_todoTreeView;
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::createScopeButtons()
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
m_currentFileButton = new QToolButton();
|
|
|
|
|
m_currentFileButton->setCheckable(true);
|
2013-12-09 09:06:12 +01:00
|
|
|
m_currentFileButton->setText(tr("Current Document"));
|
|
|
|
|
m_currentFileButton->setToolTip(tr("Scan only the currently edited document."));
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
m_wholeProjectButton = new QToolButton();
|
|
|
|
|
m_wholeProjectButton->setCheckable(true);
|
2013-12-09 09:06:12 +01:00
|
|
|
m_wholeProjectButton->setText(tr("Active Project"));
|
|
|
|
|
m_wholeProjectButton->setToolTip(tr("Scan the whole active project."));
|
2011-10-25 23:14:27 +03:00
|
|
|
|
2015-05-30 08:54:39 +02:00
|
|
|
m_subProjectButton = new QToolButton();
|
|
|
|
|
m_subProjectButton->setCheckable(true);
|
|
|
|
|
m_subProjectButton->setText(tr("Subproject"));
|
|
|
|
|
m_subProjectButton->setToolTip(tr("Scan the current subproject."));
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
m_scopeButtons = new QButtonGroup();
|
|
|
|
|
m_scopeButtons->addButton(m_wholeProjectButton);
|
|
|
|
|
m_scopeButtons->addButton(m_currentFileButton);
|
2015-05-30 08:54:39 +02:00
|
|
|
m_scopeButtons->addButton(m_subProjectButton);
|
2015-01-29 10:42:16 +01:00
|
|
|
connect(m_scopeButtons, static_cast<void (QButtonGroup::*)(QAbstractButton *)>(&QButtonGroup::buttonClicked),
|
|
|
|
|
this, &TodoOutputPane::scopeButtonClicked);
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
m_spacer = new QWidget;
|
2012-02-24 09:43:52 +01:00
|
|
|
m_spacer->setMinimumWidth(Constants::OUTPUT_TOOLBAR_SPACER_WIDTH);
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
void TodoOutputPane::freeScopeButtons()
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
delete m_currentFileButton;
|
|
|
|
|
delete m_wholeProjectButton;
|
2015-05-30 08:54:39 +02:00
|
|
|
delete m_subProjectButton;
|
2011-10-25 23:14:27 +03:00
|
|
|
delete m_scopeButtons;
|
|
|
|
|
delete m_spacer;
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
QModelIndex TodoOutputPane::selectedModelIndex()
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
QModelIndexList selectedIndexes = m_todoTreeView->selectionModel()->selectedIndexes();
|
|
|
|
|
if (selectedIndexes.isEmpty())
|
|
|
|
|
return QModelIndex();
|
|
|
|
|
else
|
|
|
|
|
// There is only one item selected
|
|
|
|
|
return selectedIndexes.first();
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
QModelIndex TodoOutputPane::nextModelIndex()
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
QModelIndex indexToBeSelected = m_todoTreeView->indexBelow(selectedModelIndex());
|
|
|
|
|
if (!indexToBeSelected.isValid())
|
|
|
|
|
return m_todoTreeView->model()->index(0, 0);
|
|
|
|
|
else
|
|
|
|
|
return indexToBeSelected;
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
2011-10-25 23:14:27 +03:00
|
|
|
QModelIndex TodoOutputPane::previousModelIndex()
|
2012-02-14 22:43:26 +04:00
|
|
|
{
|
2011-10-25 23:14:27 +03:00
|
|
|
QModelIndex indexToBeSelected = m_todoTreeView->indexAbove(selectedModelIndex());
|
|
|
|
|
if (!indexToBeSelected.isValid())
|
|
|
|
|
return m_todoTreeView->model()->index(m_todoTreeView->model()->rowCount() - 1, 0);
|
|
|
|
|
else
|
|
|
|
|
return indexToBeSelected;
|
2012-02-14 22:43:26 +04:00
|
|
|
}
|
2011-10-25 23:14:27 +03:00
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Todo
|