Wed, 16 Oct 2013 23:20:35 +0300
removed some custom functions in favor of Qt implementations
src/file.cpp | file | annotate | diff | comparison | revisions | |
src/gui.cpp | file | annotate | diff | comparison | revisions | |
src/gui_editactions.cpp | file | annotate | diff | comparison | revisions | |
src/ldconfig.cpp | file | annotate | diff | comparison | revisions | |
src/misc.cpp | file | annotate | diff | comparison | revisions | |
src/misc.h | file | annotate | diff | comparison | revisions | |
src/primitives.cpp | file | annotate | diff | comparison | revisions | |
src/types.cpp | file | annotate | diff | comparison | revisions |
--- a/src/file.cpp Wed Oct 16 23:07:59 2013 +0300 +++ b/src/file.cpp Wed Oct 16 23:20:35 2013 +0300 @@ -637,7 +637,7 @@ #define CHECK_TOKEN_NUMBERS(MIN, MAX) \ for (int i = MIN; i <= MAX; ++i) \ - if (!isNumber (tokens[i])) \ + if (!numeric (tokens[i])) \ return new LDError (line, fmt ("Token #%1 was `%2`, expected a number", (i + 1), tokens[i])); // ============================================================================= @@ -645,8 +645,8 @@ static vertex parseVertex (QStringList& s, const int n) { vertex v; -for (const Axis ax : g_Axes) - v[ax] = atof (s[n + ax]); + for (const Axis ax : g_Axes) + v[ax] = s[n + ax].toDouble(); return v; }
--- a/src/gui.cpp Wed Oct 16 23:07:59 2013 +0300 +++ b/src/gui.cpp Wed Oct 16 23:20:35 2013 +0300 @@ -281,18 +281,17 @@ ui->objectList->clear(); -for (LDObject * obj : LDFile::current()->objects()) + for (LDObject* obj : LDFile::current()->objects()) { str descr; switch (obj->getType()) { case LDObject::Comment: - descr = static_cast<LDComment*> (obj)->text; + { descr = static_cast<LDComment*> (obj)->text; // Remove leading whitespace while (descr[0] == ' ') descr.remove (0, 1); - - break; + } break; case LDObject::Empty: break; // leave it empty @@ -301,41 +300,36 @@ case LDObject::Triangle: case LDObject::Quad: case LDObject::CndLine: - - for (short i = 0; i < obj->vertices(); ++i) + { for (short i = 0; i < obj->vertices(); ++i) { if (i != 0) descr += ", "; descr += obj->getVertex (i).stringRep (true); } - - break; + } break; case LDObject::Error: - descr = fmt ("ERROR: %1", obj->raw()); - break; + { descr = fmt ("ERROR: %1", obj->raw()); + } break; case LDObject::Vertex: - descr = static_cast<LDVertex*> (obj)->pos.stringRep (true); - break; + { descr = static_cast<LDVertex*> (obj)->pos.stringRep (true); + } break; case LDObject::Subfile: { LDSubfile* ref = static_cast<LDSubfile*> (obj); - descr = fmt ("%1 %2, (", ref->fileInfo()->name(), - ref->position().stringRep (true)); + descr = fmt ("%1 %2, (", ref->fileInfo()->name(), ref->position().stringRep (true)); - for (short i = 0; i < 9; ++i) - descr += fmt ("%1%2", ftoa (ref->transform() [i]), - (i != 8) ? " " : ""); + for (int i = 0; i < 9; ++i) + descr += fmt ("%1%2", ref->transform()[i], (i != 8) ? " " : ""); descr += ')'; - } - break; + } break; case LDObject::BFC: - descr = LDBFC::statements[static_cast<LDBFC*> (obj)->type]; - break; + { descr = LDBFC::statements[static_cast<LDBFC*> (obj)->type]; + } break; case LDObject::Overlay: { LDOverlay* ovl = static_cast<LDOverlay*> (obj); @@ -345,8 +339,8 @@ break; default: - descr = obj->typeName(); - break; + { descr = obj->typeName(); + } break; } // Put it into brackets if it's hidden @@ -360,9 +354,8 @@ if (obj->getType() == LDObject::Error) { item->setBackground (QColor ("#AA0000")); item->setForeground (QColor ("#FFAA00")); - } elif (lv_colorize && obj->isColored() && - - obj->color() != maincolor && obj->color() != edgecolor) + } + elif (lv_colorize && obj->isColored() && obj->color() != maincolor && obj->color() != edgecolor) { // If the object isn't in the main or edge color, draw this // list entry in said color. LDColor* col = getColor (obj->color()); @@ -408,8 +401,8 @@ m_sel.clear(); const QList<QListWidgetItem*> items = ui->objectList->selectedItems(); -for (LDObject * obj : LDFile::current()->objects()) - for (QListWidgetItem * item : items) + for (LDObject* obj : LDFile::current()->objects()) + for (QListWidgetItem* item : items) { if (item == obj->qObjListEntry) { m_sel << obj; break; @@ -417,12 +410,12 @@ } // Update the GL renderer -for (LDObject * obj : priorSelection) + for (LDObject* obj : priorSelection) { obj->setSelected (false); m_renderer->compileObject (obj); } -for (LDObject * obj : m_sel) + for (LDObject* obj : m_sel) { obj->setSelected (true); m_renderer->compileObject (obj); }
--- a/src/gui_editactions.cpp Wed Oct 16 23:07:59 2013 +0300 +++ b/src/gui_editactions.cpp Wed Oct 16 23:20:35 2013 +0300 @@ -507,20 +507,21 @@ int num = 0; for (LDObject* obj : g_win->sel()) - for (short i = 0; i < obj->vertices(); ++i) + { for (short i = 0; i < obj->vertices(); ++i) { vertex v = obj->getVertex (i); - for (const Axis ax : g_Axes) + for (const Axis ax : g_Axes) { // HACK: .. should find a better way to do this - char valstr[64]; - sprintf (valstr, "%.3f", v[ax]); - v[ax] = atof (valstr); + str valstr; + valstr.sprintf ("%.3f", v[ax]); + v[ax] = valstr.toDouble(); } obj->setVertex (i, v); g_win->R()->compileObject (obj); num += 3; } + } log (ForgeWindow::tr ("Rounded %1 coordinates"), num); g_win->refresh();
--- a/src/ldconfig.cpp Wed Oct 16 23:07:59 2013 +0300 +++ b/src/ldconfig.cpp Wed Oct 16 23:20:35 2013 +0300 @@ -72,7 +72,7 @@ if (!parseLDConfigTag (pars, "CODE", valuestr)) continue; - if (!isNumber (valuestr)) + if (!numeric (valuestr)) continue; // not a number // Ensure that the code is within [0 - 511]
--- a/src/misc.cpp Wed Oct 16 23:07:59 2013 +0300 +++ b/src/misc.cpp Wed Oct 16 23:20:35 2013 +0300 @@ -128,33 +128,8 @@ } // ============================================================================= -// Float to string. Removes trailing zeroes and is locale-independant. -// TODO: Replace with QString::number() // ----------------------------------------------------------------------------- -str ftoa (double num) -{ // Disable the locale first so that the decimal point will not - // turn into anything weird (like commas) - setlocale (LC_NUMERIC, "C"); - - str rep; - rep.sprintf ("%f", num); - - // Remove trailing zeroes - while (rep.right (1) == "0") - rep.chop (1); - - // If there were only zeroes in the decimal place, remove - // the decimal point now. - if (rep.right (1) == ".") - rep.chop (1); - - return rep; -} - -// ============================================================================= -// TODO: I guess Qt must have something like this stashed somewhere? -// ----------------------------------------------------------------------------- -bool isNumber (const str& tok) +bool numeric (const str& tok) { bool gotDot = false; for (int i = 0; i < tok.length(); ++i) @@ -283,28 +258,6 @@ } // ============================================================================= -// TODO: I'm quite sure Qt has this covered as well. -// ----------------------------------------------------------------------------- -double atof (str val) -{ // Disable the locale while parsing the line or atof's behavior changes - // between locales (i.e. fails to read decimals properly). That is - // quite undesired... - setlocale (LC_NUMERIC, "C"); - - char* buf = new char[val.length()]; - char* bufptr = &buf[0]; - - for (QChar& c : val) - *bufptr++ = c.toLatin1(); - - *bufptr = '\0'; - - double fval = atof (buf); - delete[] buf; - return fval; -} - -// ============================================================================= // This is the main algorithm of the ring finder. It tries to use math to find // the one ring between r0 and r1. If it fails (the ring number is non-integral), // it finds an intermediate radius (ceil of the ring number times scale) and
--- a/src/misc.h Wed Oct 16 23:07:59 2013 +0300 +++ b/src/misc.h Wed Oct 16 23:20:35 2013 +0300 @@ -33,12 +33,7 @@ extern const int g_primes[NUM_PRIMES]; // Returns whether a given string represents a floating point number. -bool isNumber (const str& tok); - -// Converts a float value to a string value. -str ftoa (double num); - -double atof (str val); +bool numeric (const str& tok); // Simplifies the given fraction. void simplify (int& numer, int& denom);
--- a/src/primitives.cpp Wed Oct 16 23:07:59 2013 +0300 +++ b/src/primitives.cpp Wed Oct 16 23:20:35 2013 +0300 @@ -498,7 +498,7 @@ // ----------------------------------------------------------------------------- LDFile* generatePrimitive (PrimitiveType type, int segs, int divs, int num) { // Make the description - str frac = ftoa ( ( (float) segs) / divs); + str frac = str::number ((float) segs / divs); str name = radialFileName (type, segs, divs, num); str descr;
--- a/src/types.cpp Wed Oct 16 23:07:59 2013 +0300 +++ b/src/types.cpp Wed Oct 16 23:20:35 2013 +0300 @@ -219,7 +219,7 @@ { if (i > 0) val += ' '; - val += ftoa (m_vals[i]); + val += str::number (m_vals[i]); } return val; @@ -282,11 +282,11 @@ } StringFormatArg::StringFormatArg (const float& v) -{ m_val = ftoa (v); +{ m_val = str::number (v); } StringFormatArg::StringFormatArg (const double& v) -{ m_val = ftoa (v); +{ m_val = str::number (v); } StringFormatArg::StringFormatArg (const vertex& v)