[Digikam-devel] branches/digikam/0.8-experimental/digikam/libs/filters
Gilles Caulier
caulier.gilles at free.fr
Sat Jun 11 21:08:13 BST 2005
SVN commit 424408 by cgilles:
Threaded Filter class: Add new initFilter virtual method to prepare data before threaded loop. Using in Texture plugin.
CCMAIL: digikam-devel at kde.org
M +19 -25 threadedfilter.cpp
M +8 -2 threadedfilter.h
--- branches/digikam/0.8-experimental/digikam/libs/filters/threadedfilter.cpp #424407:424408
@@ -40,16 +40,19 @@
namespace Digikam
{
-ThreadedFilter::ThreadedFilter(QImage *orgImage, QObject *parent)
+ThreadedFilter::ThreadedFilter(QImage *orgImage, QObject *parent, QString name)
: QThread()
{
m_orgImage = orgImage->copy();
m_parent = parent;
m_cancel = false;
- m_name = QString::null;
-
+ m_name = name;
+}
+
+void ThreadedFilter::initFilter(void)
+{
m_destImage.create(m_orgImage.width(), m_orgImage.height(), 32);
-
+
if (m_orgImage.width() && m_orgImage.height())
{
if (m_parent)
@@ -61,9 +64,7 @@
{
if (m_parent) // If parent then send event about a problem.
{
- m_eventData.starting = false;
- m_eventData.success = false;
- QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, &m_eventData));
+ postProgress(0, false, false);
kdDebug() << m_name << "::No valid image data !!! ..." << endl;
}
}
@@ -76,17 +77,20 @@
cleanupFilter();
}
+void ThreadedFilter::postProgress(int progress, bool starting, bool success)
+{
+ m_eventData.progress = progress;
+ m_eventData.starting = starting;
+ m_eventData.success = success;
+ QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, &m_eventData));
+}
+
void ThreadedFilter::startComputation()
{
QDateTime startDate = QDateTime::currentDateTime();
if (m_parent)
- {
- m_eventData.starting = true;
- m_eventData.success = false;
- m_eventData.progress = 0;
- QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, &m_eventData));
- }
+ postProgress(0, true, false);
filterImage();
@@ -95,24 +99,14 @@
if (!m_cancel)
{
if (m_parent)
- {
- m_eventData.starting = false;
- m_eventData.success = true;
- m_eventData.progress = 0;
- QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, &m_eventData));
- }
+ postProgress(0, false, true);
kdDebug() << m_name << "::End of computation !!! ... ( " << startDate.secsTo(endDate) << " s )" << endl;
}
else
{
if (m_parent)
- {
- m_eventData.starting = false;
- m_eventData.success = false;
- m_eventData.progress = 0;
- QApplication::postEvent(m_parent, new QCustomEvent(QEvent::User, &m_eventData));
- }
+ postProgress(0, false, false);
kdDebug() << m_name << "::Computation aborted... ( " << startDate.secsTo(endDate) << " s )" << endl;
}
--- branches/digikam/0.8-experimental/digikam/libs/filters/threadedfilter.h #424407:424408
@@ -62,7 +62,7 @@
public:
- ThreadedFilter(QImage *orgImage, QObject *parent=0);
+ ThreadedFilter(QImage *orgImage, QObject *parent=0, QString name=QString::null);
~ThreadedFilter(){ stopComputation(); };
@@ -91,7 +91,10 @@
protected:
- // List of threaded operations.
+ // Start filter operation before threaded method. Must be calls by your constructor.
+ virtual void initFilter(void);
+
+ // List of threaded operations by filter.
virtual void run(){ startComputation(); };
// Main image filter method.
@@ -100,6 +103,9 @@
// Clean up filter data if necessary. Call by stopComputation() method.
virtual void cleanupFilter(void){};
+ // Post Event to parent about progress.
+ void postProgress(int progress=0, bool starting=true, bool success=false);
+
};
} // NameSpace Digikam
More information about the Digikam-devel
mailing list