Advertisement
ttldtor

Untitled

Mar 25th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void DimexReportsProcessor::countRows(const QString &databaseName, std::function<void(void)> onStart, std::function<void(long long)> onDone)
  2. {
  3.     auto watcher = getWatcher();
  4.  
  5.     watchers_ << watcher;
  6.  
  7.     connect(watcher, &Watcher::finished, [this, watcher, databaseName, onDone]()
  8.     {
  9.         QVariantMap result = watcher->future().result();
  10.  
  11.         if (result["job"].toString().compare("count") == 0)
  12.         {
  13.             long long rowsCount = result["count"].toLongLong();
  14.  
  15.             onDone(rowsCount);
  16.         }
  17.         freeWatchers_ << watcher;
  18.         watchers_.removeAll(watcher);
  19.         watcher->disconnect();
  20.     });
  21.  
  22.     onStart();
  23.  
  24.     watcher->setFuture(QtConcurrent::run([databaseName, this]() -> QVariantMap
  25.     {
  26.         QVariantMap   result;
  27.         QString       query = loadQuery("totalrowsnumberquery");
  28.         soci::session sql(soci::firebird, QString("service=%1 user=SYSDBA password=masterkey").arg(databaseName).toStdString());
  29.         long long     count = 0;
  30.  
  31.         sql << query.toStdString(), soci::into(count);
  32.         result["job"] = QString("count");
  33.         result["count"] = count;
  34.  
  35.         return result;
  36.     }));
  37. }
  38.  
  39.  
  40.  
  41. .........
  42.  
  43.  
  44.     connect(ui->openButton, &QPushButton::clicked, [this]
  45.     {
  46.         QString fileName = QFileDialog::getOpenFileName(this, trUtf8("Select database files"), "", trUtf8("Firebird database files (*.fdb)"));
  47.  
  48.         if (!fileName.isNull())
  49.         {
  50.             qDebug() << fileName;
  51.  
  52.             processor_->countRows(fileName, [this, fileName]
  53.             {
  54.                 ui->exportButton->setEnabled(false);
  55. ......
  56.             },
  57.             [this, fileName](long long rowsCount)
  58.             {
  59.                 ui->rowsCountLabel->setText(trUtf8("[Rows count: <b style='color:green'>%1</b>]").arg(rowsCount));
  60.                 openedDataBaseName_ = fileName;
  61.                 ui->exportButton->setEnabled(true);
  62.             });
  63.         }
  64.         else
  65.         {
  66. .....
  67.  
  68.         }
  69.     });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement