void NumberEdit::texttChanged(const QString& text) { QString in=text; if (!suffix.isEmpty()) { if (text.endsWith(suffix)) { in=in.remove(text.size()-suffix.size(), suffix.size()); } } double d=extractVal(text); setViewOK(); if ((checkMax) && (d>max)) { d=max; setViewError(); }//setValue(d);} if ((checkMin) && (d<min)) { d=min; setViewError(); }//setValue(d); } //std::cout<<d<<std::endl; //QMessageBox::information(this, "", QString("value is %1").arg(d)); else emit valueChanged(d); if ((!suffix.isEmpty()) && (!text.contains(suffix))) { int cp=cursorPosition(); setText(text+suffix); setCursorPosition(cp); } }
void NumberEdit::setValue(double value) { double v=value; if (v!=0 && v==extractVal(text())) return; if (checkMin) if (v<min) v=min; if (checkMax) if (v>max) v=max; QString t; t.setNum(v, 'f', decimals); setText(t+suffix); setViewOK(); }
double NumberEdit::value() { double d=extractVal(text()); return d; }
static void loadTable() { // // Just loop, reading lines at a time, until we either find the start // of the character table or hit the end of the file. Along the way, we // should see a few header values that we store away. // const unsigned int tmpBufSz = 2048; char tmpBuf[tmpBufSz - 1]; while (getLine(tmpBuf, tmpBufSz)) { // // Check for one of the special values we are intersted int. If // its CHARMAP, then we fall out of this loop. // if (!strcmp(tmpBuf, "CHARMAP")) break; if (!strncmp(tmpBuf, "<mb_cur_max>", 12)) { gMaxChar = extractVal(&tmpBuf[12]); } else if (!strncmp(tmpBuf, "<mb_cur_min>", 12)) { gMinChar = extractVal(&tmpBuf[12]); } else if (!strncmp(tmpBuf, "<subchar>", 9)) { gRepChar = (char)extractVal(&tmpBuf[9]); } } // // Ok, now we just run till we hit the "END CHARMAP" line. Each entry // will be in the form: // // <UXXXX> \xXX // // Where X is a hex number. // char* endPtr; while (getLine(tmpBuf, tmpBufSz)) { // Watch for the end of table if (!strcmp(tmpBuf, "END CHARMAP")) break; // The absolute minium it could be is 12 chars if (strlen(tmpBuf) < 12) { cout << "Line " << fLineNum << " is too short to hold a valid entry" << endl; exit(1); } // Make sure the first token meets the criteria if ((tmpBuf[0] != '<') || (tmpBuf[1] != 'U') || (tmpBuf[6] != '>')) { cout << "Line " << fLineNum << " has a badly formed Unicode value" << endl; exit(1); } // // Looks reasonable so lets try to convert it. We can play tricks // with this buffer, so put a null over the > char. // tmpBuf[6] = 0; const unsigned int uniVal = strtoul(&tmpBuf[2], &endPtr, 16); if (*endPtr) { cout << "Invalid Unicode value on line " << fLineNum << endl; exit(1); } // // Ok, lets search over to the second token. We have to find a \\ // character. // char* srcPtr = &tmpBuf[7]; while (*srcPtr && (*srcPtr != '\\')) srcPtr++; // If we never found it, its in error if (!*srcPtr) { cout << "Never found second token on line " << fLineNum << endl; exit(1); } // Try to translate it srcPtr += 2; const unsigned int cpVal = strtoul(srcPtr, &endPtr, 16); if (*endPtr) { cout << "Invalid code page value on line " << fLineNum << endl; exit(1); } // Make sure that the values are within range if (uniVal > 0xFFFF) { cout << "Unicode value is too big on line " << fLineNum << endl; exit(1); } if (cpVal > 0xFF) { cout << "Code page value is too big on line " << fLineNum << endl; exit(1); } // Looks reasonable, so add a new entry to the global table gMainTable[gMainTableSz].uniVal = (unsigned short)uniVal; gMainTable[gMainTableSz].cpVal = (unsigned char)cpVal; gMainTableSz++; } }