int main(int argc, char *argv[]) { QApplication app(argc, argv); //application settings app.setOrganizationName(QLatin1String("TestSoftware")); app.setOrganizationDomain(QLatin1String("testsoft.com")); app.setApplicationName(QLatin1String("TestGraphs")); app.setApplicationVersion(QLatin1String("1.0")); //qml loading MainQmlQuick1Loader view; TranslationChanger translationChanger; view.setMainTranslator(&translationChanger); view.createLangMenu(); QProgressDialog *mainProgressDialog = new QProgressDialog(&view, Qt::FramelessWindowHint); mainProgressDialog->setWindowModality(Qt::WindowModal); static const QString cancelButtonStr = QObject::tr("Cancel"); mainProgressDialog->setCancelButtonText(cancelButtonStr); qmlRegisterType<GraphsAlgorithmsSolver>("com.testsoft.graphs", 1, 0, "GraphSolver"); view.rootContext()->setContextProperty(QLatin1String("mainTranslator"), (QObject *) &translationChanger); view.rootContext()->setContextProperty(QLatin1String("mainProgressDialog"), (QObject *) mainProgressDialog); view.setResizeMode(QDeclarativeView::SizeRootObjectToView); view.setMainQmlFile(QLatin1String("qrc:////MainFilePath/main.qml")); view.showQmlScene(); return app.exec(); }
sqlqueryresultlist searchhandler::perform_grep(QString searchtxt, sqlqueryresultlist searchlist, bool exactmatch) { QVector<QString> strvec; sqlqueryresultlist resultlist; QFutureWatcher<sqlqueryresultlist> futureWatcher; QProgressDialog dialog; unsigned int n = searchlist.resultlist.size(); if (n == 0) return resultlist; strvec.resize(n); for (unsigned int i=0; i < n; i++) { strvec.replace(i, str2qt(searchlist.resultlist[i].filepath)); } dialog.setAutoReset(false); dialog.setLabelText(QString("Grep ").append(QString(tr("in progress"))).append(QString(" ..."))); dialog.setCancelButtonText(tr("Cancel")); 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))); m_grepExactMatch = exactmatch; (*m_grepRegExp) = QRegExp(searchtxt.toAscii().data(), Qt::CaseInsensitive); m_grepRegExp->setPatternSyntax(QRegExp::RegExp2); futureWatcher.setFuture(QtConcurrent::mappedReduced(strvec, doGrep, collateGrep, QtConcurrent::SequentialReduce)); dialog.exec(); futureWatcher.waitForFinished(); if (futureWatcher.isCanceled() == false) resultlist = futureWatcher.result(); return resultlist; }
void Main_Window::on_sweep_clicked() { QProgressDialog *dlg = new QProgressDialog(this); dlg->setWindowModality(Qt::WindowModal); dlg->setLabelText("Frequency Sweep"); dlg->setCancelButtonText("Cancel"); dlg->setMaximum(100); dlg->show(); double start = ui.sweep_start->value(); double stop = ui.sweep_stop->value(); double step = ui.sweep_step->value(); for (double f = start; f <= stop && !dlg->wasCanceled(); f += step) { dlg->setValue((int)((f - start) * 100.0 / (stop - start))); QCoreApplication::processEvents(); ui.freq->setValue(f); on_idle_clicked(); update_freq(); send_freq(); on_cal_clicked(); on_tx_clicked(); usleep(100 * 1000); } delete dlg; }
void Demo::OpenDialog() { QProgressDialog* dialog = new QProgressDialog(this); dialog->setLabelText("Nyan nyan nyan nyan"); dialog->setWindowTitle("Nyan nyan nyan nyan"); dialog->setCancelButtonText("Nooooooooo!"); dialog->setMinimumWidth(350); QTimer* timer = new QTimer(dialog); timer->setInterval(100); connect(timer, SIGNAL(timeout()), SLOT(DialogTimerFired())); connect(dialog, SIGNAL(canceled()), dialog, SLOT(deleteLater())); dialog->show(); timer->start(); }
void DatabaseWidget::readCsvBase(QString openFilename) { // QString currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz"); // qDebug().noquote() << "readCsvBase BEGIN" // << currTime // << this->thread()->currentThreadId(); emit toDebug(objectName(), QString("Открывается файл '%1'.").arg(openFilename)); QString name = QFileInfo(openFilename).fileName(); if(!QFileInfo(openFilename).exists()) { emit toDebug(objectName(), QString("Файл '%1' не найден").arg(openFilename)); return; } QProgressDialog *dialog = new QProgressDialog; dialog->setWindowTitle(trUtf8("Обработка базы (1/3)")); dialog->setLabelText(trUtf8("Открывается файл \"%1\". \nОжидайте ...") .arg(name)); dialog->setCancelButtonText(trUtf8("Отмена")); 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))); QObject::connect(&_futureWatcher, SIGNAL(finished()), dialog, SLOT(deleteLater())); QObject::connect(&_futureWatcher, SIGNAL(finished()), dialog, SLOT(hide())); QFuture<ListAddress> f1 = QtConcurrent::run( readFile, openFilename, MAX_OPEN_ROWS); // Start the computation. _futureWatcher.setFuture(f1); dialog->exec(); // currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz"); // qDebug().noquote() << "readCsvBase END" // << currTime // << this->thread()->currentThreadId(); }
void DatabaseWidget::onProcessOfOpenFinished() { if(_futureWatcher.isFinished() && !_futureWatcher.isCanceled()) { _paddr.reset(new ListAddress(_futureWatcher.future().result())); emit toDebug(objectName(), QString("Открытие файла успешно завершено. Прочитано строк = %1") .arg(_paddr.data()->size())); if(!_paddr.data()->isEmpty()) { // QString currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz"); // qDebug().noquote() << "onProcessOfOpenFinished BEGIN" // << currTime // << this->thread()->currentThreadId(); emit toDebug(objectName(), QString("Начало обработки прочитанной базы.")); QProgressDialog *dialog = new QProgressDialog; dialog->setWindowTitle(trUtf8("Обработка базы (2/3)")); dialog->setLabelText(trUtf8("Обрабатывается файл. Строк: \"%1\". \nОжидайте ...") .arg(_paddr.data()->size())); dialog->setCancelButtonText(trUtf8("Отмена")); QObject::connect(dialog, SIGNAL(canceled()), &_futureWatcherParser, SLOT(cancel())); QObject::connect(&_futureWatcherParser, SIGNAL(progressRangeChanged(int,int)), dialog, SLOT(setRange(int,int))); QObject::connect(&_futureWatcherParser, SIGNAL(progressValueChanged(int)), dialog, SLOT(setValue(int))); QObject::connect(&_futureWatcherParser, SIGNAL(finished()), dialog, SLOT(deleteLater())); QFuture<void> f1 = QtConcurrent::map(*_paddr, parsingAddress ); // Start the computation. _futureWatcherParser.setFuture(f1); dialog->exec(); // currTime=QDateTime::currentDateTime().toString("dd.MM.yyyy hh:mm:ss.zzz"); // qDebug().noquote() << "onProcessOfOpenFinished END" // << currTime // << this->thread()->currentThreadId(); }
void MainWindow::importFile() { QFile loadfile(filename); loadfile.open(QIODevice::ReadOnly); QDataStream ls(&loadfile); ls.setByteOrder(QDataStream::BigEndian); ls.device()->seek(3200); Reel.ReadREEL(ls); //Max_XLine=Max_YLine=Min_XLine=Min_YLine=0; DBTrace t; int xLine; //主测线号XLINE int oldxLine; int inLine; //inLine 号 int temp,_temp,N; temp =_temp=0; N=0; QFile writefile(filename+tr("_db")); writefile.open(QIODevice::WriteOnly); QDataStream ws(&writefile); QProgressDialog *pdg = new QProgressDialog(this); QFont font("Times",10,QFont::Bold); pdg->setFont(font); pdg->setWindowModality(Qt::WindowModal); pdg->setWindowTitle(tr("导入SEGY文件")); pdg->setLabelText(tr("扫描SEGY数据")); pdg->setCancelButtonText(tr("取消")); pdg->setRange(0,Reel.TotalTraces); pdg->setMinimumDuration(500); int HNS = Reel.hns; int DataType = Reel.DataType; xLine = oldxLine = 0; pdg->setValue(0); qApp->processEvents(); for( int i = 0; i < Reel.TotalTraces; i ++) { double fp = 3600.0 + 8.0 + double(i)*double(HNS*DataType + 240.0); pdg->setValue(i+1); qApp->processEvents(); if (pdg->wasCanceled()) { break; } ws<<i; ls.device()->seek(fp); ls >>xLine; ls.device()->seek(fp+12.0); ls>>inLine; t.fp = i; t.in = xLine; t.cross = inLine; t.st = 0; t.et = Reel.hns*Reel.hdt/1000; CdbTrace->AddData(t); if( i == 0 ) { Max_XLine = xLine; Min_XLine = xLine; Max_YLine = inLine; Min_YLine = inLine; } else { if( xLine > Max_XLine ) Max_XLine = xLine; if( xLine < Min_XLine ) Min_XLine = xLine; if( inLine > Max_YLine ) Max_YLine = inLine; if( inLine < Min_YLine ) Min_YLine = inLine; } } loadfile.close(); /**/ reelAction->setEnabled(true); traceAction->setEnabled(true); dataAction->setEnabled(true); }
void Main_GUI::run() { statusBar()->clearMessage(); QString input_name = QDir::fromNativeSeparators(input_line->text()); QString output_name = QDir::fromNativeSeparators(output_line->text()); if (!check_filenames(input_name, output_name)) return; // we need C file descriptors for communication with TTF_autohint FILE* input; FILE* output; again: if (!open_files(input_name, &input, output_name, &output)) return; QProgressDialog dialog; dialog.setCancelButtonText(tr("Cancel")); dialog.setMinimumDuration(1000); dialog.setWindowModality(Qt::WindowModal); const unsigned char* error_string; TA_Info_Func info_func = info; GUI_Progress_Data gui_progress_data = {-1, true, &dialog}; Info_Data info_data; info_data.data = NULL; // must be deallocated after use info_data.data_wide = NULL; // must be deallocated after use info_data.data_len = 0; info_data.data_wide_len = 0; info_data.hinting_range_min = min_box->value(); info_data.hinting_range_max = max_box->value(); info_data.hinting_limit = no_limit_box->isChecked() ? 0 : limit_box->value(); info_data.gray_strong_stem_width = gray_box->isChecked(); info_data.gdi_cleartype_strong_stem_width = gdi_box->isChecked(); info_data.dw_cleartype_strong_stem_width = dw_box->isChecked(); info_data.increase_x_height = no_increase_box->isChecked() ? 0 : increase_box->value(); info_data.x_height_snapping_exceptions = x_height_snapping_exceptions; info_data.windows_compatibility = wincomp_box->isChecked(); info_data.pre_hinting = pre_box->isChecked(); info_data.hint_with_components = hint_box->isChecked(); info_data.latin_fallback = fallback_box->currentIndex(); info_data.symbol = symbol_box->isChecked(); if (info_box->isChecked()) { int ret = build_version_string(&info_data); if (ret == 1) QMessageBox::information( this, "TTFautohint", tr("Can't allocate memory for <b>TTFautohint</b> options string" " in <i>name</i> table."), QMessageBox::Ok, QMessageBox::Ok); else if (ret == 2) QMessageBox::information( this, "TTFautohint", tr("<b>TTFautohint</b> options string" " in <i>name</i> table too long."), QMessageBox::Ok, QMessageBox::Ok); } else info_func = NULL; QByteArray snapping_string = snapping_line->text().toLocal8Bit(); TA_Error error = TTF_autohint("in-file, out-file," "hinting-range-min, hinting-range-max," "hinting-limit," "gray-strong-stem-width," "gdi-cleartype-strong-stem-width," "dw-cleartype-strong-stem-width," "error-string," "progress-callback, progress-callback-data," "info-callback, info-callback-data," "ignore-restrictions," "windows-compatibility," "pre-hinting," "hint-with-components," "increase-x-height," "x-height-snapping-exceptions," "fallback-script, symbol", input, output, info_data.hinting_range_min, info_data.hinting_range_max, info_data.hinting_limit, info_data.gray_strong_stem_width, info_data.gdi_cleartype_strong_stem_width, info_data.dw_cleartype_strong_stem_width, &error_string, gui_progress, &gui_progress_data, info_func, &info_data, ignore_restrictions, info_data.windows_compatibility, info_data.pre_hinting, info_data.hint_with_components, info_data.increase_x_height, snapping_string.constData(), info_data.latin_fallback, info_data.symbol); if (info_box->isChecked()) { free(info_data.data); free(info_data.data_wide); } fclose(input); fclose(output); if (error) { if (handle_error(error, error_string, output_name)) goto again; } else statusBar()->showMessage(tr("Auto-hinting finished.")); }
void SongsQueryWideget::export_excel_clicked() { ///建立临时表映射 /// setCursor(Qt::WaitCursor); QSqlQueryModel *sqlquery = new QSqlQueryModel(this); QSqlQuery _query; MediaPagingQuery argu; getQueryCondition(argu); if(!_sql->queryMedia_All(argu, _query)) return; sqlquery->setQuery(_query); int rows = sqlquery->rowCount(); int columns = sqlquery->columnCount(); setCursor(Qt::ArrowCursor); QString desktopPath = QProcessEnvironment::systemEnvironment().value("USERPROFILE")+"\\Desktop"; QString fileName = QFileDialog::getSaveFileName(tableView_songsQuery, "保存", //QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), desktopPath, "Excel 文件(*.xls *.xlsx)"); QProgressDialog *progress = new QProgressDialog(this); progress->setLabelText("正在导出表格数据……"); progress->setRange(0, rows); progress->setModal(true); progress->setCancelButtonText("取消"); // progress->setMinimumSize(300, 50); progress->setMinimumWidth(400); progress->setAutoClose(true); if (fileName!="") { QAxObject *excel = new QAxObject; if (excel->setControl("Excel.Application")) //连接Excel控件 { excel->dynamicCall("SetVisible (bool Visible)","false");//不显示窗体 excel->setProperty("DisplayAlerts", false);//不显示任何警告信息。如果为true那么在关闭是会出现类似“文件已修改,是否保存”的提示 QAxObject *workbooks = excel->querySubObject("WorkBooks");//获取工作簿集合 workbooks->dynamicCall("Add");//新建一个工作簿 QAxObject *workbook = excel->querySubObject("ActiveWorkBook");//获取当前工作簿 QAxObject *worksheet = workbook->querySubObject("Worksheets(int)", 1); // //数据区 for(int i=0; i<rows; i++) { for (int j=0;j<columns; j++) { QModelIndex index = sqlquery->index(i, j); QString text = index.data().toString(); // table->item(i,j)?table->item(i,j)->text():"" worksheet->querySubObject("Cells(int,int)", i+1, j+1)->dynamicCall("SetValue(const QString&)", text); } QString label_text = QString("正在导出%1行……").arg(i+1); progress->setLabelText(label_text); progress->setValue(i+1); if(progress->wasCanceled()) { break; } } workbook->dynamicCall("SaveAs(const QString&)",QDir::toNativeSeparators(fileName));//保存至fileName workbook->dynamicCall("Close()");//关闭工作簿 //关闭excel excel->dynamicCall("Quit (void)"); delete excel; excel=NULL; QMessageBox box(QMessageBox::Question, "完成", "文件已经导出,是否现在打开?"); box.setStandardButtons(QMessageBox::Yes|QMessageBox::No); box.setButtonText(QMessageBox::Yes, "确定(&Q)"); box.setButtonText(QMessageBox::No, "取消(&C)"); if(box.exec() == QMessageBox::Yes) // if (QMessageBox::question(NULL,"完成","文件已经导出,是否现在打开?",QMessageBox::Yes|QMessageBox::No)==QMessageBox::Yes) { QString local_path = QString("file:///") + fileName; QDesktopServices::openUrl(QUrl(local_path, QUrl::TolerantMode)); //QDir::toNativeSeparators(fileName))); } } else { QMessageBox::warning(NULL,"错误","未能创建 Excel 对象,请安装 Microsoft Excel。",QMessageBox::Apply); } } // progress->close(); }