2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01: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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01: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
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "progressview.h"
|
|
|
|
|
#include "futureprogress.h"
|
|
|
|
|
|
2008-12-09 15:25:01 +01:00
|
|
|
#include <utils/qtcassert.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QVBoxLayout>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace Core::Internal;
|
|
|
|
|
|
|
|
|
|
ProgressView::ProgressView(QWidget *parent)
|
2008-12-02 14:09:21 +01:00
|
|
|
: QWidget(parent)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FutureProgress *ProgressView::addTask(const QFuture<void> &future,
|
|
|
|
|
const QString &title,
|
|
|
|
|
const QString &type,
|
2009-11-26 15:51:10 +01:00
|
|
|
ProgressManager::ProgressFlags flags)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
removeOldTasks(type);
|
|
|
|
|
if (m_taskList.size() == 3)
|
|
|
|
|
removeOneOldTask();
|
|
|
|
|
FutureProgress *progress = new FutureProgress(this);
|
|
|
|
|
progress->setTitle(title);
|
|
|
|
|
progress->setFuture(future);
|
2010-03-12 16:26:42 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
m_layout->insertWidget(0, progress);
|
|
|
|
|
m_taskList.append(progress);
|
2010-03-12 16:26:42 +01:00
|
|
|
progress->setType(type);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
if (flags.testFlag(ProgressManager::KeepOnFinish))
|
2010-10-15 17:22:45 +02:00
|
|
|
progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction);
|
Remove braces for single lines of conditions
#!/usr/bin/env ruby
Dir.glob('**/*.cpp') { |file|
# skip ast (excluding paste, astpath, and canv'ast'imer)
next if file =~ /ast[^eip]|keywords\.|qualifiers|preprocessor|names.cpp/i
s = File.read(file)
next if s.include?('qlalr')
orig = s.dup
s.gsub!(/\n *if [^\n]*{\n[^\n]*\n\s+}(\s+else if [^\n]* {\n[^\n]*\n\s+})*(\s+else {\n[^\n]*\n\s+})?\n/m) { |m|
res = $&
if res =~ /^\s*(\/\/|[A-Z_]{3,})/ # C++ comment or macro (Q_UNUSED, SDEBUG), do not touch braces
res
else
res.gsub!('} else', 'else')
res.gsub!(/\n +} *\n/m, "\n")
res.gsub(/ *{$/, '')
end
}
s.gsub!(/ *$/, '')
File.open(file, 'wb').write(s) if s != orig
}
Change-Id: I3b30ee60df0986f66c02132c65fc38a3fbb6bbdc
Reviewed-by: hjk <qthjk@ovi.com>
2013-01-08 03:32:53 +02:00
|
|
|
else
|
2011-06-24 16:00:47 +02:00
|
|
|
progress->setKeepOnFinish(FutureProgress::HideOnFinish);
|
2010-03-12 16:26:42 +01:00
|
|
|
connect(progress, SIGNAL(removeMe()), this, SLOT(slotRemoveTask()));
|
2008-12-02 12:01:29 +01:00
|
|
|
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;
|
2010-03-12 16:26:42 +01:00
|
|
|
if ((*i)->type() == type) {
|
2011-06-09 13:18:39 +02:00
|
|
|
if (firstFound && ((*i)->future().isFinished() || (*i)->future().isCanceled())) {
|
2008-12-02 12:01:29 +01:00
|
|
|
deleteTask(*i);
|
|
|
|
|
i = m_taskList.erase(i);
|
|
|
|
|
}
|
|
|
|
|
firstFound = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ProgressView::deleteTask(FutureProgress *progress)
|
|
|
|
|
{
|
|
|
|
|
layout()->removeWidget(progress);
|
2009-01-28 16:33:16 +01:00
|
|
|
progress->hide();
|
2008-12-02 12:01:29 +01:00
|
|
|
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) {
|
2010-03-12 16:26:42 +01:00
|
|
|
QString type = (*i)->type();
|
|
|
|
|
|
|
|
|
|
int taskCount = 0;
|
|
|
|
|
foreach (FutureProgress *p, m_taskList)
|
|
|
|
|
if (p->type() == type)
|
|
|
|
|
++taskCount;
|
|
|
|
|
|
|
|
|
|
if (taskCount > 1) { // don't care for optimizations it's only a handful of entries
|
2008-12-02 12:01:29 +01:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-12 16:26:42 +01:00
|
|
|
void ProgressView::slotRemoveTask()
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
FutureProgress *progress = qobject_cast<FutureProgress *>(sender());
|
2008-12-09 15:25:01 +01:00
|
|
|
QTC_ASSERT(progress, return);
|
2010-03-12 16:26:42 +01:00
|
|
|
QString type = progress->type();
|
|
|
|
|
removeTask(progress);
|
|
|
|
|
removeOldTasks(type, true);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|