Loading ...
Sorry, an error occurred while loading the content.

Bugreport: problems with xAxis and yAxis on QDrawWidget

Expand Messages
  • landratte71
    Hello, I m drawing charcteristics using a QDrawWidget. Depending on the value range I get overlapping text for xAxis and yAxis. I think the the static function
    Message 1 of 7 , Mar 3, 2012
    View Source
    • 0 Attachment
      Hello,

      I'm drawing charcteristics using a QDrawWidget.
      Depending on the value range I get overlapping text for xAxis and yAxis.

      I think the the static function "beautyval" in the file QDrawWidget.cpp is not working properly!

      I changed the variable "floatFormat" to "%.1f", so beautyval is not applied anymore!

      ciao
      landratte
    • pvbrowser
      ... Thank you for the report. I will review the function. Always printing only 1 digit behind the . might not be OK for everyone.
      Message 2 of 7 , Mar 3, 2012
      View Source
      • 0 Attachment
        > I'm drawing charcteristics using a QDrawWidget.
        > Depending on the value range I get overlapping text for
        > xAxis and yAxis.
        >
        > I think the the static function "beautyval" in the file
        > QDrawWidget.cpp is not working properly!
        >
        > I changed the variable "floatFormat" to "%.1f",
        > so beautyval is not applied anymore!

        Thank you for the report.
        I will review the function.

        Always printing only 1 digit behind the . might not be OK for everyone.
      • pvbrowser
        Please try if this code at the end of beautyval would be ok for you. while(i 0) { i--; if(text[i] == 0 ) text[i] = 0 ; else if(text[i] == . ) { text[i] =
        Message 3 of 7 , Mar 3, 2012
        View Source
        • 0 Attachment
          Please try if this code at the end of beautyval would be ok for you.

          while(i>0)
          {
          i--;
          if(text[i] == '0') text[i] = '\0';
          else if(text[i] == '.')
          {
          text[i] = '\0';
          return 0;
          }
          else
          {
          if(strchr(text,'.') != NULL)
          {
          float fval = atof(text);
          if (fval > 9.99f) sprintf(text,"%.1f", fval);
          else if(fval < -9.99f) sprintf(text,"%.1f", fval);
          }
          return 0;
          }
          }
        • landratte71
          input: 123.99 output: 123.98173 (not ok) input: 123.998 output: 124.0 (ok) input: 0.7898 output 0.7898 (not ok) input: 12.45 output: 12.4 (not ok) input: 12.46
          Message 4 of 7 , Mar 4, 2012
          View Source
          • 0 Attachment
            input: 123.99
            output: 123.98173 (not ok)

            input: 123.998
            output: 124.0 (ok)

            input: 0.7898
            output 0.7898 (not ok)

            input: 12.45
            output: 12.4 (not ok)

            input: 12.46
            output: 12.5 (ok)

            --- In pvbrowser@yahoogroups.com, "pvbrowser" <pvbrowser@...> wrote:
            >
            >
            >
            > Please try if this code at the end of beautyval would be ok for you.
            >
            > while(i>0)
            > {
            > i--;
            > if(text[i] == '0') text[i] = '\0';
            > else if(text[i] == '.')
            > {
            > text[i] = '\0';
            > return 0;
            > }
            > else
            > {
            > if(strchr(text,'.') != NULL)
            > {
            > float fval = atof(text);
            > if (fval > 9.99f) sprintf(text,"%.1f", fval);
            > else if(fval < -9.99f) sprintf(text,"%.1f", fval);
            > }
            > return 0;
            > }
            > }
            >
          • pvbrowser
            Oh, in our pvslib there is already a function to influence the float format used for labels. //after gBeginDraw (p, id); //call something like
            Message 5 of 7 , Mar 4, 2012
            View Source
            • 0 Attachment
              Oh, in our pvslib there is already a function to influence the float format used for labels.

              //after
              gBeginDraw (p, id);
              //call something like
              gSetFloatFormat(p, "%.2f");

              But nevertheless i have made beautyval now very simple:
              static int beautyval(char *text)
              {
              char *cptr = strchr(text,'.');
              if(cptr != NULL)
              {
              char *end = cptr + strlen(text) - 1;
              while(end != cptr) // eliminate trailing 0
              {
              if (*end == '0') { *end = '\0'; }
              else if(*end == '.') { *end = '\0'; break; }
              end--;
              }
              }
              return 0;
              }

              You can find the updated version within the git repository.
              There is also a small modification for the default floatFormat.
            • pvbrowser
              This had been to quick. The code is now as follows. Within the last post there was a bug. static int beautyval(char *text) { char *cptr = strchr(text, . );
              Message 6 of 7 , Mar 4, 2012
              View Source
              • 0 Attachment
                This had been to quick.
                The code is now as follows.
                Within the last post there was a bug.

                static int beautyval(char *text)
                {
                char *cptr = strchr(text,'.');
                if(cptr != NULL)
                {
                char *end = cptr + strlen(cptr) - 1;
                while(end != cptr) // eliminate trailing 0
                {
                if (*end == '0') { *end = '\0'; }
                else if(*end == '.') { *end = '\0'; break; }
                else { break; }
                end--;
                }
                if(cptr == end) *cptr = '\0';
                }
                return 0;
                }
              • landratte71
                I m fine with gSetFloatFormat. Thx Landratte
                Message 7 of 7 , Mar 5, 2012
                View Source
                • 0 Attachment
                  I'm fine with gSetFloatFormat.

                  Thx
                  Landratte

                  --- In pvbrowser@yahoogroups.com, "pvbrowser" <pvbrowser@...> wrote:
                  >
                  > This had been to quick.
                  > The code is now as follows.
                  > Within the last post there was a bug.
                  >
                  > static int beautyval(char *text)
                  > {
                  > char *cptr = strchr(text,'.');
                  > if(cptr != NULL)
                  > {
                  > char *end = cptr + strlen(cptr) - 1;
                  > while(end != cptr) // eliminate trailing 0
                  > {
                  > if (*end == '0') { *end = '\0'; }
                  > else if(*end == '.') { *end = '\0'; break; }
                  > else { break; }
                  > end--;
                  > }
                  > if(cptr == end) *cptr = '\0';
                  > }
                  > return 0;
                  > }
                  >
                Your message has been successfully submitted and would be delivered to recipients shortly.