void TFutureProgressPrivate::_q_SetFinished() { Q_Q(TFutureProgress); _q_UpdateToolTip(Watcher.future().progressText()); Progress->SetFinished(true); if(Watcher.future().isCanceled()) Progress->SetError(true); else Progress->SetError(false); emit q->Finished(); TryToFadeAway(); }
void downloadFile() { QTemporaryFile file; file.setAutoRemove(false); if (file.open()) { const QString filename = file.fileName(); QInstaller::blockingWrite(&file, QByteArray(scLargeSize, '1')); file.close(); DownloadFileTask fileTask(QLatin1String("file:///") + filename); QFutureWatcher<FileTaskResult> watcher; QSignalSpy started(&watcher, SIGNAL(started())); QSignalSpy finished(&watcher, SIGNAL(finished())); QSignalSpy progress(&watcher, SIGNAL(progressValueChanged(int))); watcher.setFuture(QtConcurrent::run(&DownloadFileTask::doTask, &fileTask)); watcher.waitForFinished(); QTest::qWait(10); // Spin the event loop to deliver queued signals. QCOMPARE(started.count(), 1); QCOMPARE(finished.count(), 1); FileTaskResult result = watcher.result(); QCOMPARE(watcher.future().resultCount(), 1); QVERIFY(QFile(result.target()).exists()); QCOMPARE(file.size(), QFile(result.target()).size()); QCOMPARE(result.checkSum().toHex(), QByteArray("85304f87b8d90554a63c6f6d1e9cc974fbef8d32")); } }
void BaseFileFind::runSearch(Find::SearchResult *search) { FileFindParameters parameters = search->userData().value<FileFindParameters>(); CountingLabel *label = new CountingLabel; connect(search, SIGNAL(countChanged(int)), label, SLOT(updateCount(int))); Find::SearchResultWindow::instance()->popup(true); QFutureWatcher<FileSearchResultList> *watcher = new QFutureWatcher<FileSearchResultList>(); m_watchers.insert(watcher, search); watcher->setPendingResultsLimit(1); connect(watcher, SIGNAL(resultReadyAt(int)), this, SLOT(displayResult(int))); connect(watcher, SIGNAL(finished()), this, SLOT(searchFinished())); if (parameters.flags & Find::FindRegularExpression) { watcher->setFuture(Utils::findInFilesRegExp(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), ITextEditor::openedTextEditorsContents())); } else { watcher->setFuture(Utils::findInFiles(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), ITextEditor::openedTextEditorsContents())); } Core::FutureProgress *progress = Core::ICore::progressManager()->addTask(watcher->future(), tr("Search"), QLatin1String(Constants::TASK_SEARCH)); progress->setWidget(label); connect(progress, SIGNAL(clicked()), search, SLOT(popup())); }
void test01(){ // Prepare the vector. QVector<int> vector; for (int i = 0; i < iterations; ++i) vector.append(i); // Create a progress dialog. QProgressDialog dialog; dialog.setLabelText(QString("Progressing using %1 thread(s)...").arg(QThread::idealThreadCount())); // Create a QFutureWatcher and connect signals and slots. QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); // Start the computation. futureWatcher.setFuture(QtConcurrent::map(vector, spin)); // Display the dialog and start the event loop. dialog.exec(); futureWatcher.waitForFinished(); // Query the future to check if was canceled. qDebug() << "Canceled?" << futureWatcher.future().isCanceled(); }
void BaseFileFind::runSearch(SearchResult *search) { FileFindParameters parameters = search->userData().value<FileFindParameters>(); CountingLabel *label = new CountingLabel; connect(search, &SearchResult::countChanged, label, &CountingLabel::updateCount); CountingLabel *statusLabel = new CountingLabel; connect(search, &SearchResult::countChanged, statusLabel, &CountingLabel::updateCount); SearchResultWindow::instance()->popup(IOutputPane::Flags(IOutputPane::ModeSwitch|IOutputPane::WithFocus)); QFutureWatcher<FileSearchResultList> *watcher = new QFutureWatcher<FileSearchResultList>(); d->m_watchers.insert(watcher, search); watcher->setPendingResultsLimit(1); connect(watcher, &QFutureWatcherBase::resultReadyAt, this, &BaseFileFind::displayResult); connect(watcher, &QFutureWatcherBase::finished, this, &BaseFileFind::searchFinished); if (parameters.flags & FindRegularExpression) { watcher->setFuture(Utils::findInFilesRegExp(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), TextDocument::openedTextDocumentContents())); } else { watcher->setFuture(Utils::findInFiles(parameters.text, files(parameters.nameFilters, parameters.additionalParameters), textDocumentFlagsForFindFlags(parameters.flags), TextDocument::openedTextDocumentContents())); } FutureProgress *progress = ProgressManager::addTask(watcher->future(), tr("Searching"), Constants::TASK_SEARCH); progress->setWidget(label); progress->setStatusBarWidget(statusLabel); connect(progress, &FutureProgress::clicked, search, &SearchResult::popup); }
void MapReduceProgress::operationFinished() { QFutureWatcher<void>* watcher = (QFutureWatcher<void>*) sender(); m_model->removeRow(itemForFuture(watcher->future())->row()); watcher->deleteLater(); if (m_model->rowCount() == 0) accept(); }
void MainWindow::writeFile() { QString filename = QFileDialog::getSaveFileName(this, QString("Write fiff data file"), QString("./MNE-sample-data/MEG/sample/"), tr("fif data files (*.fif)")); if(filename.isEmpty()) { qDebug("User aborted saving to fiff data file"); return; } if(filename == m_qFileRaw.fileName()) { QMessageBox msgBox; msgBox.setText("You are trying to write to the file you are currently loading the data from. Please choose another file to write to."); msgBox.exec(); return; } //Create output file, progress dialog and future watcher QFile qFileOutput (filename); if(qFileOutput.isOpen()) qFileOutput.close(); QFutureWatcher<bool> writeFileFutureWatcher; QProgressDialog progressDialog("Writing to fif file...", QString(), 0, 0, this, Qt::Dialog); //Connect future watcher and dialog connect(&writeFileFutureWatcher, &QFutureWatcher<bool>::finished, &progressDialog, &QProgressDialog::reset); connect(&progressDialog, &QProgressDialog::canceled, &writeFileFutureWatcher, &QFutureWatcher<bool>::cancel); connect(m_pDataWindow->getDataModel(), &RawModel::writeProgressRangeChanged, &progressDialog, &QProgressDialog::setRange); connect(m_pDataWindow->getDataModel(), &RawModel::writeProgressChanged, &progressDialog, &QProgressDialog::setValue); //Run the file writing in seperate thread writeFileFutureWatcher.setFuture(QtConcurrent::run(m_pDataWindow->getDataModel(), &RawModel::writeFiffData, &qFileOutput)); progressDialog.exec(); writeFileFutureWatcher.waitForFinished(); if(!writeFileFutureWatcher.future().result()) qDebug() << "MainWindow: ERROR writing fiff data file" << qFileOutput.fileName() << "!"; else qDebug() << "MainWindow: Successfully written to" << qFileOutput.fileName() << "!"; }
void tst_QFutureWatcher::startFinish() { QFutureWatcher<void> futureWatcher; QSignalSpy started(&futureWatcher, SIGNAL(started())); QSignalSpy finished(&futureWatcher, SIGNAL(finished())); futureWatcher.setFuture(QtConcurrent::run(sleeper)); QTest::qWait(10); // spin the event loop to deliver queued signals. QCOMPARE(started.count(), 1); QCOMPARE(finished.count(), 0); futureWatcher.future().waitForFinished(); QTest::qWait(10); QCOMPARE(started.count(), 1); QCOMPARE(finished.count(), 1); }
void DeviceProperties::UpdateFormatsFinished() { QFutureWatcher<bool>* watcher = static_cast<QFutureWatcher<bool>*>(sender()); watcher->deleteLater(); updating_formats_ = false; if (!watcher->future().result()) { supported_formats_.clear(); } // Hide widgets if there are no supported types ui_->supported_formats_container->setVisible(!supported_formats_.isEmpty()); ui_->transcode_unsupported->setEnabled(!supported_formats_.isEmpty()); if (ui_->transcode_unsupported->isChecked() && supported_formats_.isEmpty()) { ui_->transcode_off->setChecked(true); } // Populate supported types list ui_->supported_formats->clear(); for (Song::FileType type : supported_formats_) { QListWidgetItem* item = new QListWidgetItem(Song::TextForFiletype(type)); ui_->supported_formats->addItem(item); } ui_->supported_formats->sortItems(); // Set the format combobox item TranscoderPreset preset = Transcoder::PresetForFileType( Song::FileType(index_.data(DeviceManager::Role_TranscodeFormat).toInt())); if (preset.type_ == Song::Type_Unknown) { // The user hasn't chosen a format for this device yet, so work our way down // a list of some preferred formats, picking the first one that is supported preset = Transcoder::PresetForFileType( Transcoder::PickBestFormat(supported_formats_)); } ui_->transcode_format->setCurrentIndex( ui_->transcode_format->findText(preset.name_)); ui_->formats_stack->setCurrentWidget(ui_->formats_page); }
void SymbolsFindFilter::startSearch(SearchResult *search) { SymbolSearcher::Parameters parameters = search->userData().value<SymbolSearcher::Parameters>(); QSet<QString> projectFileNames; if (parameters.scope == SymbolSearcher::SearchProjectsOnly) { foreach (ProjectExplorer::Project *project, ProjectExplorer::SessionManager::projects()) projectFileNames += project->files(ProjectExplorer::Project::AllFiles).toSet(); } QFutureWatcher<SearchResultItem> *watcher = new QFutureWatcher<SearchResultItem>(); m_watchers.insert(watcher, search); connect(watcher, SIGNAL(finished()), this, SLOT(finish())); connect(watcher, SIGNAL(resultsReadyAt(int,int)), this, SLOT(addResults(int,int))); SymbolSearcher *symbolSearcher = m_manager->indexingSupport()->createSymbolSearcher(parameters, projectFileNames); connect(watcher, SIGNAL(finished()), symbolSearcher, SLOT(deleteLater())); watcher->setFuture(QtConcurrent::run(&SymbolSearcher::runSearch, symbolSearcher)); FutureProgress *progress = ProgressManager::addTask(watcher->future(), tr("Searching for Symbol"), Core::Constants::TASK_SEARCH); connect(progress, SIGNAL(clicked()), search, SLOT(popup())); }
int main(int argc, char **argv) { QApplication app(argc, argv); QVector<int> vector; for (int i=0; i<iterations; ++i) vector.append(i); QProgressDialog dialog; dialog.setLabelText(QString("Progressing using %1 thraed(s)...").arg(QThread::idealThreadCount())); QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int, int)), &dialog, SLOT(setRange(int, int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); futureWatcher.setFuture(QtConcurrent::map(vector, spin)); dialog.exec(); futureWatcher.waitForFinished(); qDebug() << "Canceled ?" << futureWatcher.future().isCanceled(); }
int main(int argc, char **argv) { Vals vals; /* the application */ QApplication app(argc, argv); app.setApplicationName(APP_NAME); app.setWindowIcon(QIcon(":/icon")); Window window; /* translations */ QTranslator qtr; if (qtr.load("qt_" + QLocale::system().name(), QTR_PATH)) app.installTranslator(&qtr); QTranslator htr; if (htr.load("H4KvT_" + QLocale::system().name(), ":/")) app.installTranslator(&htr); /* display information */ QTextEdit *text = new QTextEdit; text->setReadOnly(true); text->setLineWrapMode(QTextEdit::NoWrap); text->setToolTip(Window::tr("Drop any file for hashing")); QObject::connect(&window, &Window::idle, text, &QWidget::setEnabled); /* compare hash */ QLineEdit *test = new QLineEdit; HexVal hexval; test->setValidator(&hexval); test->installEventFilter(&window); test->setToolTip(Window::tr("Compare hashes")); QObject::connect(test, &QLineEdit::textChanged, [&](const QString &newValue) { if (vals.name != "") { std::string hashVal = newValue.toStdString(); std::transform(hashVal.begin(), hashVal.end(), hashVal.begin(), ::tolower); std::stringstream html; if (hashVal != "") html << "<style>.h" << hashVal << "{color:green}</style>"; html << "<div style='margin-bottom:2; font-size:27px'><i><b>" << vals.name << "</b></i></div>"; html << "<div style='margin-bottom:7; margin-left:23; font-size:13px'>" << vals.path << "</div>"; if (!ALL(vals,"")) { html << "<div style='font-size:13px'><table>"; if (vals.md5 != "") html << "<tr><td>md5: </td><td class='h" << vals.md5 << "'>" << vals.md5 << "</td</tr>"; if (vals.sha1 != "") html << "<tr><td>sha1: </td><td class='h" << vals.sha1 << "'>" << vals.sha1 << "</td</tr>"; if (vals.sha224 != "") html << "<tr><td>sha224: </td><td class='h" << vals.sha224 << "'>" << vals.sha224 << "</td</tr>"; if (vals.sha256 != "") html << "<tr><td>sha256: </td><td class='h" << vals.sha256 << "'>" << vals.sha256 << "</td</tr>"; if (vals.sha384 != "") html << "<tr><td>sha384: </td><td class='h" << vals.sha384 << "'>" << vals.sha384 << "</td</tr>"; if (vals.sha512 != "") html << "<tr><td>sha512: </td><td class='h" << vals.sha512 << "'>" << vals.sha512 << "</td</tr>"; html << "</table></div>"; } int horizontal = text->horizontalScrollBar()->value(); int vertical = text->verticalScrollBar()->value(); text->setHtml(QString::fromStdString(html.str())); text->horizontalScrollBar()->setValue(horizontal); text->verticalScrollBar()->setValue(vertical); test->setStyleSheet(ANY(vals,hashVal) ? "color:green" : ""); }}); /* error messages */ QLabel *error = new QLabel; error->setStyleSheet("color:red"); /* test or error */ QStackedWidget *stack = new QStackedWidget; delete stack->layout(); stack->setLayout(new Stack); stack->addWidget(error); stack->addWidget(test); stack->setCurrentIndex(1); /* toggle test or error */ QPushButton *hash = new QPushButton(QIcon(":/icon"), ""); hash->setCheckable(true); hash->setChecked(true); hash->setToolTip(Window::tr("Compare hashes")); QObject::connect(hash, &QPushButton::toggled, stack, &QStackedWidget::setCurrentIndex); /* store method */ QSettings settings("H4KvT", "H4KvT"); /* more methods */ bool more; try { settings.setValue("MoreHashingMethods", more = moreOrLess()); } catch (...) { more = settings.value("MoreHashingMethods", false).toBool(); } /* hashing method */ QComboBox *meth = new QComboBox; meth->addItem("md5"); meth->addItem("sha1"); if (more) meth->addItem("sha224"); meth->addItem("sha256"); if (more) meth->addItem("sha384"); meth->addItem("sha512"); meth->setToolTip(Window::tr("Hashing method")); meth->setCurrentText(settings.value("HashingMethod", "md5").toString()); QObject::connect(&window, &Window::idle, meth, &QWidget::setEnabled); QObject::connect(meth, &QComboBox::currentTextChanged, [&](const QString &text) { settings.setValue("HashingMethod", text); }); /* toolbar */ QHBoxLayout *pane = new QHBoxLayout; pane->addWidget(hash, 0, Qt::AlignLeft); pane->addWidget(stack); pane->addWidget(meth, 0, Qt::AlignRight); /* main layout */ QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(text); layout->addLayout(pane); /* the window */ window.centralWidget()->setLayout(layout); window.show(); /* future hashing */ QFutureWatcher<Vals> zu; QObject::connect(&zu, &QFutureWatcher<Vals>::finished, [&]() { Vals valsi = zu.future().result(); window.idle(true); if (valsi.path == "") { error->setText(QString::fromStdString(valsi.name)); hash->setChecked(false); } else { error->clear(); vals += valsi; test->textChanged(test->text()); } }); QObject::connect(meth, &QComboBox::currentTextChanged, [&](const QString &text) { if (vals.name != "") { window.idle(false); zu.setFuture(QtConcurrent::run(&update, text, vals)); }}); QObject::connect(&window, &Window::fileDroped, [&](const QString &name, const QString &path) { window.idle(false); zu.setFuture(QtConcurrent::run(&update, meth->currentText(), Vals(name, path))); }); /* hashing info */ QGraphicsBlurEffect blur; blur.setBlurHints(QGraphicsBlurEffect::AnimationHint); QPropertyAnimation anim(&blur, "blurRadius"); anim.setDuration(2000); anim.setLoopCount(-1); anim.setKeyValueAt(0, 0); anim.setKeyValueAt(0.5, 3); anim.setKeyValueAt(1, 0); QLabel *hashing = new QLabel; hashing->setPixmap(QPixmap(":/icon")); hashing->setAttribute(Qt::WA_TransparentForMouseEvents); hashing->setGraphicsEffect(&blur); hashing->hide(); (new QHBoxLayout(text))->addWidget(hashing, 0, Qt::AlignCenter); QObject::connect(&blur, &QGraphicsBlurEffect::blurRadiusChanged, hashing, static_cast<void(QWidget::*)()>(&QWidget::update)); QObject::connect(&window, &Window::idle, [&](bool idle) { if (idle) { hashing->hide(); anim.stop(); } else { hashing->show(); anim.start(); } }); /* about app */ QMenu about; QAction *action = about.addAction(QIcon(":/icon"), Window::tr("About %1").arg(APP_NAME)); action->setMenuRole(QAction::AboutRole); QObject::connect(action, &QAction::triggered, &window, &Window::about); error->setContextMenuPolicy(Qt::NoContextMenu); hash->setContextMenuPolicy(Qt::NoContextMenu); meth->setContextMenuPolicy(Qt::NoContextMenu); window.setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(&window, &QWidget::customContextMenuRequested, [&about, &window](const QPoint &pos) { about.popup(window.mapToGlobal(pos)); }); text->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(text, &QWidget::customContextMenuRequested, [action, text](const QPoint &pos) { if (QMenu *m = text->createStandardContextMenu()) { m->insertAction(m->insertSeparator(m->actions()[0]), action); m->popup(text->mapToGlobal(pos)); } }); test->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(test, &QWidget::customContextMenuRequested, [action, test](const QPoint &pos) { if (QMenu *m = test->createStandardContextMenu()) { m->insertAction(m->insertSeparator(m->actions()[0]), action); m->popup(test->mapToGlobal(pos)); } }); return app.exec(); }
void QTAIMCriticalPointLocator::locateBondCriticalPoints() { if( m_nuclearCriticalPoints.length() < 1 ) { return; } const qint64 numberOfNuclei = m_wfn->numberOfNuclei(); if( numberOfNuclei < 2) { return; } QString temporaryFileName=QTAIMCriticalPointLocator::temporaryFileName(); QString nuclearCriticalPointsFileName=QTAIMCriticalPointLocator::temporaryFileName(); QFile nuclearCriticalPointsFile(nuclearCriticalPointsFileName); nuclearCriticalPointsFile.open(QIODevice::WriteOnly); QDataStream nuclearCriticalPointsOut(&nuclearCriticalPointsFile); nuclearCriticalPointsOut << m_nuclearCriticalPoints; nuclearCriticalPointsFile.close(); QList<QList<QVariant> > inputList; for( qint64 M=0 ; M < numberOfNuclei - 1 ; ++M ) { for( qint64 N=M+1 ; N < numberOfNuclei ; ++N ) { const qreal distanceCutoff = 8.0 ; Matrix<qreal,3,1> a; Matrix<qreal,3,1> b; a << m_wfn->xNuclearCoordinate(M), m_wfn->yNuclearCoordinate(M), m_wfn->zNuclearCoordinate(M) ; b << m_wfn->xNuclearCoordinate(N), m_wfn->yNuclearCoordinate(N), m_wfn->zNuclearCoordinate(N) ; if( QTAIMMathUtilities::distance(a,b) < distanceCutoff ) { QVector3D x0y0z0( ( m_wfn->xNuclearCoordinate(M) + m_wfn->xNuclearCoordinate(N) ) / 2.0 , ( m_wfn->yNuclearCoordinate(M) + m_wfn->yNuclearCoordinate(N) ) / 2.0, ( m_wfn->zNuclearCoordinate(M) + m_wfn->zNuclearCoordinate(N) ) / 2.0 ); QList<QVariant> input; input.append( temporaryFileName ); input.append( nuclearCriticalPointsFileName ); input.append( M ); input.append( N ); input.append( x0y0z0.x() ); input.append( x0y0z0.y() ); input.append( x0y0z0.z() ); inputList.append(input); } } // end N } // end M m_wfn->saveToBinaryFile(temporaryFileName); QProgressDialog dialog; dialog.setWindowTitle("QTAIM"); dialog.setLabelText(QString("Bond Critical Points Search")); QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); QFuture<QList<QVariant> > future=QtConcurrent::mapped(inputList, QTAIMLocateBondCriticalPoint);; futureWatcher.setFuture(future); dialog.exec(); futureWatcher.waitForFinished(); QList<QList<QVariant> > results; if( futureWatcher.future().isCanceled() ) { results.clear(); } else { results=future.results(); } QFile file; file.remove(temporaryFileName); file.remove(nuclearCriticalPointsFileName); for( qint64 i=0 ; i < results.length() ; ++i ) { QList<QVariant> thisCriticalPoint=results.at(i); bool success=thisCriticalPoint.at(0).toBool(); if(success) { QPair<qint64,qint64> bondedAtoms; bondedAtoms.first=thisCriticalPoint.at(1).toInt(); bondedAtoms.second=thisCriticalPoint.at(2).toInt(); m_bondedAtoms.append( bondedAtoms ); QVector3D coordinates(thisCriticalPoint.at(3).toReal(), thisCriticalPoint.at(4).toReal(), thisCriticalPoint.at(5).toReal()); m_bondCriticalPoints.append( coordinates ); m_laplacianAtBondCriticalPoints.append(thisCriticalPoint.at(6).toReal()); m_ellipticityAtBondCriticalPoints.append(thisCriticalPoint.at(7).toReal()); qint64 pathLength=thisCriticalPoint.at(8).toInt(); QList<QVector3D> bondPath; for( qint64 i=0 ; i < pathLength ; ++i ) { QVector3D pathPoint(thisCriticalPoint.at(9 + i ).toReal(), thisCriticalPoint.at(9 + i + pathLength ).toReal(), thisCriticalPoint.at(9 + i + 2*pathLength ).toReal()); bondPath.append(pathPoint); } m_bondPaths.append(bondPath); } } }
void TFutureProgressPrivate::_q_Cancel() { Watcher.future().cancel(); }
void QTAIMCriticalPointLocator::locateElectronDensitySinks() { QString temporaryFileName=QTAIMCriticalPointLocator::temporaryFileName(); QList<QList<QVariant> > inputList; qreal xmin,ymin,zmin; qreal xmax,ymax,zmax; qreal xstep,ystep,zstep; // TODO: if only we were using Eigen data structures... QList<qreal> xNuclearCoordinates; QList<qreal> yNuclearCoordinates; QList<qreal> zNuclearCoordinates; for( qint64 i=0; i < m_wfn->numberOfNuclei() ; ++i ) { xNuclearCoordinates.append( m_wfn->xNuclearCoordinate(i) ); yNuclearCoordinates.append( m_wfn->yNuclearCoordinate(i) ); zNuclearCoordinates.append( m_wfn->zNuclearCoordinate(i) ); } xmin=xNuclearCoordinates.first(); xmax=xNuclearCoordinates.first(); for( qint64 i=1 ; i < m_wfn->numberOfNuclei() ; ++i) { if( xNuclearCoordinates.at(i) < xmin ) { xmin=xNuclearCoordinates.at(i); } if( xNuclearCoordinates.at(i) > xmax ) { xmax=xNuclearCoordinates.at(i); } } ymin=yNuclearCoordinates.first(); ymax=yNuclearCoordinates.first(); for( qint64 i=1 ; i < yNuclearCoordinates.count() ; ++i) { if( yNuclearCoordinates.at(i) < ymin ) { ymin=yNuclearCoordinates.at(i); } if( yNuclearCoordinates.at(i) > ymax ) { ymax=yNuclearCoordinates.at(i); } } zmin=zNuclearCoordinates.first(); zmax=zNuclearCoordinates.first(); for( qint64 i=1 ; i < zNuclearCoordinates.count() ; ++i) { if( zNuclearCoordinates.at(i) < zmin ) { zmin=zNuclearCoordinates.at(i); } if( zNuclearCoordinates.at(i) > zmax ) { zmax=zNuclearCoordinates.at(i); } } xmin= -2.0 + xmin; ymin= -2.0 + ymin; zmin= -2.0 + zmin; xmax = 2.0 + xmax; ymax = 2.0 + ymax; zmax = 2.0 + zmax; xstep=ystep=zstep= 0.5; for( qreal x=xmin ; x < xmax+xstep ; x=x+xstep) { for( qreal y=ymin ; y < ymax+ystep ; y=y+ystep) { for( qreal z=zmin ; z < zmax+zstep ; z=z+zstep) { QList<QVariant> input; input.append( temporaryFileName ); // input.append( n ); input.append( x ); input.append( y ); input.append( z ); inputList.append(input); } } } m_wfn->saveToBinaryFile(temporaryFileName); QProgressDialog dialog; dialog.setWindowTitle("QTAIM"); dialog.setLabelText(QString("Electron Density Sinks Search")); QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); QFuture<QList<QVariant> > future=QtConcurrent::mapped(inputList, QTAIMLocateElectronDensitySink ); futureWatcher.setFuture(future); dialog.exec(); futureWatcher.waitForFinished(); QList<QList<QVariant> > results; if( futureWatcher.future().isCanceled() ) { results.clear(); } else { results=future.results(); } QFile file; file.remove(temporaryFileName); for( qint64 n=0 ; n < results.length() ; ++n ) { qint64 counter=0; bool correctSignature = results.at(n).at(counter).toBool(); counter++; if( correctSignature ) { qreal x=results.at(n).at(counter).toReal(); counter++; qreal y=results.at(n).at(counter).toReal(); counter++; qreal z=results.at(n).at(counter).toReal(); counter++; if( (xmin < x && x < xmax) && (ymin < y && y < ymax) && (zmin < z && z < zmax) ) { QVector3D result(x,y,z); qreal smallestDistance=HUGE_REAL_NUMBER; for(qint64 i=0 ; i < m_electronDensitySinks.length() ; ++i ) { Matrix<qreal,3,1> a(x,y,z); Matrix<qreal,3,1> b(m_electronDensitySinks.at(i).x(), m_electronDensitySinks.at(i).y(), m_electronDensitySinks.at(i).z()); qreal distance=QTAIMMathUtilities::distance(a,b); if( distance < smallestDistance ) { smallestDistance=distance; } } if( smallestDistance > 1.e-2 ) { m_electronDensitySinks.append( result ); } } } } // qDebug() << "SINKS" << m_electronDensitySinks; }
void MapReduceProgress::operationChanged() { QFutureWatcher<void>* watcher = (QFutureWatcher<void>*) sender(); m_ui.view->update(itemForFuture(watcher->future())->index()); }
void QTAIMCriticalPointLocator::locateNuclearCriticalPoints() { QString temporaryFileName=QTAIMCriticalPointLocator::temporaryFileName(); QList<QList<QVariant> > inputList; const qint64 numberOfNuclei = m_wfn->numberOfNuclei(); for( qint64 n=0 ; n < numberOfNuclei ; ++n) { QList<QVariant> input; input.append( temporaryFileName ); input.append( n ); input.append( m_wfn->xNuclearCoordinate(n) ); input.append( m_wfn->yNuclearCoordinate(n) ); input.append( m_wfn->zNuclearCoordinate(n) ); inputList.append(input); } m_wfn->saveToBinaryFile(temporaryFileName); QProgressDialog dialog; dialog.setWindowTitle("QTAIM"); dialog.setLabelText(QString("Nuclear Critical Points Search")); QFutureWatcher<void> futureWatcher; QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset())); QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel())); QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int,int)), &dialog, SLOT(setRange(int,int))); QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int))); QFuture<QList<QVariant> > future=QtConcurrent::mapped(inputList, QTAIMLocateNuclearCriticalPoint); futureWatcher.setFuture(future); dialog.exec(); futureWatcher.waitForFinished(); QList<QList<QVariant> > results; if( futureWatcher.future().isCanceled() ) { results.clear(); } else { results=future.results(); } QFile file; file.remove(temporaryFileName); for( qint64 n=0 ; n < results.length() ; ++n ) { bool correctSignature = results.at(n).at(0).toBool(); if (correctSignature) { QVector3D result( results.at(n).at(1).toReal(), results.at(n).at(2).toReal(), results.at(n).at(3).toReal() ); m_nuclearCriticalPoints.append( result ); } } }