Results 1 to 5 of 5

Thread: How to execute a QProgressDialog once

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to execute a QProgressDialog once

    Hi to all,
    I created a QProgressDialog to inform the user about waveform generation.
    The problem is that everytime the widget is repainted ( for example with a resize event ) the waveform is re-calculated and the QProgressDialog
    is shown. I would display that progress dialog only the first time that I display the waveform.

    Is there a way to do that? How can such dialog can be disabled?

    Regards
    Franco Amato

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to execute a QProgressDialog once

    Please show us your current code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to execute a QProgressDialog once

    Quote Originally Posted by wysota View Post
    Please show us your current code.
    Here it go

    Qt Code:
    1. /************************************************************************/
    2. /* drawStandardPCM16 */
    3. /************************************************************************/
    4. void WaveDisplay::drawStandardPCM16( QPainter& painter, int numSamples )
    5. {
    6. int h = height();
    7. int w = width();
    8.  
    9. // Calculate magical constants that should be left untouched unless dealing with
    10. // other variants of PCM-Streams.
    11. int channels = m_wave->getChannels();
    12. int bits = m_wave->getBits();
    13. int pcm_length = m_wave->getPcmLength();
    14. int freq = m_wave->getFrequency();
    15.  
    16. int sample_size = channels * bits / 8;
    17.  
    18. int samples = pcm_length / sample_size; //pcm_length bytes totali del sound
    19. int maxHeight = (h / 2) / channels;
    20. int increment = (h / 2);
    21. float modifier = (float)maxHeight / 0x0000FFFF * 2;
    22. int* minValues = new int[channels];
    23. int* maxValues = new int[channels];
    24.  
    25. //Adjust these values to obtain a different drawing scheme. Offset defines the initial sample
    26. //where to begin drawing (it takes into account channel, sample size, bit size etc). maxSamplesOnscreen
    27. //defines the amount of samples displayed on the screen.
    28. int startOffset = 0;
    29. int maxSamplesOnscreen = samples;
    30.  
    31. // Calculate the starting position in the stream where start fetching our data. And calculate
    32. // the width between samples. By default the width truncated to the nearest integer for drawing.
    33. // Note: doubles are needed for this calculation due floating point in-precision. Floating point
    34. // operations have the same speed either so it's quite valid.
    35. char* stream = (char*)m_wave->getSoundStream() + (startOffset * sample_size);
    36. double samplesInc = 1.0f / ( maxSamplesOnscreen / (double)w);
    37. double samplesCur = 0.0f;
    38.  
    39. //Correct the maximum samples displayed on the screen, if this step is not done we'ld be
    40. //drawing outside the boundaries of the data stream.
    41. maxSamplesOnscreen = (samples - startOffset) > maxSamplesOnscreen ? maxSamplesOnscreen : (samples - startOffset);
    42.  
    43. QProgressDialog *progress = new QProgressDialog("Creating waveform...",
    44. "Abort process", 0, maxSamplesOnscreen, this);
    45. progress->setWindowModality(Qt::WindowModal);
    46.  
    47. //Iterate over each sample that lies withing the lower and upper boundaries that we precomputed. For
    48. //every sample we draw the maximum value, and minimum value. Store the value in a temp. array and process that
    49. //array once we detect our x is changed.
    50. for( int i = startOffset, maxI = i + maxSamplesOnscreen, oldX = 0, x = 0; i < maxI; i++, stream += sample_size, samplesCur += samplesInc, x = samplesCur)
    51. {
    52. if( i % (60 * freq) == 0 ) //every minute
    53. {
    54. m_timePosition.append(i);// qua dovrei anche aggiungere i minuti, magari con una map
    55. }
    56. //Analyze the raw stream of data to determine the min and max amplitude of the sound.
    57. for( int k = 0, j = 0; k < channels; k++, j += 2 )
    58. {
    59. signed short* value1 = reinterpret_cast<signed short*>(stream + j);
    60. int y = *value1 * modifier;
    61. maxValues[k] = y > maxValues[k] ? y : maxValues[k];
    62. minValues[k] = y < minValues[k] ? y : minValues[k];
    63. }
    64.  
    65. //Early out of x is the same
    66. if( oldX == x)
    67. continue;
    68. oldX = x;
    69. progress->setValue(i);
    70.  
    71. //Draw the peaks from midpoint to upper peak, and from midpoint to lower peaks
    72. for( int k = 0, startY = maxHeight; k < channels; k++ )
    73. {
    74. QPoint midPoint = QPoint(x, startY);
    75. painter.drawLine( midPoint, QPoint(x, startY + maxValues[k]) );
    76. painter.drawLine( midPoint, QPoint(x, startY + minValues[k]) );
    77. maxValues[k] = minValues[k] = 0;
    78. startY += increment;
    79. }
    80. }
    81. progress->setValue( maxSamplesOnscreen );
    82. progress->deleteLater();
    83.  
    84. //Draw a mid-based line for each channel around, so there is always 'signal displayed' used against
    85. //double point in-precision.
    86. for( int k = 0, startY = maxHeight; k < channels; k++ )
    87. {
    88. painter.drawLine( QPoint(0, startY), QPoint(w, startY) );
    89. startY += increment;
    90. }
    91.  
    92. //Clean up the outline tables for min and max values.
    93. delete minValues;
    94. delete maxValues;
    95. }
    To copy to clipboard, switch view to plain text mode 
    Franco Amato

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to execute a QProgressDialog once

    Why not have a boolean variable which will say whether this wave form has been calculated before and show the dialog only when it is set to false (and set it to true after showing the dialog)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to execute a QProgressDialog once

    Quote Originally Posted by wysota View Post
    Why not have a boolean variable which will say whether this wave form has been calculated before and show the dialog only when it is set to false (and set it to true after showing the dialog)?
    This can be an idea. But I have to hide all code of the qprogressdialog inside the boolean check? Or only a part?
    Franco Amato

Similar Threads

  1. Need help in QProgressDialog
    By santhoshv84 in forum Qt Programming
    Replies: 3
    Last Post: 12th September 2008, 18:24
  2. QProgressDialog
    By samirg in forum Qt Programming
    Replies: 5
    Last Post: 5th September 2007, 16:37
  3. QProgressDialog and the events
    By chaosgeorge in forum Qt Programming
    Replies: 1
    Last Post: 26th November 2006, 09:22
  4. qprogressDialog
    By mickey in forum Qt Programming
    Replies: 5
    Last Post: 17th July 2006, 14:16
  5. setLabel in QprogressDialog
    By mickey in forum Newbie
    Replies: 5
    Last Post: 12th July 2006, 11:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.