Функции
01 void TransactionThread::run
02 {
03 Transaction *transact;
04 forever {
05 mutex.lock;
06 if (transactions.isEmpty) {
07 mutex.unlock;
08 break;
09 }
10 QImage oldImage = currentImage;
11 transact = transactions.dequeue;
12 mutex.unlock;
13 emit transactionStarted(transact->message);
14 QImage newImage = transact->apply(oldImage);
15 delete transact;
16 mutex.lock;
17 currentImage = newImage;
18 mutex.unlock;
19 }
20 }
Функция
После старта транзакции мы генерируем сигнал
01 class Transaction
02 {
03 public:
04 virtual ~Transaction { }
05 virtual QImage apply(const QImage ℑ) = 0;
06 virtual QString message = 0;
07 };
Класс
01 class FlipTransaction : public Transaction
02 {
03 public:
04 FlipTransaction(Qt::Orientation orientation);
05 QImage apply(const QImage ℑ);
06 QString message;
07 private:
08 Qt::Orientation orientation;
09 };
Конструктор
01 QImage FlipTransaction::apply(const QImage ℑ)
02 {
03 return image.mirrored(
04 orientation == Qt::Horizontal, orientation == Qt::Vertical);
05 }
Функция
01 QString FlipTransaction::message
02 {
03 if (orientation == Qt::Horizontal) {
04 return QObject::tr("Flipping image horizontally...");
05 } else {
06 return QObject::tr("Flipping image vertically...");
07 }
08 }
Функция
Применение классов Qt во вторичных потоках