Commit 86bcd586 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Add a proxy class for the progress updater so it's possible for

classes to report progress without needing an actual QWidget --
for instance in unittests.

svn path=/trunk/koffice/; revision=740237
parent 9c36f715
......@@ -153,7 +153,7 @@ if(SHOULD_BUILD_KPRESENTER)
endif(SHOULD_BUILD_KPRESENTER)
macro_optional_add_subdirectory(kdgantt)
macro_optional_add_subdirectory(kchart)
#macro_optional_add_subdirectory(kchart)
FIND_PROGRAM(BZIP2_EXECUTABLE NAMES bzip2 )
......@@ -167,7 +167,7 @@ macro_optional_add_subdirectory(kformula)
macro_optional_add_subdirectory(kivio)
#macro_optional_add_subdirectory(koshell)
macro_optional_add_subdirectory(kounavail)
macro_optional_add_subdirectory(kplato)
#macro_optional_add_subdirectory(kplato)
macro_optional_add_subdirectory(krita)
#macro_optional_add_subdirectory(kugar)
macro_optional_add_subdirectory(kword)
......
......@@ -23,10 +23,11 @@
#include <kis_rotate_visitor.h>
#include <KoProgressUpdater.h>
#include "testutil.h"
void KisRotateVisitorTest::testCreation()
{
KoProgressUpdater pu(0);
TestUtil::TestProgressBar bar;
KoProgressUpdater pu(&bar);
KoUpdater updater = pu.startSubtask();
KisRotateVisitor test(&updater);
}
......
......@@ -23,13 +23,13 @@
#include "kis_shear_visitor.h"
#include "testutil.h"
#include <KoProgressUpdater.h>
void KisShearVisitorTest::testCreation()
{
KoProgressUpdater pu(0);
TestUtil::TestProgressBar bar;
KoProgressUpdater pu(&bar);
KoUpdater updater = pu.startSubtask();
KisShearVisitor test(0.5, 0.5, &updater);
}
......
......@@ -29,10 +29,11 @@
#include "kis_types.h"
#include "kis_image.h"
#include "kis_filter_strategy.h"
#include "testutil.h"
void KisTransformVisitorTest::testCreation()
{
KoProgressUpdater pu(0);
TestUtil::TestProgressBar bar;
KoProgressUpdater pu(&bar);
KoUpdater updater = pu.startSubtask();
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisImageSP img = new KisImage(0, 10, 10, cs, "bla");
......
......@@ -24,12 +24,25 @@
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <KoColorProfile.h>
#include <KoProgressUpdater.h>
#include "kis_paint_device.h"
/**
* Routines that are useful for writing efficient tests
*/
namespace TestUtil {
struct TestProgressBar : public KoProgressProxy
{
int maximum() const {}
void setValue( int value ) {}
void setRange( int minimum, int maximum ) {}
void setFormat( const QString & format ) {}
};
bool compareQImages( QPoint & pt, const QImage & img1, const QImage & img2 )
{
// QTime t;
......
......@@ -20,7 +20,7 @@
#include <QLabel>
#include <QFontMetrics>
#include <QProgressBar>
#include <KoProgressBar.h>
#include <ksqueezedtextlabel.h>
#include <kstatusbar.h>
#include <klocale.h>
......@@ -36,6 +36,7 @@
#include "kis_view2.h"
#include "kis_canvas2.h"
#include "KoViewConverter.h"
#include "KoProgressBar.h"
enum {
IMAGE_SIZE_ID,
......@@ -61,7 +62,7 @@ KisStatusBar::KisStatusBar(KStatusBar * sb, KisView2 * view )
//int height = m_statusBarProfileLabel->height();
m_progress = new QProgressBar(sb);
m_progress = new KoProgressBar(sb);
m_progress->setMaximumWidth(225);
m_progress->setMinimumWidth(225);
m_progress->setMaximumHeight(sb->fontMetrics().height() );
......
......@@ -20,8 +20,8 @@
#define KIS_STATUSBAR_H
#include <QObject>
#include <QProgressBar>
#include <KoProgressBar.h>
#include <kis_types.h>
class QLabel;
......@@ -48,14 +48,14 @@ public slots:
void setProfile( KisImageSP img );
void setHelp( const QString &t );
void updateStatusBarProfileLabel();
QProgressBar * progress()
KoProgressBar * progress()
{
return m_progress;
}
private:
KisView2 * m_view;
QProgressBar * m_progress;
KoProgressBar * m_progress;
KStatusBar * m_statusbar;
QLabel *m_statusBarZoomLabel; // Make interactive line edit
......
......@@ -60,6 +60,7 @@ set(koguiutils_LIB_SRCS
KoProgressUpdater.cpp
KoPrintingDialog.cpp
KoShapePainter.cpp
KoProgressBar.cpp
)
kde4_add_ui_files( koguiutils_LIB_SRCS
......
......@@ -23,6 +23,7 @@
#include <KoZoomHandler.h>
#include <KoShapeManager.h>
#include <KoShape.h>
#include <KoProgressBar.h>
#include <KDebug>
#include <KLocale>
......@@ -30,7 +31,6 @@
#include <QPrinter>
#include <QGridLayout>
#include <QLabel>
#include <QProgressBar>
#include <QPushButton>
#include <QTimer>
......@@ -139,7 +139,7 @@ KoPrintingDialog::KoPrintingDialog(QWidget *parent)
setLayout(grid);
d->pageNumber = new QLabel(this);
grid->addWidget(d->pageNumber, 0, 0);
QProgressBar *bar = new QProgressBar(this);
KoProgressBar *bar = new KoProgressBar(this);
d->progress = new KoProgressUpdater(bar);
grid->addWidget(bar, 1, 0, 1, 3);
d->button = new QPushButton(i18n("Stop"), this);
......
/* This file is part of the KDE project
* Copyright (C) Boudewijn Rempt <boud@valdyas.org>, (C) 2007
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "KoProgressBar.h"
KoProgressBar::KoProgressBar( QWidget * parent )
: QProgressBar( parent )
{
}
KoProgressBar::~KoProgressBar()
{
}
int KoProgressBar::maximum() const
{
return QProgressBar::maximum();
}
void KoProgressBar::setValue( int value )
{
QProgressBar::setValue( value );
}
void KoProgressBar::setRange( int minimum, int maximum )
{
QProgressBar::setRange( minimum, maximum );
}
void KoProgressBar::setFormat( const QString & format )
{
QProgressBar::setFormat( format );
}
/* This file is part of the KDE project
* Copyright (C) Boudewijn Rempt <boud@valdyas.org>, (C) 2007
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KOPROGRESSBAR_H
#define KOPROGRESSBAR_H
#include <QProgressBar>
#include <KoProgressUpdater.h>
#include "koguiutils_export.h"
/**
* KoProgressBar is a thin wrapper around QProgressBar that also implements
* the abstract base class KoProgressProxy. Use this class, not QProgressBar
* to pass to KoProgressUpdater.
*/
class KOGUIUTILS_EXPORT KoProgressBar : public QProgressBar, public KoProgressProxy
{
public:
KoProgressBar( QWidget * parent = 0 );
~KoProgressBar();
int maximum() const;
void setValue( int value );
void setRange( int minimum, int maximum );
void setFormat( const QString & format );
};
#endif
......@@ -22,7 +22,6 @@
#include <threadAction/KoExecutePolicy.h>
#include <threadweaver/ThreadWeaver.h>
#include <QProgressBar>
#include <QString>
// #include <KDebug>
......@@ -63,7 +62,7 @@ private:
class KoProgressUpdater::Private {
public:
Private(QProgressBar *p)
Private(KoProgressProxy *p)
: progressBar(p),
totalWeight(0),
currentProgress(0),
......@@ -102,7 +101,7 @@ public:
}
QProgressBar *progressBar;
KoProgressProxy *progressBar;
QList<KoProgressUpdaterPrivate*> subtasks;
int totalWeight;
int currentProgress; // used for the update and updateUi methods. Don't use elsewhere
......@@ -111,7 +110,7 @@ public:
};
KoProgressUpdater::KoProgressUpdater(QProgressBar *progressBar)
KoProgressUpdater::KoProgressUpdater(KoProgressProxy *progressBar)
: d(new Private(progressBar))
{
Q_ASSERT(d->progressBar);
......
......@@ -26,10 +26,10 @@
#include <QMutex>
#include <QPointer>
class QProgressBar;
class KoUpdater;
class KoProgressUpdaterPrivate;
class KoAction;
class KoProgressProxy;
/**
* Allow multiple subtasks to safely update and report progress.
......@@ -63,7 +63,7 @@ public:
* Constructor.
* @param progressBar the progress bar to update.
*/
KoProgressUpdater(QProgressBar *progressBar);
KoProgressUpdater(KoProgressProxy *progressBar);
/// destructor
virtual ~KoProgressUpdater();
......@@ -73,8 +73,8 @@ public:
* the progressBar as well as the text in the progressbar.
* @param range the total range of progress bar makes.
* @param text The text to show in the progressBar.
* @see QProgressBar::setRange()
* @see QProgressBar::setFormat()
* @see KoProgressProxy::setRange()
* @see KoProgressProxy::setFormat()
*/
void start(int range = 100, const QString &text = "%p%");
......@@ -147,5 +147,25 @@ private:
QPointer<KoProgressUpdaterPrivate> d;
};
/**
* A proxy interface for a real progress status reporting thing, either
* a widget such as a KoProgressProxy childclass that also inherits this
* interface, or something that prints progress to stdout.
*/
class KoProgressProxy {
public:
virtual ~KoProgressProxy()
{
}
virtual int maximum() const = 0;
virtual void setValue( int value ) = 0;
virtual void setRange( int minimum, int maximum ) = 0;
virtual void setFormat( const QString & format ) = 0;
};
#endif
......@@ -86,7 +86,7 @@ KoPADocumentStructureDocker::KoPADocumentStructureDocker( QWidget* parent )
QWidget *mainWidget = new QWidget( this );
QGridLayout* layout = new QGridLayout( mainWidget );
layout->addWidget( m_sectionView = new KoDocumentSectionView( mainWidget ), 0, 0, 1, 4 );
m_sectionView->setDisplayMode( KoDocumentSectionView::DetailedMode );
QButtonGroup *buttonGroup = new QButtonGroup( mainWidget );
buttonGroup->setExclusive( false );
......
......@@ -64,7 +64,7 @@ public:
* @return this color
*/
KoColor &operator=(const KoColor &other);
bool operator==(const KoColor &other) const;
/// return the current colorSpace
......@@ -100,8 +100,8 @@ public:
/// Convenient function for converting from a QColor and setting the opacity
void fromQColor(const QColor& c, quint8 opacity) const;
/// For easy memcpy'ing etc. WARNING; violates encapsulation.
KDE_DEPRECATED quint8 * data() const;
/// For easy memcpy'ing etc.
quint8 * data() const;
#ifndef NODEBUG
/// use kDebug calls to print internal info
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment