예제 #1
0
void FilesystemWidget::ExtractDirectory(const DiscIO::Partition& partition, const QString& path,
                                        const QString& out)
{
  const DiscIO::FileSystem* filesystem = m_volume->GetFileSystem(partition);
  if (!filesystem)
    return;

  std::unique_ptr<DiscIO::FileInfo> info = filesystem->FindFileInfo(path.toStdString());
  u32 size = info->GetTotalChildren();

  QProgressDialog* dialog = new QProgressDialog(this);
  dialog->setMinimum(0);
  dialog->setMaximum(size);
  dialog->show();

  bool all = path.isEmpty();

  DiscIO::ExportDirectory(
      *m_volume, partition, *info, true, path.toStdString(), out.toStdString(),
      [all, dialog](const std::string& current) {
        dialog->setLabelText(
            (all ? QObject::tr("Extracting All Files...") : QObject::tr("Extracting Directory..."))
                .append(QStringLiteral(" %1").arg(QString::fromStdString(current))));
        dialog->setValue(dialog->value() + 1);

        QCoreApplication::processEvents();
        return dialog->wasCanceled();
      });

  dialog->close();
}
예제 #2
0
/*=========================================================================
  _doFileSearch 
=========================================================================*/
void MainWindow::_doFileSearch (const QString &path, const QString &name, 
    const QString &text, KFileList *fileList, QProgressDialog &progress)
  {
  QFileInfo info (path + "/" + name);
  if (info.isDir())
    {
    QStringList entries = QDir(path + "/" + name).entryList();
    int l = entries.count();
    for (int i = 0; i < l; i++)
      {
      QString epath = entries[i]; 
      if (epath != "." && epath != ".." && !progress.wasCanceled())
        {
        int v = progress.value();
        v++;
        if (v == 100) v = 0;
        progress.setValue (v);
        if (name == "")
          _doFileSearch (path, epath, text, fileList, progress);
        else
          _doFileSearch (path, name + "/" + epath, text, fileList, progress);
        }
      }
    }
  else
    {
    if (name.contains (text, Qt::CaseInsensitive))
      fileList->addName (name);
    }
  }
예제 #3
0
bool MainWindow::parseDirectory(QString dirName, parseType type,bool convert,bool create,QProgressDialog &progress)
{
    QFileInfoList list;
    QStringList filter;
    QDir dir(dirName);

    /* create filter list for files */
    filter.append(QString("*.h"));
    filter.append(QString("*.c"));
    filter.append(QString("*.cpp"));
    filter.append(QString("*.cxx"));

    /* parse files in current directory */
    list = dir.entryInfoList(filter,QDir::Files);
    progress.setMaximum(progress.maximum()+list.size());
    for(int i = 0;i<list.size();i++)
    {
        /* increase progress bar */
        progress.setValue(progress.value()+1);

        if(convert)
        {
            if(!parser.converteFile(list.at(i).absoluteFilePath()))
                return false;
        }
        else
        {
            if(!parser.parseFile(list.at(i).absoluteFilePath()))
                return false;
        }

        progress.setLabelText(list.at(i).absoluteFilePath());
    }

    /* go recursive through all the subdiectories */
    list = dir.entryInfoList(QDir::Dirs|QDir::NoDotAndDotDot);
    for(int i = 0;i<list.size();i++)
    {
        if(!parseDirectory(list.at(i).absoluteFilePath(),type,convert,create,progress))
            return false;
    }

    return true;
}
예제 #4
0
void LvlScene::loadUserData(QProgressDialog &progress)
{
    int i, total=0;

    UserBGs uBG;
    UserBlocks uBlock;
    UserBGOs uBGO;
    UserNPCs uNPC;

    bool WrongImagesDetected=false;

    uBGOs.clear();
    uBlocks.clear();
    uNPCs.clear();
    uBGs.clear();

    bool loaded1, loaded2;
    QString uLVLDs = LvlData->path + "/" + LvlData->filename + "/";
    QString uLVLD = LvlData->path + "/" + LvlData->filename;
    QString uLVLs = LvlData->path + "/";


    if(!progress.wasCanceled())
        progress.setLabelText(
                    tr("Search User Backgrounds %1")
                    .arg(QString::number(pConfigs->main_bg.size()) ) );

    qApp->processEvents();
    //Load Backgrounds
    for(i=0; i<pConfigs->main_bg.size(); i++) //Add user images
        {
            loaded1 = false;
            loaded2 = false;

            //check for first image
            if((QFile::exists(uLVLD) ) &&
                  (QFile::exists(uLVLDs + pConfigs->main_bg[i].image_n)) )
            {
                uBG.image = GraphicsHelps::loadPixmap( uLVLDs + pConfigs->main_bg[i].image_n );
                uBG.id = pConfigs->main_bg[i].id;
                if(uBG.image.isNull()) WrongImagesDetected=true;
                loaded1 = true;
            }
            else
            if(QFile::exists(uLVLs + pConfigs->main_bg[i].image_n) )
            {
                uBG.image = GraphicsHelps::loadPixmap( uLVLs + pConfigs->main_bg[i].image_n );
                uBG.id = pConfigs->main_bg[i].id;
                if(uBG.image.isNull()) WrongImagesDetected=true;
                loaded1 = true;
            }

            if((loaded1)&&(pConfigs->main_bg[i].animated) )
            {
                uBG.image=uBG.image.copy(0, 0, uBG.image.width(), (int)round(uBG.image.height()/pConfigs->main_bg[i].frames));
            }

            //check for second image
            if(pConfigs->main_bg[i].type == 1)
            {
                if((QFile::exists(uLVLD) ) &&
                      (QFile::exists(uLVLDs + pConfigs->main_bg[i].second_image_n )) )
                {
                    uBG.second_image = GraphicsHelps::loadPixmap( uLVLDs + pConfigs->main_bg[i].second_image_n );
                    uBG.id = pConfigs->main_bg[i].id;
                    loaded2 = true;
                    if(uBG.second_image.isNull()) WrongImagesDetected=true;
                }
                else
                if(QFile::exists(uLVLs + pConfigs->main_bg[i].second_image_n) )
                {
                    uBG.second_image = GraphicsHelps::loadPixmap( uLVLs + pConfigs->main_bg[i].second_image_n );
                    uBG.id = pConfigs->main_bg[i].id;
                    loaded2 = true;
                    if(uBG.second_image.isNull()) WrongImagesDetected=true;
                }
            }
            if((loaded1)&&(!loaded2)) uBG.q = 0;
            if((!loaded1)&&(loaded2)) uBG.q = 1;
            if((loaded1)&&(loaded2)) uBG.q = 2;


            //If user images found and loaded
            if( (loaded1) || (loaded2) )
                uBGs.push_back(uBG);

        total++;
        if(progress.wasCanceled())
            /*progress.setValue(progress.value()+1);
        else*/ return;
        }

///////////////////////////////////////////////////////////////////////////

    if(!progress.wasCanceled())
    {
        progress.setLabelText(
                    tr("Search User Blocks %1")
                    .arg(QString::number(pConfigs->main_block.size()) ) );
        progress.setValue(progress.value()+1);
    }
    qApp->processEvents();
    //Load Blocks
    for(i=0; i<pConfigs->main_block.size(); i++) //Add user images
    {

        bool custom=false;

            if((QFile::exists(uLVLD) ) &&
                  (QFile::exists(uLVLDs + pConfigs->main_block[i].image_n)) )
            {
                if(QFile::exists(uLVLDs + pConfigs->main_block[i].mask_n))
                    uBlock.mask = GraphicsHelps::loadPixmap( uLVLDs + pConfigs->main_block[i].mask_n );
                else
                    uBlock.mask = pConfigs->main_block[i].mask;

                uBlock.image = GraphicsHelps::setAlphaMask(GraphicsHelps::loadPixmap(uLVLDs + pConfigs->main_block[i].image_n ), uBlock.mask);
                if(uBlock.image.isNull()) WrongImagesDetected=true;

                uBlock.id = pConfigs->main_block[i].id;
                uBlocks.push_back(uBlock);
                custom=true;

                //Apply index;
                if(uBlock.id < (unsigned int)index_blocks.size())
                {
                    index_blocks[uBlock.id].type = 1;
                    //index_blocks[uBlock.id].i = (uBlocks.size()-1);
                }
            }
            else
            if(QFile::exists(uLVLs + pConfigs->main_block[i].image_n) )
            {
                if(QFile::exists(uLVLs + pConfigs->main_block[i].mask_n))
                    uBlock.mask = GraphicsHelps::loadPixmap(uLVLs + pConfigs->main_block[i].mask_n );
                else
                    uBlock.mask = pConfigs->main_block[i].mask;

                uBlock.image = GraphicsHelps::setAlphaMask(GraphicsHelps::loadPixmap(uLVLs + pConfigs->main_block[i].image_n ), uBlock.mask);
                if(uBlock.image.isNull()) WrongImagesDetected=true;

                uBlock.id = pConfigs->main_block[i].id;
                uBlocks.push_back(uBlock);
                custom=true;

                //Apply index;
                if(uBlock.id < (unsigned int)index_blocks.size())
                {
                    index_blocks[uBlock.id].type = 1;
                    //index_blocks[uBlock.id].i = (uBlocks.size()-1);
                }
            }


            int frameFirst;
            int frameLast;

            switch(pConfigs->main_block[i].algorithm)
            {
                case 1: // Invisible block
                {
                    frameFirst = 5;
                    frameLast = 6;
                    break;
                }
                case 3: //Player's character block
                {
                    frameFirst = 0;
                    frameLast = 1;
                    break;
                }
                case 4: //Player's character switch
                {
                    frameFirst = 0;
                    frameLast = 3;
                    break;
                }
                default: //Default block
                {
                    frameFirst = 0;
                    frameLast = -1;
                    break;
                }
            }
            SimpleAnimator * aniBlock = new SimpleAnimator(
                        ((custom)?
                             ((uBlocks.last().image.isNull())?
                                uBgoImg:
                                    uBlocks.last().image)
                                 :
                             ((pConfigs->main_block[i].image.isNull())?
                                uBgoImg:
                                   pConfigs->main_block[i].image)
                             ),
                                  pConfigs->main_block[i].animated,
                                  pConfigs->main_block[i].frames,
                                  pConfigs->main_block[i].framespeed, frameFirst,frameLast,
                                  pConfigs->main_block[i].animation_rev,
                                  pConfigs->main_block[i].animation_bid
                                  );

            animates_Blocks.push_back( aniBlock );
            index_blocks[pConfigs->main_block[i].id].i = i;
            index_blocks[pConfigs->main_block[i].id].ai = animates_Blocks.size()-1;

            #ifdef _DEBUG_
                WriteToLog(QtDebugMsg, QString("BGO Animator ID: %1").arg(index_bgo[pConfigs->main_bgo[i].id].ai));
            #endif

    if(progress.wasCanceled())
        /*progress.setValue(progress.value()+1);
    else*/ return;
    }

///////////////////////////////////////////////////////////////////////////

    if(!progress.wasCanceled())
    {
        progress.setLabelText(
                    tr("Search User BGOs %1")
                    .arg(QString::number(pConfigs->main_bgo.size()) ) );

        progress.setValue(progress.value()+1);
    }
    qApp->processEvents();
    //Load BGO
    for(i=0; i<pConfigs->main_bgo.size(); i++) //Add user images
    {

        bool custom=false;
            if((QFile::exists(uLVLD) ) &&
                  (QFile::exists(uLVLDs + pConfigs->main_bgo[i].image_n)) )
            {
                if(QFile::exists(uLVLDs + pConfigs->main_bgo[i].mask_n))
                    uBGO.mask = GraphicsHelps::loadPixmap(uLVLDs + pConfigs->main_bgo[i].mask_n );
                else
                    uBGO.mask = pConfigs->main_bgo[i].mask;

                uBGO.image = GraphicsHelps::setAlphaMask(GraphicsHelps::loadPixmap(uLVLDs + pConfigs->main_bgo[i].image_n ), uBGO.mask);
                if(uBGO.image.isNull()) WrongImagesDetected=true;

                uBGO.id = pConfigs->main_bgo[i].id;
                uBGOs.push_back(uBGO);
                custom=true;

                //Apply index;
                if(uBGO.id < (unsigned int)index_bgo.size())
                {
                    index_bgo[uBGO.id].type = 1;
                    index_bgo[uBGO.id].i = (uBGOs.size()-1);
                }
            }
            else
            if(QFile::exists(uLVLs + pConfigs->main_bgo[i].image_n) )
            {
                if(QFile::exists(uLVLs + pConfigs->main_bgo[i].mask_n))
                    uBGO.mask = GraphicsHelps::loadPixmap(uLVLs + pConfigs->main_bgo[i].mask_n );
                else
                    uBGO.mask = pConfigs->main_bgo[i].mask;

                uBGO.image = GraphicsHelps::setAlphaMask(GraphicsHelps::loadPixmap(uLVLs + pConfigs->main_bgo[i].image_n ), uBGO.mask);
                if(uBGO.image.isNull()) WrongImagesDetected=true;

                uBGO.id = pConfigs->main_bgo[i].id;
                uBGOs.push_back(uBGO);
                custom=true;

                //Apply index;
                if(uBGO.id < (unsigned int)index_bgo.size())
                {
                    index_bgo[uBGO.id].type = 1;
                    //index_bgo[uBGO.id].i = (uBGOs.size()-1);
                }
            }


            SimpleAnimator * aniBGO = new SimpleAnimator(
                        ((custom)?
                             ((uBGOs.last().image.isNull())?
                                uBgoImg:
                                    uBGOs.last().image)
                                 :
                             ((pConfigs->main_bgo[i].image.isNull())?
                                uBgoImg:
                                   pConfigs->main_bgo[i].image)
                             ),
                                  pConfigs->main_bgo[i].animated,
                                  pConfigs->main_bgo[i].frames,
                                  pConfigs->main_bgo[i].framespeed
                                  );
            animates_BGO.push_back( aniBGO );
            index_bgo[pConfigs->main_bgo[i].id].i = i;
            index_bgo[pConfigs->main_bgo[i].id].ai = animates_BGO.size()-1;
            #ifdef _DEBUG_
                WriteToLog(QtDebugMsg, QString("BGO Animator ID: %1").arg(index_bgo[pConfigs->main_bgo[i].id].ai));
            #endif

        if(progress.wasCanceled())
            /*progress.setValue(progress.value()+1);
        else*/ return;
    }

///////////////////////////////////////////////////////////////////////////


    if(!progress.wasCanceled())
    {
        progress.setLabelText(
                    tr("Search User NPCs %1")
                    .arg(QString::number(pConfigs->main_npc.size()) ) );

        progress.setValue(progress.value()+1);
    }
    qApp->processEvents();

    //Load NPC
    for(i=0; i<pConfigs->main_npc.size(); i++) //Add user images
    {
        if(!progress.wasCanceled())
            progress.setLabelText(
                        tr("Search User NPCs %1")
                        .arg(QString::number(i+1)+"/"+QString::number(pConfigs->main_npc.size()) ) );

             uNPC.withImg = false;
             uNPC.withTxt = false;

             QSize capturedS = QSize(0,0);

             // /////////////////////// Looking for user's NPC.txt ////////////////////////////
             // //(for use custom image filename, need to parse NPC.txt before iamges)/////////
             if((QFile::exists(uLVLD) ) &&
                   (QFile::exists(uLVLDs +
                      "npc-" + QString::number(pConfigs->main_npc[i].id)+".txt") ) )
             {
                QFile file(uLVLDs +
                           "npc-" + QString::number(pConfigs->main_npc[i].id)+".txt");
                if(file.open(QIODevice::ReadOnly))
                {
                    uNPC.sets = FileFormats::ReadNpcTXTFile(file, true);
                    uNPC.id = pConfigs->main_npc[i].id;
                    uNPC.withTxt = true;
                }
             }
             else
             if(QFile::exists(uLVLs +
                              "npc-" + QString::number(pConfigs->main_npc[i].id)+".txt"
                              ) )
             {
                 QFile file(uLVLs +
                            "npc-" + QString::number(pConfigs->main_npc[i].id)+".txt");
                 if(file.open(QIODevice::ReadOnly))
                 {
                     uNPC.sets = FileFormats::ReadNpcTXTFile(file, true);
                     uNPC.id = pConfigs->main_npc[i].id;
                     uNPC.withTxt = true;
                 }
             }

             // ///////////////////////Looking for user's GFX
             if((QFile::exists(uLVLD) ) &&
                   (QFile::exists(uLVLDs + pConfigs->main_npc[i].image_n)) )
             {
                 if(QFile::exists(uLVLDs + pConfigs->main_npc[i].mask_n))
                     uNPC.mask = GraphicsHelps::loadPixmap(uLVLDs + pConfigs->main_npc[i].mask_n );
                 else
                     uNPC.mask = pConfigs->main_npc[i].mask;

                 uNPC.image = GraphicsHelps::setAlphaMask(GraphicsHelps::loadPixmap(uLVLDs + pConfigs->main_npc[i].image_n ), uNPC.mask);
                 if(uNPC.image.isNull()) WrongImagesDetected=true;

                 uNPC.id = pConfigs->main_npc[i].id;
                 uNPC.withImg = true;
             }
             else
             if(QFile::exists(uLVLs + pConfigs->main_npc[i].image_n) )
             {
                 if(QFile::exists(uLVLs + pConfigs->main_npc[i].mask_n))
                     uNPC.mask = GraphicsHelps::loadPixmap(uLVLs + pConfigs->main_npc[i].mask_n );
                 else
                     uNPC.mask = pConfigs->main_npc[i].mask;

                 uNPC.image = GraphicsHelps::setAlphaMask(GraphicsHelps::loadPixmap(uLVLs + pConfigs->main_npc[i].image_n ), uNPC.mask);
                 if(uNPC.image.isNull()) WrongImagesDetected=true;

                 uNPC.id = pConfigs->main_npc[i].id;
                 uNPC.withImg = true;
             }

             if(uNPC.withImg)
             {
                 capturedS = QSize(uNPC.image.width(), uNPC.image.height());
             }

             if(uNPC.withTxt)
             {  //Merge global and user's settings from NPC.txt file
                 uNPC.merged = FileFormats::mergeNPCConfigs(pConfigs->main_npc[i], uNPC.sets, capturedS);
             }
             else
             {
                 if(uNPC.withImg)
                 {
                     NPCConfigFile autoConf = FileFormats::CreateEmpytNpcTXTArray();

                     autoConf.gfxwidth = capturedS.width();
                     //autoConf.en_gfxwidth = true;
                     unsigned int defGFX_h;
                     switch(pConfigs->main_npc[i].framestyle)
                     {
                     case 0:
                         defGFX_h = (int)round(capturedS.height() / pConfigs->main_npc[i].frames);
                         break;
                     case 1:
                         defGFX_h = (int)round((capturedS.height() / pConfigs->main_npc[i].frames)/2 );
                         break;
                     case 2:
                         defGFX_h = (int)round((capturedS.height()/pConfigs->main_npc[i].frames)/4);
                         break;
                     case 3:
                         defGFX_h = (int)round((capturedS.height()/pConfigs->main_npc[i].frames)/4);
                         break;
                     case 4:
                         defGFX_h = (int)round((capturedS.height()/pConfigs->main_npc[i].frames)/8);
                         break;
                     default:
                         defGFX_h=0;
                         break;
                     }

                     capturedS.setHeight(defGFX_h);

                     uNPC.merged = FileFormats::mergeNPCConfigs(
                                 pConfigs->main_npc[i],
                                 autoConf, capturedS);
                 }

             }

             //Apply only if custom config or image was found
             if((uNPC.withImg)||(uNPC.withTxt))
             {
                 uNPCs.push_back(uNPC);
                 //Apply index;
                 if(uNPC.id < (unsigned int)index_npc.size())
                 {
                     index_npc[uNPC.id].type = 1;
                     index_npc[uNPC.id].i = (uNPCs.size()-1);
                 }
             }
         if(progress.wasCanceled())
             /*progress.setValue(progress.value()+1);
         else*/ return;
     }

    progress.setValue(progress.value()+1);
    qApp->processEvents();

    //Notification about wrong custom image sprites
    if(WrongImagesDetected)
    {
        QMessageBox * msg = new QMessageBox();
        msg->setWindowFlags(msg->windowFlags() | Qt::WindowStaysOnTopHint);
        msg->setWindowTitle(tr("Wrong custom images"));
        msg->setText(tr("This level have a wrong custom graphics files.\nYou will see 'ghosties' or other dummy images instead custom GFX of items, what used broken images. It occurred because, for example, the BMP format with GIF extension was used.\nPlease, reconvert your images to valid format and try to reload this level."));
        msg->addButton(QMessageBox::Ok);
        msg->setIcon(QMessageBox::Warning);

        msg->exec();
    }
}
예제 #5
0
void Demo::DialogTimerFired() {
  QProgressDialog* dialog = qobject_cast<QProgressDialog*>(sender()->parent());
  dialog->setValue((dialog->value() + 4) % dialog->maximum());
}
예제 #6
0
bool QgsShapeFile::insertLayer( QString dbname, QString schema, QString primary_key, QString geom_col,
                                QString srid, PGconn * conn, QProgressDialog& pro, bool &fin,
                                QString& errorText )
{
  connect( &pro, SIGNAL( canceled() ), this, SLOT( cancelImport() ) );
  import_canceled = false;
  bool result = true;

  QString query = QString( "CREATE TABLE %1.%2(%3 int4 PRIMARY KEY" )
                  .arg( QgsPgUtil::quotedIdentifier( schema ) )
                  .arg( QgsPgUtil::quotedIdentifier( table_name ) )
                  .arg( QgsPgUtil::quotedIdentifier( primary_key ) );

  for ( uint n = 0; n < column_names.size() && result; n++ )
  {
    query += QString( ",%1 %2" )
             .arg( QgsPgUtil::quotedIdentifier( column_names[n] ) )
             .arg( column_types[n] );
  }
  query += " )";

  QgsDebugMsg( "Query string is: " + query );

  PGresult *res = PQexec( conn, query.toUtf8() );

  if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
  {
    // flag error and send query and error message to stdout on debug
    errorText += tr( "The database gave an error while executing this SQL:" ) + "\n";
    errorText += query + '\n';
    errorText += tr( "The error was:" ) + "\n";
    errorText += PQresultErrorMessage( res ) + '\n';
    PQclear( res );
    return false;
  }
  else
  {
    PQclear( res );
  }

  query = QString( "SELECT AddGeometryColumn(%1,%2,%3,%4,%5,2)" )
          .arg( QgsPgUtil::quotedValue( schema ) )
          .arg( QgsPgUtil::quotedValue( table_name ) )
          .arg( QgsPgUtil::quotedValue( geom_col ) )
          .arg( srid )
          .arg( QgsPgUtil::quotedValue( geom_type ) );

  res = PQexec( conn, query.toUtf8() );

  if ( PQresultStatus( res ) != PGRES_TUPLES_OK )
  {
    errorText += tr( "The database gave an error while executing this SQL:" ) + "\n";

    errorText += query + '\n';
    errorText += tr( "The error was:" ) + "\n";
    errorText += PQresultErrorMessage( res ) + '\n';
    PQclear( res );
    return false;
  }
  else
  {
    PQclear( res );
  }

  if ( isMulti )
  {
    query = QString( "select constraint_name from information_schema.table_constraints where table_schema=%1 and table_name=%2 and constraint_name in ('$2','enforce_geotype_the_geom')" )
            .arg( QgsPgUtil::quotedValue( schema ) )
            .arg( QgsPgUtil::quotedValue( table_name ) );

    QStringList constraints;
    res = PQexec( conn, query.toUtf8() );
    if ( PQresultStatus( res ) == PGRES_TUPLES_OK )
    {
      for ( int i = 0; i < PQntuples( res ); i++ )
        constraints.append( PQgetvalue( res, i, 0 ) );
    }
    PQclear( res );

    if ( constraints.size() > 0 )
    {
      // drop the check constraint
      // TODO This whole concept needs to be changed to either
      // convert the geometries to the same type or allow
      // multiple types in the check constraint. For now, we
      // just drop the constraint...
      query = QString( "alter table %1 drop constraint %2" )
              .arg( QgsPgUtil::quotedIdentifier( table_name ) )
              .arg( QgsPgUtil::quotedIdentifier( constraints[0] ) );

      res = PQexec( conn, query.toUtf8() );
      if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
      {
        errorText += tr( "The database gave an error while executing this SQL:" ) + "\n";
        errorText += query + '\n';
        errorText += tr( "The error was:" ) + "\n";
        errorText += PQresultErrorMessage( res ) + '\n';
        PQclear( res );
        return false;
      }

      PQclear( res );
    }

  }

  //adding the data into the table
  for ( int m = 0; m < features && result; m++ )
  {
    if ( import_canceled )
    {
      fin = true;
      break;
    }

    OGRFeatureH feat = OGR_L_GetNextFeature( ogrLayer );
    if ( feat )
    {
      OGRGeometryH geom = OGR_F_GetGeometryRef( feat );
      if ( geom )
      {
        query = QString( "INSERT INTO %1.%2 VALUES(%3" )
                .arg( QgsPgUtil::quotedIdentifier( schema ) )
                .arg( QgsPgUtil::quotedIdentifier( table_name ) )
                .arg( m );

        char *geo_temp;
        // 'GeometryFromText' supports only 2D coordinates
        // TODO for proper 2.5D support we would need to use 'GeomFromEWkt'
        if ( hasMoreDimensions )
          OGR_G_SetCoordinateDimension( geom, 2 );
        OGR_G_ExportToWkt( geom, &geo_temp );
        QString geometry( geo_temp );
        CPLFree( geo_temp );

        for ( uint n = 0; n < column_types.size(); n++ )
        {
          QString val;

          // FIXME: OGR_F_GetFieldAsString returns junk when called with a 8.255 float field
          if ( column_types[n] == "float" )
            val = QString::number( OGR_F_GetFieldAsDouble( feat, n ) );
          else
            val = codec->toUnicode( OGR_F_GetFieldAsString( feat, n ) );

          if ( val.isEmpty() )
            val = "NULL";
          else
            val = QgsPgUtil::quotedValue( val );

          query += "," + val;
        }
        query += QString( ",GeometryFromText(%1,%2))" )
                 .arg( QgsPgUtil::quotedValue( geometry ) )
                 .arg( srid );

        if ( result )
          res = PQexec( conn, query.toUtf8() );

        if ( PQresultStatus( res ) != PGRES_COMMAND_OK )
        {
          // flag error and send query and error message to stdout on debug
          result = false;
          errorText += tr( "The database gave an error while executing this SQL:" ) + "\n";
          // the query string can be quite long. Trim if necessary...
          if ( query.count() > 100 )
            errorText += query.left( 150 ) +
                         tr( "... (rest of SQL trimmed)", "is appended to a truncated SQL statement" ) +
                         "\n";
          else
            errorText += query + '\n';
          errorText += tr( "The error was:" ) + "\n";
          errorText += PQresultErrorMessage( res );
          errorText += '\n';
        }
        else
        {
          PQclear( res );
        }

        pro.setValue( pro.value() + 1 );
        qApp->processEvents();
      }
      OGR_F_Destroy( feat );
    }
  }
  // create the GIST index if the the load was successful
  if ( result )
  {
    // prompt user to see if they want to build the index and warn
    // them about the potential time-cost
  }
  OGR_L_ResetReading( ogrLayer );
  return result;
}
예제 #7
0
bool WLD_SetPoint::DrawObjects(QProgressDialog &progress)
{
    //int DataSize = progress.maximum();
    int TotalSteps = 5;

        if(!progress.wasCanceled())

            progress.setLabelText(tr("1/%1 Loading user data").arg(TotalSteps));

    qApp->processEvents();
    scene->loadUserData(progress);

        if(progress.wasCanceled()) return false;

        if(!progress.wasCanceled())
            progress.setLabelText(tr("1/%1 Applying Tiles").arg(TotalSteps));

    progress.setValue(progress.value()+1);
    qApp->processEvents();
    scene->setTiles(progress);

        if(progress.wasCanceled()) return false;

        if(!progress.wasCanceled())
            progress.setLabelText(tr("2/%1 Applying Sceneries...").arg(TotalSteps));

    progress.setValue(progress.value()+1);
    qApp->processEvents();
    scene->setSceneries(progress);

        if(progress.wasCanceled()) return false;

        if(!progress.wasCanceled())
            progress.setLabelText(tr("3/%1 Applying Paths...").arg(TotalSteps));

    progress.setValue(progress.value()+1);
    qApp->processEvents();
    scene->setPaths(progress);

        if(progress.wasCanceled()) return false;

        if(!progress.wasCanceled())
            progress.setLabelText(tr("4/%1 Applying Levels...").arg(TotalSteps));

    progress.setValue(progress.value()+1);
    progress.setValue(progress.value()+1);
    qApp->processEvents();
    scene->setLevels(progress);

        if(progress.wasCanceled()) return false;

        if(!progress.wasCanceled())
            progress.setLabelText(tr("5/%1 Applying Musics...").arg(TotalSteps));

    progress.setValue(progress.value()+1);
    qApp->processEvents();

    scene->setMusicBoxes(progress);

        if(progress.wasCanceled()) return false;

    if(scene->opts.animationEnabled)
        scene->startAnimation(); //Apply block animation

    if(!sceneCreated)
    {
        ui->graphicsView->setScene(scene);
        sceneCreated = true;
    }
    if(!progress.wasCanceled())
        progress.setValue(progress.maximum());
    return true;
}