Initial import

This commit is contained in:
con
2008-12-02 12:01:29 +01:00
commit 05c35356ab
1675 changed files with 229938 additions and 0 deletions

View File

@@ -0,0 +1,167 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "futureprogress.h"
#include "progresspie.h"
#include <QtGui/QColor>
#include <QtGui/QVBoxLayout>
#include <QtGui/QMenu>
using namespace Core;
FutureProgress::FutureProgress(QWidget *parent)
: QWidget(parent),
m_progress(new ProgressBar),
m_widget(0),
m_widgetLayout(new QHBoxLayout)
{
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
layout->addWidget(m_progress);
layout->setMargin(0);
layout->setSpacing(0);
layout->addLayout(m_widgetLayout);
m_widgetLayout->setContentsMargins(7, 0, 7, 0);
m_widgetLayout->setSpacing(0);
connect(&m_watcher, SIGNAL(started()), this, SLOT(setStarted()));
connect(&m_watcher, SIGNAL(finished()), this, SLOT(setFinished()));
connect(&m_watcher, SIGNAL(progressRangeChanged(int,int)), this, SLOT(setProgressRange(int,int)));
connect(&m_watcher, SIGNAL(progressValueChanged(int)), this, SLOT(setProgressValue(int)));
connect(&m_watcher, SIGNAL(progressTextChanged(const QString&)),
this, SLOT(setProgressText(const QString&)));
connect(m_progress, SIGNAL(clicked()), this, SLOT(cancel()));
}
FutureProgress::~FutureProgress()
{
if (m_widget)
delete m_widget;
}
void FutureProgress::setWidget(QWidget *widget)
{
if (m_widget)
delete m_widget;
QSizePolicy sp = widget->sizePolicy();
sp.setHorizontalPolicy(QSizePolicy::Ignored);
widget->setSizePolicy(sp);
m_widget = widget;
if (m_widget)
m_widgetLayout->addWidget(m_widget);
}
void FutureProgress::setTitle(const QString &title)
{
m_progress->setTitle(title);
}
QString FutureProgress::title() const
{
return m_progress->title();
}
void FutureProgress::cancel()
{
m_watcher.future().cancel();
}
void FutureProgress::setStarted()
{
m_progress->reset();
m_progress->setError(false);
m_progress->setRange(m_watcher.progressMinimum(), m_watcher.progressMaximum());
m_progress->setValue(m_watcher.progressValue());
// if (m_watcher.progressMinimum() == 0 && m_watcher.progressMaximum() == 0)
// m_progress->startAnimation();
}
void FutureProgress::setFinished()
{
// m_progress->stopAnimation();
setToolTip(m_watcher.future().progressText());
if (m_watcher.future().isCanceled()) {
m_progress->setError(true);
// m_progress->execGlowOut(true);
} else {
m_progress->setError(false);
// m_progress->execGlowOut(false);
}
// m_progress->showToolTip();
emit finished();
}
void FutureProgress::setProgressRange(int min, int max)
{
m_progress->setRange(min, max);
if (min != 0 || max != 0) {
// m_progress->setUsingAnimation(false);
} else {
// m_progress->setUsingAnimation(true);
if (m_watcher.future().isRunning()) {
//m_progress->startAnimation();
}
}
}
void FutureProgress::setProgressValue(int val)
{
m_progress->setValue(val);
}
void FutureProgress::setProgressText(const QString &text)
{
setToolTip(text);
}
void FutureProgress::setFuture(const QFuture<void> &future)
{
m_watcher.setFuture(future);
}
QFuture<void> FutureProgress::future() const
{
return m_watcher.future();
}
void FutureProgress::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
emit clicked();
QWidget::mousePressEvent(event);
}
bool FutureProgress::hasError() const
{
return m_progress->hasError();
}

View File

@@ -0,0 +1,94 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef FUTUREPROGRESS_H
#define FUTUREPROGRESS_H
#include <coreplugin/core_global.h>
#include <QtCore/QString>
#include <QtCore/QFuture>
#include <QtCore/QFutureWatcher>
#include <QtGui/QWidget>
#include <QtGui/QIcon>
#include <QtGui/QAction>
#include <QtGui/QProgressBar>
#include <QtGui/QMouseEvent>
#include <QtGui/QHBoxLayout>
class ProgressBar;
namespace Core {
class CORE_EXPORT FutureProgress : public QWidget
{
Q_OBJECT
public:
FutureProgress(QWidget *parent = 0);
~FutureProgress();
void setFuture(const QFuture<void> &future);
QFuture<void> future() const;
void setTitle(const QString &title);
QString title() const;
bool hasError() const;
void setWidget(QWidget *widget);
QWidget *widget() const { return m_widget; }
signals:
void clicked();
void finished();
protected:
void mousePressEvent(QMouseEvent *event);
private slots:
void cancel();
void setStarted();
void setFinished();
void setProgressRange(int min, int max);
void setProgressValue(int val);
void setProgressText(const QString &text);
private:
QFutureWatcher<void> m_watcher;
ProgressBar *m_progress;
QWidget *m_widget;
QHBoxLayout *m_widgetLayout;
};
} // namespace Core
#endif // FUTUREPROGRESS_H

View File

@@ -0,0 +1,110 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "progressmanager.h"
#include "progressview.h"
#include "coreimpl.h"
#include "baseview.h"
#include "coreconstants.h"
#include "uniqueidmanager.h"
#include "viewmanagerinterface.h"
using namespace Core;
using namespace Core::Internal;
ProgressManager::ProgressManager(QObject *parent) :
ProgressManagerInterface(parent)
{
m_progressView = new ProgressView;
ICore *core = CoreImpl::instance();
connect(core, SIGNAL(coreAboutToClose()), this, SLOT(cancelAllRunningTasks()));
}
ProgressManager::~ProgressManager()
{
}
void ProgressManager::init()
{
}
void ProgressManager::cancelTasks(const QString &type)
{
QMap<QFutureWatcher<void> *, QString>::iterator task = m_runningTasks.begin();
while (task != m_runningTasks.end()) {
if (task.value() != type) {
++task;
continue;
}
disconnect(task.key(), SIGNAL(finished()), this, SLOT(taskFinished()));
task.key()->cancel();
delete task.key();
task = m_runningTasks.erase(task);
}
}
void ProgressManager::cancelAllRunningTasks()
{
QMap<QFutureWatcher<void> *, QString>::const_iterator task = m_runningTasks.constBegin();
while (task != m_runningTasks.constEnd()) {
disconnect(task.key(), SIGNAL(finished()), this, SLOT(taskFinished()));
task.key()->cancel();
delete task.key();
++task;
}
m_runningTasks.clear();
}
FutureProgress *ProgressManager::addTask(const QFuture<void> &future, const QString &title, const QString &type, PersistentType persistency)
{
QFutureWatcher<void> *watcher = new QFutureWatcher<void>();
m_runningTasks.insert(watcher, type);
connect(watcher, SIGNAL(finished()), this, SLOT(taskFinished()));
watcher->setFuture(future);
return m_progressView->addTask(future, title, type, persistency);
}
QWidget *ProgressManager::progressView()
{
return m_progressView;
}
void ProgressManager::taskFinished()
{
QObject *taskObject = sender();
Q_ASSERT(taskObject);
QFutureWatcher<void> *task = static_cast<QFutureWatcher<void> *>(taskObject);
m_runningTasks.remove(task);
delete task;
}

View File

@@ -0,0 +1,74 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef PROGRESSMANAGER_H
#define PROGRESSMANAGER_H
#include "progressmanagerinterface.h"
#include <QtCore/QPointer>
#include <QtCore/QList>
#include <QtCore/QFutureWatcher>
namespace Core {
namespace Internal {
class ProgressView;
class ProgressManager : public Core::ProgressManagerInterface
{
Q_OBJECT
public:
ProgressManager(QObject *parent = 0);
~ProgressManager();
void init();
FutureProgress *addTask(const QFuture<void> &future, const QString &title, const QString &type, PersistentType persistency);
QWidget *progressView();
public slots:
void cancelTasks(const QString &type);
private slots:
void taskFinished();
void cancelAllRunningTasks();
private:
QPointer<ProgressView> m_progressView;
QMap<QFutureWatcher<void> *, QString> m_runningTasks;
};
} // namespace Internal
} // namespace Core
#endif //PROGRESSMANAGER_H

View File

@@ -0,0 +1,62 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef PROGRESSMANAGERINTERFACE_H
#define PROGRESSMANAGERINTERFACE_H
#include <coreplugin/core_global.h>
#include <coreplugin/progressmanager/futureprogress.h>
#include <QtCore/QObject>
#include <QtCore/QFuture>
#include <QtGui/QIcon>
namespace Core {
class CORE_EXPORT ProgressManagerInterface : public QObject
{
Q_OBJECT
public:
enum PersistentType { CloseOnSuccess, KeepOnFinish };
ProgressManagerInterface(QObject *parent = 0) : QObject(parent) {}
virtual ~ProgressManagerInterface() {}
virtual FutureProgress *addTask(const QFuture<void> &future, const QString &title, const QString &type, PersistentType persistency = KeepOnFinish) = 0;
public slots:
virtual void cancelTasks(const QString &type) = 0;
};
} //namespace
#endif //PROGRESSMANAGERINTERFACE_H

View File

@@ -0,0 +1,166 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "progresspie.h"
#include "stylehelper.h"
#include <QtGui/QPainter>
#include <QtGui/QFont>
#include <QtGui/QBrush>
#include <QtGui/QColor>
#include <QtDebug>
ProgressBar::ProgressBar(QWidget *parent)
: QProgressBar(parent), m_error(false)
{
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
}
ProgressBar::~ProgressBar()
{
}
QString ProgressBar::title() const
{
return m_title;
}
bool ProgressBar::hasError() const
{
return m_error;
}
void ProgressBar::setTitle(const QString &title)
{
m_title = title;
}
void ProgressBar::setError(bool on)
{
m_error = on;
update();
}
QSize ProgressBar::sizeHint() const
{
QSize s;
s.setWidth(50);
s.setHeight(fontMetrics().height() * 2);
return s;
}
namespace { const int INDENT = 7; }
void ProgressBar::mousePressEvent(QMouseEvent *event)
{
if (event->modifiers() == Qt::NoModifier
&& event->x() >= size().width()-INDENT-m_progressHeight) {
event->accept();
emit clicked();
return;
}
QProgressBar::mousePressEvent(event);
}
void ProgressBar::paintEvent(QPaintEvent *)
{
// TODO move font into stylehelper
// TODO use stylehelper white
double range = maximum() - minimum();
double percent = 0.50;
if (range != 0)
percent = (value() - minimum()) / range;
if(percent > 1)
percent = 1;
else if(percent < 0)
percent = 0;
QPainter p(this);
QFont boldFont(p.font());
boldFont.setPointSizeF(StyleHelper::sidebarFontSize());
boldFont.setBold(true);
p.setFont(boldFont);
QFontMetrics fm(boldFont);
// Draw separator
int h = fm.height();
p.setPen(QColor(0, 0, 0, 70));
p.drawLine(0,0, size().width(), 0);
p.setPen(QColor(255, 255, 255, 70));
p.drawLine(0, 1, size().width(), 1);
p.setPen(StyleHelper::panelTextColor());
p.drawText(QPoint(7, h+1), m_title);
m_progressHeight = h-4;
m_progressHeight += ((m_progressHeight % 2) + 1) % 2; // make odd
// draw outer rect
QRect rect(INDENT, h+6, size().width()-2*INDENT-m_progressHeight+1, m_progressHeight-1);
p.setPen(StyleHelper::panelTextColor());
p.drawRect(rect);
// draw inner rect
QColor c = StyleHelper::panelTextColor();
c.setAlpha(180);
p.setPen(Qt::NoPen);
p.setBrush(c);
QRect inner = rect.adjusted(2, 2, -1, -1);
inner.adjust(0, 0, qRound((percent - 1) * inner.width()), 0);
if (m_error) {
// TODO this is not fancy enough
QColor red(255, 0, 0, 180);
p.setBrush(red);
// avoid too small red bar
if (inner.width() < 10)
inner.adjust(0, 0, 10 - inner.width(), 0);
} else if (value() == maximum()) {
QColor green(140, 255, 140, 180);
p.setBrush(green);
}
p.drawRect(inner);
if (value() < maximum() && !m_error) {
// draw cancel thingy
// TODO this is quite ugly at the moment
p.setPen(StyleHelper::panelTextColor());
p.setBrush(QBrush(Qt::NoBrush));
QRect cancelRect(size().width()-INDENT-m_progressHeight+3, h+6+1, m_progressHeight-3, m_progressHeight-3);
p.drawRect(cancelRect);
p.setPen(c);
p.drawLine(cancelRect.center()+QPoint(-1,-1), cancelRect.center()+QPoint(+3,+3));
p.drawLine(cancelRect.center()+QPoint(+3,-1), cancelRect.center()+QPoint(-1,+3));
}
}

View File

@@ -0,0 +1,69 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef PROGRESSPIE_H
#define PROGRESSPIE_H
#include <QtCore/QString>
#include <QtGui/QWidget>
#include <QtGui/QProgressBar>
#include <QtGui/QMouseEvent>
class ProgressBar : public QProgressBar
{
Q_OBJECT
public:
ProgressBar(QWidget *parent = 0);
~ProgressBar();
QString title() const;
void setTitle(const QString &title);
// TODO rename setError
void setError(bool on);
bool hasError() const;
QSize sizeHint() const;
void paintEvent(QPaintEvent *);
signals:
void clicked();
protected:
void mousePressEvent(QMouseEvent *event);
private:
QString m_text;
QString m_title;
bool m_error;
int m_progressHeight;
};
#endif // PROGRESSPIE_H

View File

@@ -0,0 +1,142 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#include "progressview.h"
#include "futureprogress.h"
#include <QtGui/QHBoxLayout>
using namespace Core;
using namespace Core::Internal;
ProgressView::ProgressView(QWidget *parent)
: QWidget(parent)
{
m_layout = new QVBoxLayout;
setLayout(m_layout);
m_layout->setMargin(0);
m_layout->setSpacing(0);
setWindowTitle(tr("Processes"));
}
ProgressView::~ProgressView()
{
qDeleteAll(m_taskList);
m_taskList.clear();
m_type.clear();
m_keep.clear();
}
FutureProgress *ProgressView::addTask(const QFuture<void> &future,
const QString &title,
const QString &type,
ProgressManagerInterface::PersistentType persistency)
{
removeOldTasks(type);
if (m_taskList.size() == 3)
removeOneOldTask();
FutureProgress *progress = new FutureProgress(this);
progress->setTitle(title);
progress->setFuture(future);
m_layout->insertWidget(0, progress);
m_taskList.append(progress);
m_type.insert(progress, type);
m_keep.insert(progress, (persistency == ProgressManagerInterface::KeepOnFinish));
connect(progress, SIGNAL(finished()), this, SLOT(slotFinished()));
return progress;
}
void ProgressView::removeOldTasks(const QString &type, bool keepOne)
{
bool firstFound = !keepOne; // start with false if we want to keep one
QList<FutureProgress *>::iterator i = m_taskList.end();
while (i != m_taskList.begin()) {
--i;
if (m_type.value(*i) == type) {
if (firstFound && (*i)->future().isFinished()) {
deleteTask(*i);
i = m_taskList.erase(i);
}
firstFound = true;
}
}
}
void ProgressView::deleteTask(FutureProgress *progress)
{
m_type.remove(progress);
m_keep.remove(progress);
layout()->removeWidget(progress);
progress->deleteLater();
}
void ProgressView::removeOneOldTask()
{
if (m_taskList.isEmpty())
return;
// look for oldest ended process
for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
if ((*i)->future().isFinished()) {
deleteTask(*i);
i = m_taskList.erase(i);
return;
}
}
// no ended process, look for a task type with multiple running tasks and remove the oldest one
for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
QString type = m_type.value(*i);
if (m_type.keys(type).size() > 1) { // don't care for optimizations it's only a handful of entries
deleteTask(*i);
i = m_taskList.erase(i);
return;
}
}
// no ended process, no type with multiple processes, just remove the oldest task
FutureProgress *task = m_taskList.takeFirst();
deleteTask(task);
}
void ProgressView::removeTask(FutureProgress *task)
{
m_taskList.removeAll(task);
deleteTask(task);
}
void ProgressView::slotFinished()
{
FutureProgress *progress = qobject_cast<FutureProgress *>(sender());
Q_ASSERT(progress);
if (m_keep.contains(progress) && !m_keep.value(progress) && !progress->hasError())
removeTask(progress);
removeOldTasks(m_type.value(progress), true);
}

View File

@@ -0,0 +1,81 @@
/***************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Qt Software Information (qt-info@nokia.com)
**
**
** Non-Open Source Usage
**
** Licensees may use this file in accordance with the Qt Beta Version
** License Agreement, Agreement version 2.2 provided with the Software or,
** alternatively, in accordance with the terms contained in a written
** agreement between you and Nokia.
**
** GNU General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU General
** Public License versions 2.0 or 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the packaging
** of this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
**
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
** http://www.gnu.org/copyleft/gpl.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt GPL Exception version
** 1.2, included in the file GPL_EXCEPTION.txt in this package.
**
***************************************************************************/
#ifndef PROGRESSVIEW_H
#define PROGRESSVIEW_H
#include "progressmanagerinterface.h"
#include <QtCore/QFuture>
#include <QtGui/QWidget>
#include <QtGui/QIcon>
#include <QtGui/QVBoxLayout>
namespace Core {
class FutureProgress;
namespace Internal {
class ProgressView : public QWidget
{
Q_OBJECT
public:
ProgressView(QWidget *parent = 0);
~ProgressView();
/** The returned FutureProgress instance is guaranteed to live till next main loop event processing (deleteLater). */
FutureProgress *addTask(const QFuture<void> &future,
const QString &title,
const QString &type,
ProgressManagerInterface::PersistentType persistency);
private slots:
void slotFinished();
private:
void removeOldTasks(const QString &type, bool keepOne = false);
void removeOneOldTask();
void removeTask(FutureProgress *task);
void deleteTask(FutureProgress *task);
QVBoxLayout *m_layout;
QList<FutureProgress *> m_taskList;
QHash<FutureProgress *, QString> m_type;
QHash<FutureProgress *, bool> m_keep;
};
} // namespace Internal
} // namespace Core
#endif //PROGRESSVIEW_H