Ejemplo n.º 1
0
void Thread::Execute(bool WaitTilDone) { //starts the thread, waits til complete;
	clock_t startTime, finishTime;
	startTime = clock();

	QProgressDialog progress;
	progress.setModal(true);
	if (pCancelFlag) *pCancelFlag = false; //haven't canceled before we started!

	start(); 

	if (WantProgress) progress.show();

	if (WantProgress || WantTimed || WaitTilDone){ //if we want to stick around until the thread is finished...
		while (isRunning()){
			if (WantProgress){
				progress.setLabelText(QString((*pCurMessage).c_str()));
				progress.setRange(0, *pCurMaxTick);
				progress.setValue(*pCurTick);
				QApplication::processEvents();
				if (progress.wasCanceled()){
					*pCancelFlag = true;
					wait();
					return; //returns
				}
			}
			msleep(50);
		}
	}

	finishTime = clock();
	double duration = (double)(finishTime - startTime) / CLOCKS_PER_SEC;
	std::ostringstream os;
	os << "Elapsed time: " << duration << " Sec";
	if (WantTimed) QMessageBox::warning(NULL, "Warning", (os.str()).c_str());
}
Ejemplo n.º 2
0
void CandidateIndexesPage::generateCandidates()
{
    if (generator != nullptr) {
        return;
    }

    MainWizard *mainWizard = static_cast<MainWizard*>(wizard());

    QProgressDialog *progress = new QProgressDialog(
        tr("Generating candidates..."),
        tr("Cancel"),
        0,
        100,
        this
    );

    progress->setModal(true);
    progress->setValue(0);
    progress->setMinimumDuration(0);

    generator = new GenerateCandidateIndexes(mainWizard->project);
    connect(generator, SIGNAL(finished()), progress, SLOT(accept()));
    connect(generator, SIGNAL(progress(int)), progress, SLOT(setValue(int)));
    connect(generator, SIGNAL(resultReady()), this, SLOT(candidatesGenerated()));
    connect(progress, SIGNAL(canceled()), generator, SLOT(terminate()));
    generator->start();
}
Ejemplo n.º 3
0
void
TomahawkApp::onShutdownDelayed()
{
    QProgressDialog* d = new QProgressDialog( tr( "Tomahawk is updating the database. Please wait, this may take a minute!" ), QString(),
                                              0, 0, 0, Qt::Tool
                                              | Qt::WindowTitleHint
                                              | Qt::CustomizeWindowHint );
    d->setModal( true );
    d->setAutoClose( false );
    d->setAutoReset( false );
    d->setWindowTitle( tr( "Tomahawk" ) );

#ifdef Q_OS_MAC
    d->setAttribute( Qt::WA_MacAlwaysShowToolWindow );
#endif
    d->show();
}
Ejemplo n.º 4
0
KOnlineBankingSetupWizard::KOnlineBankingSetupWizard(QWidget *parent):
    QWizard(parent),
    d(new Private),
    m_fDone(false),
    m_fInit(false),
    m_appId(0)
{
  setupUi(this);

  m_applicationEdit->hide();
  m_headerVersionEdit->hide();
#ifndef LIBOFX_HAVE_CLIENTUID
  m_editClientUid->setEnabled(false);
  m_clientUidLabel->setEnabled(false);
#endif

  m_appId = new OfxAppVersion(m_applicationCombo, m_applicationEdit, "");
  m_headerVersion = new OfxHeaderVersion(m_headerVersionCombo, "");

  // fill the list view with banks
  QProgressDialog* dlg = new QProgressDialog(this);
  dlg->setWindowTitle(i18n("Loading banklist"));
  dlg->setLabelText(i18n("Getting list of banks from http://moneycentral.msn.com/\nThis may take some time depending on the available bandwidth."));
  dlg->setModal(true);
  dlg->setCancelButton(0);
  // force to show immediately as the call to OfxPartner::BankNames()
  // does not call the processEvents() loop
  dlg->setMinimumDuration(0);
  QCoreApplication::processEvents();

  //set password field according to KDE preferences
  m_editPassword->setPasswordMode(true);

  KListWidgetSearchLine* searchLine = new KListWidgetSearchLine(autoTab, m_listFi);
  vboxLayout1->insertWidget(0, searchLine);
  QTimer::singleShot(20, searchLine, SLOT(setFocus()));

  OfxPartner::setDirectory(QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QLatin1Char('/') + "");
  m_listFi->addItems(OfxPartner::BankNames());
  m_fInit = true;
  delete dlg;

  checkNextButton();
  connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(checkNextButton()));
  connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(newPage(int)));
  connect(m_listFi, SIGNAL(itemSelectionChanged()), this, SLOT(checkNextButton()));
  connect(m_listAccount, SIGNAL(itemSelectionChanged()), this, SLOT(checkNextButton()));
  connect(m_selectionTab, SIGNAL(currentChanged(int)), this, SLOT(checkNextButton()));
  connect(m_fid, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton()));
  connect(m_bankName, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton()));
  connect(m_url, SIGNAL(textChanged(QString)), this, SLOT(checkNextButton()));
  connect(m_editUsername, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton()));
  connect(m_editPassword, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton()));
  connect(m_applicationEdit, SIGNAL(userTextChanged(QString)), this, SLOT(checkNextButton()));
  connect(m_applicationCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(applicationSelectionChanged()));

  // setup text on buttons
  setButtonText(QWizard::NextButton, i18nc("Go to next page of the wizard", "&Next"));
  setButtonText(QWizard::BackButton, KStandardGuiItem::back().text());

  // setup icons
  button(QWizard::FinishButton)->setIcon(KStandardGuiItem::ok().icon());
  button(QWizard::CancelButton)->setIcon(KStandardGuiItem::cancel().icon());
  button(QWizard::NextButton)->setIcon(KStandardGuiItem::forward(KStandardGuiItem::UseRTL).icon());
  button(QWizard::BackButton)->setIcon(KStandardGuiItem::back(KStandardGuiItem::UseRTL).icon());
}
int QgsImageWarper::warpFile( const QString& input,
                              const QString& output,
                              const QgsGeorefTransform &georefTransform,
                              ResamplingMethod resampling,
                              bool useZeroAsTrans,
                              const QString& compression,
                              const QString &projection,
                              double destResX, double destResY )
{
  if ( !georefTransform.parametersInitialized() )
    return false;

  CPLErr eErr;
  GDALDatasetH hSrcDS, hDstDS;
  GDALWarpOptions *psWarpOptions;
  if ( !openSrcDSAndGetWarpOpt( input, resampling, georefTransform.GDALTransformer(), hSrcDS, psWarpOptions ) )
  {
    // TODO: be verbose about failures
    return false;
  }

  double adfGeoTransform[6];
  int destPixels, destLines;
  eErr = GDALSuggestedWarpOutput( hSrcDS, georefTransform.GDALTransformer(),
                                  georefTransform.GDALTransformerArgs(),
                                  adfGeoTransform, &destPixels, &destLines );
  if ( eErr != CE_None )
  {
    GDALClose( hSrcDS );
    GDALDestroyWarpOptions( psWarpOptions );
    return false;
  }

  // If specified, override the suggested resolution with user values
  if ( destResX != 0.0 || destResY != 0.0 )
  {
    // If only one scale has been specified, fill in the other from the GDAL suggestion
    if ( destResX == 0.0 )
      destResX = adfGeoTransform[1];
    if ( destResY == 0.0 )
      destResY = adfGeoTransform[5];

    // Make sure user-specified coordinate system has canonical orientation
    if ( destResX < 0.0 )
      destResX = -destResX;
    if ( destResY > 0.0 )
      destResY = -destResY;

    // Assert that the north-up convention is fullfiled by GDALSuggestedWarpOutput (should always be the case)
    assert( adfGeoTransform[0] > 0.0 );
    assert( adfGeoTransform[5] < 0.0 );
    // Find suggested output image extent (in georeferenced units)
    double minX = adfGeoTransform[0];
    double maxX = adfGeoTransform[0] + adfGeoTransform[1] * destPixels;
    double maxY = adfGeoTransform[3];
    double minY = adfGeoTransform[3] + adfGeoTransform[5] * destLines;

    // Update line and pixel count to match extent at user-specified resolution
    destPixels = ( int )((( maxX - minX ) / destResX ) + 0.5 );
    destLines  = ( int )((( minY - maxY ) / destResY ) + 0.5 );
    adfGeoTransform[0] = minX;
    adfGeoTransform[3] = maxY;
    adfGeoTransform[1] = destResX;
    adfGeoTransform[5] = destResY;
  }

  if ( !createDestinationDataset( output, hSrcDS, hDstDS, destPixels, destLines,
                                  adfGeoTransform, useZeroAsTrans, compression,
                                  projection ) )
  {
    GDALClose( hSrcDS );
    GDALDestroyWarpOptions( psWarpOptions );
    return false;
  }

  // Create a QT progress dialog
  QProgressDialog *progressDialog = new QProgressDialog( mParent );
  progressDialog->setWindowTitle( tr( "Progress indication" ) );
  progressDialog->setRange( 0, 100 );
  progressDialog->setAutoClose( true );
  progressDialog->setModal( true );
  progressDialog->setMinimumDuration( 0 );

  // Set GDAL callbacks for the progress dialog
  psWarpOptions->pProgressArg = createWarpProgressArg( progressDialog );
  psWarpOptions->pfnProgress  = updateWarpProgress;

  psWarpOptions->hSrcDS = hSrcDS;
  psWarpOptions->hDstDS = hDstDS;

  // Create a transformer which transforms from source to destination pixels (and vice versa)
  psWarpOptions->pfnTransformer  = GeoToPixelTransform;
  psWarpOptions->pTransformerArg = addGeoToPixelTransform( georefTransform.GDALTransformer(),
                                   georefTransform.GDALTransformerArgs(),
                                   adfGeoTransform );

  // Initialize and execute the warp operation.
  GDALWarpOperation oOperation;
  oOperation.Initialize( psWarpOptions );

  progressDialog->show();
  progressDialog->raise();
  progressDialog->activateWindow();

  eErr = oOperation.ChunkAndWarpImage( 0, 0, destPixels, destLines );
//  eErr = oOperation.ChunkAndWarpMulti(0, 0, destPixels, destLines);

  destroyGeoToPixelTransform( psWarpOptions->pTransformerArg );
  GDALDestroyWarpOptions( psWarpOptions );
  delete progressDialog;

  GDALClose( hSrcDS );
  GDALClose( hDstDS );

  return mWarpCanceled ? -1 : eErr == CE_None ? 1 : 0;
}
Ejemplo n.º 6
0
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();
}