Thu, 05 Dec 2013 13:51:52 +0200
- ensured header files' guards start with LDFORGE_
- removed typedef "qchar" (use QChar instead), removed use of short, long and size_t (use int instead)
- use C++11-using syntax instead of typedefs in types.h
--- a/src/addObjectDialog.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/addObjectDialog.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -53,7 +53,7 @@ AddObjectDialog::AddObjectDialog (const LDObject::Type type, LDObject* obj, QWidget* parent) : QDialog (parent) { setlocale (LC_ALL, "C"); - short coordCount = 0; + int coordCount = 0; str typeName = LDObject::typeName (type); switch (type) @@ -104,7 +104,7 @@ // If the primitive lister is busy writing data, we have to wait // for that to happen first. This should be quite considerably rare. - while (primitiveLoaderBusy()) + while (isPrimitiveLoaderBusy()) ; tw_subfileList = new QTreeWidget(); @@ -164,7 +164,7 @@ connect (pb_color, SIGNAL (clicked()), this, SLOT (slot_colorButtonClicked())); } - for (short i = 0; i < coordCount; ++i) + for (int i = 0; i < coordCount; ++i) { dsb_coords[i] = new QDoubleSpinBox; dsb_coords[i]->setDecimals (5); dsb_coords[i]->setMinimum (-10000.0); @@ -182,8 +182,8 @@ // Apply coordinates if (obj) - { for (short i = 0; i < coordCount / 3; ++i) - for (short j = 0; j < 3; ++j) + { for (int i = 0; i < coordCount / 3; ++i) + for (int j = 0; j < 3; ++j) dsb_coords[ (i * 3) + j]->setValue (obj->getVertex (i).coord (j)); } @@ -233,7 +233,7 @@ if (coordCount > 0) { QGridLayout* const qCoordLayout = new QGridLayout; - for (short i = 0; i < coordCount; ++i) + for (int i = 0; i < coordCount; ++i) qCoordLayout->addWidget (dsb_coords[i], (i / 3), (i % 3)); layout->addLayout (qCoordLayout, 0, 1, (coordCount / 3), 3); @@ -252,7 +252,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void AddObjectDialog::setButtonBackground (QPushButton* button, short colnum) +void AddObjectDialog::setButtonBackground (QPushButton* button, int colnum) { LDColor* col = getColor (colnum); button->setIcon (getIcon ("palette")); @@ -276,7 +276,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void AddObjectDialog::slot_colorButtonClicked() -{ ColorSelector::getColor (colnum, colnum, this); +{ ColorSelector::selectColor (colnum, colnum, this); setButtonBackground (pb_color, colnum); } @@ -348,10 +348,10 @@ if (!obj) obj = LDObject::getDefault (type); - for (short i = 0; i < obj->vertices(); ++i) + for (int i = 0; i < obj->vertices(); ++i) { vertex v; - for (const Axis ax : g_Axes) + for (const Axis ax : g_Axes) v[ax] = dlg.dsb_coords[ (i * 3) + ax]->value(); obj->setVertex (i, v); @@ -408,5 +408,5 @@ LDFile::current()->insertObj (idx, obj); } - g_win->fullRefresh(); + g_win->doFullRefresh(); }
--- a/src/addObjectDialog.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/addObjectDialog.h Thu Dec 05 13:51:52 2013 +0200 @@ -59,10 +59,10 @@ QLineEdit* le_matrix; private: - void setButtonBackground (QPushButton* button, short color); + void setButtonBackground (QPushButton* button, int color); str currentSubfileName(); - short colnum; + int colnum; private slots: void slot_colorButtonClicked();
--- a/src/colorSelectDialog.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/colorSelectDialog.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -34,16 +34,16 @@ #include "moc_colorSelectDialog.cpp" static const int g_numColumns = 16; -static const short g_squareSize = 32; +static const int g_squareSize = 32; extern_cfg (String, gl_maincolor); extern_cfg (Float, gl_maincolor_alpha); // ============================================================================= // ----------------------------------------------------------------------------- -ColorSelector::ColorSelector (short defval, QWidget* parent) : QDialog (parent) +ColorSelector::ColorSelector (int defval, QWidget* parent) : QDialog (parent) { // Remove the default color if it's invalid - if (!::getColor (defval)) + if (!getColor (defval)) defval = -1; m_firstResize = true; @@ -52,7 +52,7 @@ m_scene = new QGraphicsScene; ui->viewport->setScene (m_scene); - setSelection (::getColor (defval)); + setSelection (getColor (defval)); // not really an icon but eh m_scene->setBackgroundBrush (getIcon ("checkerboard")); @@ -87,7 +87,7 @@ // Draw the color rectangles. m_scene->clear(); - for (short i = 0; i < MAX_COLORS; ++i) + for (int i = 0; i < MAX_COLORS; ++i) { LDColor* info = ::getColor (i); if (!info) @@ -183,7 +183,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -bool ColorSelector::getColor (short& val, short int defval, QWidget* parent) +bool ColorSelector::selectColor (int& val, int defval, QWidget* parent) { ColorSelector dlg (defval, parent); if (dlg.exec() && dlg.sel() != null)
--- a/src/colorSelectDialog.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/colorSelectDialog.h Thu Dec 05 13:51:52 2013 +0200 @@ -31,9 +31,9 @@ READ_PROPERTY (LDColor*, sel, setSelection) public: - explicit ColorSelector (short defval = -1, QWidget* parent = null); + explicit ColorSelector (int defval = -1, QWidget* parent = null); virtual ~ColorSelector(); - static bool getColor (short& val, short defval = -1, QWidget* parent = null); + static bool selectColor (int& val, int defval = -1, QWidget* parent = null); protected: void mousePressEvent (QMouseEvent* event);
--- a/src/colors.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/colors.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -52,7 +52,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -LDColor* getColor (short colnum) +LDColor* getColor (int colnum) { // Check bounds if (colnum < 0 || colnum >= MAX_COLORS) return null; @@ -62,7 +62,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void setColor (short colnum, LDColor* col) +void setColor (int colnum, LDColor* col) { if (colnum < 0 || colnum >= MAX_COLORS) return;
--- a/src/colors.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/colors.h Thu Dec 05 13:51:52 2013 +0200 @@ -28,18 +28,18 @@ { public: str name, hexcode; QColor faceColor, edgeColor; - short index; + int index; }; void initColors(); int luma (QColor& col); // Safely gets a color with the given number or null if no such color. -LDColor* getColor (short colnum); -void setColor (short colnum, LDColor* col); +LDColor* getColor (int colnum); +void setColor (int colnum, LDColor* col); // Main and edge color identifiers -static const short maincolor = 16; -static const short edgecolor = 24; +static const int maincolor = 16; +static const int edgecolor = 24; #endif // LDFORGE_COLORS_H
--- a/src/config.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/config.h Thu Dec 05 13:51:52 2013 +0200 @@ -27,7 +27,7 @@ #include <QKeySequence> class QSettings; -typedef QChar qchar; +typedef QChar QChar; typedef QString str; #define MAX_INI_LINE 512
--- a/src/configDialog.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/configDialog.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -193,7 +193,7 @@ *ylabel = new QLabel ("Y"), *zlabel = new QLabel ("Z"), *anglabel = new QLabel ("Angle"); - short i = 1; + int i = 1; for (QLabel* label : initlist<QLabel*> ({xlabel, ylabel, zlabel, anglabel})) { label->setAlignment (Qt::AlignCenter); @@ -336,7 +336,7 @@ reloadAllSubfiles(); loadLogoedStuds(); g_win->R()->setBackground(); - g_win->fullRefresh(); + g_win->doFullRefresh(); g_win->updateToolBars(); g_win->updateFileList(); } @@ -419,10 +419,10 @@ return; // don't color separators } - short defval = entry ? entry->color()->index : -1; - short val; + int defval = entry ? entry->color()->index : -1; + int val; - if (ColorSelector::getColor (val, defval, this) == false) + if (ColorSelector::selectColor (val, defval, this) == false) return; if (entry)
--- a/src/docs.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/docs.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,11 +16,11 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef DOCS_H -#define DOCS_H +#ifndef LDFORGE_DOCS_H +#define LDFORGE_DOCS_H extern const char* g_docs_overlays; void showDocumentation (const char* text); -#endif // DOCS_H \ No newline at end of file +#endif // LDFORGE_DOCS_H \ No newline at end of file
--- a/src/download.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/download.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -97,7 +97,7 @@ switch (src) { case PartsTracker: dest = ui->fname->text(); - modifyDest (dest); + modifyDestination (dest); return str (k_UnofficialURL) + dest; case CustomURL: @@ -110,7 +110,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void PartDownloader::modifyDest (str& dest) const +void PartDownloader::modifyDestination (str& dest) const { dest = dest.simplified(); // If the user doesn't want us to guess, stop right here. @@ -202,7 +202,7 @@ if (getSource() == CustomURL) dest = basename (getURL()); - modifyDest (dest); + modifyDestination (dest); if (QFile::exists (PartDownloader::getDownloadPath() + DIRSLASH + dest)) { const str overwritemsg = fmt (tr ("%1 already exists in download directory. Overwrite?"), dest); @@ -230,7 +230,7 @@ if (m_filesToDownload.indexOf (dest) != -1) return; - modifyDest (dest); + modifyDestination (dest); log ("DOWNLOAD: %1 -> %2\n", url, PartDownloader::getDownloadPath() + DIRSLASH + dest); PartDownloadRequest* req = new PartDownloadRequest (url, dest, primary, this); @@ -264,7 +264,7 @@ if (primaryFile()) { LDFile::setCurrent (primaryFile()); reloadAllSubfiles(); - g_win->fullRefresh(); + g_win->doFullRefresh(); g_win->R()->resetAngles(); } @@ -430,7 +430,7 @@ continue; str dest = err->fileRef(); - m_prompt->modifyDest (dest); + m_prompt->modifyDestination (dest); m_prompt->downloadFile (dest, str (PartDownloader::k_UnofficialURL) + dest, false); }
--- a/src/download.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/download.h Thu Dec 05 13:51:52 2013 +0200 @@ -35,9 +35,9 @@ // ============================================================================= // ----------------------------------------------------------------------------- class PartDownloader : public QDialog -{ Q_OBJECT - PROPERTY (LDFile*, primaryFile, setPrimaryFile) - PROPERTY (bool, aborted, setAborted) +{ Q_OBJECT + PROPERTY (LDFile*, primaryFile, setPrimaryFile) + PROPERTY (bool, aborted, setAborted) public: constexpr static const char* k_UnofficialURL = "http://ldraw.org/library/unofficial/"; @@ -64,7 +64,7 @@ static str getDownloadPath(); Source getSource() const; void downloadFile (str dest, str url, bool primary); - void modifyDest (str& dest) const; + void modifyDestination (str& dest) const; QPushButton* getButton (Button i); static void k_download(); @@ -78,7 +78,7 @@ friend class PartDownloadRequest; private: - QList<str> m_filesToDownload; + QStringList m_filesToDownload; QList<PartDownloadRequest*> m_requests; QPushButton* m_downloadButton; };
--- a/src/extprogs.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/extprogs.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -187,7 +187,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void writeColorGroup (const short colnum, str fname) +void writeColorGroup (const int colnum, str fname) { QList<LDObject*> objects; for (LDObject* obj : LDFile::current()->objects()) @@ -254,7 +254,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -static void insertOutput (str fname, bool replace, QList<short> colorsToReplace) +static void insertOutput (str fname, bool replace, QList<int> colorsToReplace) { #ifndef RELEASE QFile::copy (fname, "./debug_lastOutput"); @@ -274,7 +274,7 @@ if (replace) g_win->deleteSelection(); - for (const short colnum : colorsToReplace) + for (const int colnum : colorsToReplace) g_win->deleteByColor (colnum); // Insert the new objects @@ -290,7 +290,7 @@ obj->select(); } - g_win->fullRefresh(); + g_win->doFullRefresh(); } // ============================================================================= @@ -410,7 +410,7 @@ " cutter group with the input group. Both groups are cut by the intersection."); ui.cb_edges->setWhatsThis ("Makes " APPNAME " try run Isecalc to create edgelines for the intersection."); - short inCol, cutCol; + int inCol, cutCol; const bool repeatInverse = ui.cb_repeat->isChecked(); forever @@ -497,7 +497,7 @@ makeColorSelector (ui.cmb_col1); makeColorSelector (ui.cmb_col2); - short in1Col, in2Col; + int in1Col, in2Col; forever { if (!dlg->exec()) @@ -554,7 +554,7 @@ makeColorSelector (ui.cmb_col1); makeColorSelector (ui.cmb_col2); - short in1Col, in2Col; + int in1Col, in2Col; // Run the dialog and validate input forever
--- a/src/file.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/file.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -296,7 +296,7 @@ { str line = lines() [i]; // Trim the trailing newline - qchar c; + QChar c; while (!line.isEmpty() && ((c = line[line.length() - 1]) == '\n' || c == '\r')) line.chop (1); @@ -439,7 +439,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -bool LDFile::safeToClose() +bool LDFile::isSafeToClose() { typedef QMessageBox msgbox; setlocale (LC_ALL, "C"); @@ -511,7 +511,7 @@ LDFile::closeInitialFile(); g_win->R()->setFile (f); - g_win->fullRefresh(); + g_win->doFullRefresh(); g_win->updateTitle(); f->history().updateActions(); } @@ -572,7 +572,7 @@ // Rebuild the object tree view now. LDFile::setCurrent (file); - g_win->fullRefresh(); + g_win->doFullRefresh(); // Add it to the recent files list. addRecentFile (path); @@ -594,7 +594,7 @@ // Only do this if the file is explicitly open. If it's saved into a directory // called "s" or "48", prepend that into the name. LDComment* fpathComment = null; - LDObject* first = object (1); + LDObject* first = getObject (1); if (!implicit() && first != null && first->getType() == LDObject::Comment) { fpathComment = static_cast<LDComment*> (first); @@ -680,7 +680,7 @@ // Handle BFC statements if (tokens.size() > 2 && tokens[1] == "BFC") - { for (short i = 0; i < LDBFC::NumStatements; ++i) + { for (int i = 0; i < LDBFC::NumStatements; ++i) if (comm == fmt ("BFC %1", LDBFC::statements [i])) return new LDBFC ( (LDBFC::Type) i); @@ -762,7 +762,7 @@ matrix transform; - for (short i = 0; i < 9; ++i) + for (int i = 0; i < 9; ++i) transform[i] = tokens[i + 5].toDouble(); // 5 - 13 obj->setTransform (transform); @@ -778,7 +778,7 @@ LDLine* obj = new LDLine; obj->setColor (tokens[1].toLong()); - for (short i = 0; i < 2; ++i) + for (int i = 0; i < 2; ++i) obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 7 return obj; @@ -792,7 +792,7 @@ LDTriangle* obj = new LDTriangle; obj->setColor (tokens[1].toLong()); - for (short i = 0; i < 3; ++i) + for (int i = 0; i < 3; ++i) obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 10 return obj; @@ -813,7 +813,7 @@ obj->setColor (tokens[1].toLong()); - for (short i = 0; i < 4; ++i) + for (int i = 0; i < 4; ++i) obj->setVertex (i, parseVertex (tokens, 2 + (i * 3))); // 2 - 13 return obj; @@ -878,7 +878,7 @@ m_vertices << obj; obj->setFile (this); - return numObjs() - 1; + return getObjectCount() - 1; } // ============================================================================= @@ -910,7 +910,7 @@ // ----------------------------------------------------------------------------- bool safeToCloseAll() { for (LDFile* f : g_loadedFiles) - if (!f->safeToClose()) + if (!f->isSafeToClose()) return false; return true; @@ -919,10 +919,10 @@ // ============================================================================= // ----------------------------------------------------------------------------- void LDFile::setObject (int idx, LDObject* obj) -{ assert (idx < numObjs()); +{ assert (idx < m_objects.size()); // Mark this change to history - str oldcode = object (idx)->raw(); + str oldcode = getObject (idx)->raw(); str newcode = obj->raw(); m_history << new EditHistory (idx, oldcode, newcode); @@ -935,7 +935,7 @@ static QList<LDFile*> getFilesUsed (LDFile* node) { QList<LDFile*> filesUsed; -for (LDObject * obj : node->objects()) + for (LDObject* obj : node->objects()) { if (obj->getType() != LDObject::Subfile) continue; @@ -982,7 +982,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -LDObject* LDFile::object (int pos) const +LDObject* LDFile::getObject (int pos) const { if (m_objects.size() <= pos) return null; @@ -991,13 +991,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -LDObject* LDFile::obj (int pos) const -{ return object (pos); -} - -// ============================================================================= -// ----------------------------------------------------------------------------- -int LDFile::numObjs() const +int LDFile::getObjectCount() const { return objects().size(); } @@ -1188,6 +1182,6 @@ // ============================================================================= // ----------------------------------------------------------------------------- -const QList<LDObject*>& LDFile::selection() const +const QList<LDObject*>& LDFile::getSelection() const { return m_sel; } \ No newline at end of file
--- a/src/file.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/file.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef FILE_H -#define FILE_H +#ifndef LDFORGE_FILE_H +#define LDFORGE_FILE_H #include "common.h" #include "ldtypes.h" @@ -67,20 +67,19 @@ LDFile(); ~LDFile(); - int addObject (LDObject* obj); // Adds an object to this file at the end of the file. + int addObject (LDObject* obj); // Adds an object to this file at the end of the file. void addObjects (const QList<LDObject*> objs); void clearSelection(); - void forgetObject (LDObject* obj); // Deletes the given object from the object chain. + void forgetObject (LDObject* obj); // Deletes the given object from the object chain. str getShortName(); - const QList<LDObject*>& selection() const; - bool hasUnsavedChanges() const; // Does this file have unsaved changes? + const QList<LDObject*>& getSelection() const; + bool hasUnsavedChanges() const; // Does this file have unsaved changes? QList<LDObject*> inlineContents (LDSubfile::InlineFlags flags); void insertObj (int pos, LDObject* obj); - int numObjs() const; - LDObject* object (int pos) const; - LDObject* obj (int pos) const; - bool save (str path = ""); // Saves this file to disk. - bool safeToClose(); // Perform safety checks. Do this before closing any files! + int getObjectCount() const; + LDObject* getObject (int pos) const; + bool save (str path = ""); // Saves this file to disk. + bool isSafeToClose(); // Perform safety checks. Do this before closing any files! void setObject (int idx, LDObject* obj); inline LDFile& operator<< (LDObject* obj) @@ -165,7 +164,7 @@ extern QList<LDFile*> g_loadedFiles; inline const QList<LDObject*>& selection() -{ return LDFile::current()->selection(); +{ return LDFile::current()->getSelection(); } void addRecentFile (str path); @@ -209,4 +208,4 @@ void workDone(); }; -#endif // FILE_H +#endif // LDFORGE_FILE_H
--- a/src/gldraw.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/gldraw.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -97,7 +97,7 @@ }; static bool g_glInvert = false; -static QList<short> g_warnedColors; +static QList<int> g_warnedColors; // ============================================================================= // ----------------------------------------------------------------------------- @@ -320,7 +320,7 @@ qcol = getMainColor(); // Warn about the unknown colors, but only once. - for (short i : g_warnedColors) + for (int i : g_warnedColors) if (obj->color() == i) return; @@ -473,7 +473,7 @@ const LDFixedCameraInfo* cam = &g_FixedCameras[m_camera]; const Axis axisX = cam->axisX; const Axis axisY = cam->axisY; - const short negXFac = cam->negX ? -1 : 1, + const int negXFac = cam->negX ? -1 : 1, negYFac = cam->negY ? -1 : 1; // Calculate cx and cy - these are the LDraw unit coords the cursor is at. @@ -492,7 +492,7 @@ // Create the vertex from the coordinates pos3d[axisX] = tmp.sprintf ("%.3f", cx).toDouble(); pos3d[axisY] = tmp.sprintf ("%.3f", cy).toDouble(); - pos3d[3 - axisX - axisY] = depthValue(); + pos3d[3 - axisX - axisY] = getDepthValue(); return pos3d; } @@ -506,7 +506,7 @@ const LDFixedCameraInfo* cam = &g_FixedCameras[m_camera]; const Axis axisX = cam->axisX; const Axis axisY = cam->axisY; - const short negXFac = cam->negX ? -1 : 1, + const int negXFac = cam->negX ? -1 : 1, negYFac = cam->negY ? -1 : 1; glGetFloatv (GL_MODELVIEW_MATRIX, m); @@ -639,8 +639,8 @@ drawBlip (paint, coordconv3_2 (m_hoverpos)); else { QVector<vertex> verts, verts2; - const double dist0 = circleDrawDist (0), - dist1 = (m_drawedVerts.size() >= 2) ? circleDrawDist (1) : -1; + const double dist0 = getCircleDrawDist (0), + dist1 = (m_drawedVerts.size() >= 2) ? getCircleDrawDist (1) : -1; const int segs = lores; const double angleUnit = (2 * pi) / segs; Axis relX, relY; @@ -895,7 +895,7 @@ LDSubfile::RendererInline); bool oldinvert = g_glInvert; - if (ref->transform().determinant() < 0) + if (ref->transform().getDeterminant() < 0) g_glInvert = !g_glInvert; LDObject* prev = ref->prev(); @@ -1200,9 +1200,9 @@ glGetIntegerv (GL_VIEWPORT, viewport); - short x0 = mouseX, + int x0 = mouseX, y0 = mouseY; - short x1, y1; + int x1, y1; // Determine how big an area to read - with range picking, we pick by // the area given, with single pixel picking, we use an 1 x 1 area. @@ -1223,14 +1223,14 @@ dataswap (y0, y1); // Clamp the values to ensure they're within bounds - x0 = max<short> (0, x0); - y0 = max<short> (0, y0); - x1 = min<short> (x1, m_width); - y1 = min<short> (y1, m_height); + x0 = max (0, x0); + y0 = max (0, y0); + x1 = min (x1, m_width); + y1 = min (y1, m_height); - const short areawidth = (x1 - x0); - const short areaheight = (y1 - y0); - const long numpixels = areawidth * areaheight; + const int areawidth = (x1 - x0); + const int areaheight = (y1 - y0); + const qint32 numpixels = areawidth * areaheight; // Allocate space for the pixel data. uchar* const pixeldata = new uchar[4 * numpixels]; @@ -1244,11 +1244,11 @@ LDObject* removedObj = null; // Go through each pixel read and add them to the selection. - for (long i = 0; i < numpixels; ++i) - { long idx = - (* (pixelptr + 0) * 0x10000) + - (* (pixelptr + 1) * 0x00100) + - (* (pixelptr + 2) * 0x00001); + for (qint32 i = 0; i < numpixels; ++i) + { qint32 idx = + (*(pixelptr + 0) * 0x10000) + + (*(pixelptr + 1) * 0x00100) + + (*(pixelptr + 2) * 0x00001); pixelptr += 4; if (idx == 0xFFFFFF) @@ -1350,7 +1350,7 @@ { m_file = val; if (val != null) - overlaysFromObjects(); + initOverlaysFromObjects(); } // ============================================================================= @@ -1427,8 +1427,8 @@ case CircleMode: { const int segs = lores, divs = lores; // TODO: make customizable - double dist0 = circleDrawDist (0), - dist1 = circleDrawDist (1); + double dist0 = getCircleDrawDist (0), + dist1 = getCircleDrawDist (1); LDFile* refFile = null; matrix transform; bool circleOrDisc = false; @@ -1450,7 +1450,7 @@ } elif (g_RingFinder (dist0, dist1)) { // The ring finder found a solution, use that. Add the component rings to the file. - for (const RingFinder::Component& cmp : g_RingFinder.bestSolution()->components()) + for (const RingFinder::Component& cmp : g_RingFinder.bestSolution()->getComponents()) { if ((refFile = getFile (radialFileName (::Ring, lores, lores, cmp.num))) == null) { refFile = generatePrimitive (::Ring, lores, lores, cmp.num); refFile->setImplicit (false); @@ -1476,7 +1476,7 @@ vertex templ; templ[relX] = x0; templ[relY] = y0; - templ[relZ] = depthValue(); + templ[relZ] = getDepthValue(); // Calculate circle coords makeCircle (segs, divs, dist0, c0); @@ -1539,7 +1539,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -double GLRenderer::circleDrawDist (int pos) const +double GLRenderer::getCircleDrawDist (int pos) const { assert (m_drawedVerts.size() >= pos + 1); const vertex& v1 = (m_drawedVerts.size() >= pos + 2) ? m_drawedVerts[pos + 1] : m_hoverpos; Axis relX, relY; @@ -1607,7 +1607,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -uchar* GLRenderer::screencap (int& w, int& h) +uchar* GLRenderer::getScreencap (int& w, int& h) { w = m_width; h = m_height; uchar* cap = new uchar[4 * w * h]; @@ -1653,7 +1653,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -Axis GLRenderer::cameraAxis (bool y, GL::Camera camid) +Axis GLRenderer::getCameraAxis (bool y, GL::Camera camid) { if (camid == (GL::Camera) - 1) camid = m_camera; @@ -1687,8 +1687,8 @@ elif (info.lh == 0) info.lh = (info.lw * img->height()) / img->width(); - const Axis x2d = cameraAxis (false, cam), - y2d = cameraAxis (true, cam); + const Axis x2d = getCameraAxis (false, cam), + y2d = getCameraAxis (true, cam); const double negXFac = g_FixedCameras[cam].negX ? -1 : 1, negYFac = g_FixedCameras[cam].negY ? -1 : 1; @@ -1731,14 +1731,14 @@ // ============================================================================= // ----------------------------------------------------------------------------- -double GLRenderer::depthValue() const +double GLRenderer::getDepthValue() const { assert (camera() < Free); return m_depthValues[camera()]; } // ============================================================================= // ----------------------------------------------------------------------------- -const char* GLRenderer::cameraName() const +const char* GLRenderer::getCameraName() const { return g_CameraNames[camera()]; } @@ -1865,12 +1865,12 @@ vertex v0 = m_drawedVerts[0], v1 = (m_drawedVerts.size() >= 2) ? m_drawedVerts[1] : m_hoverpos; - const Axis ax = cameraAxis (false), - ay = cameraAxis (true), + const Axis ax = getCameraAxis (false), + ay = getCameraAxis (true), az = (Axis) (3 - ax - ay); for (int i = 0; i < 4; ++i) - m_rectverts[i][az] = depthValue(); + m_rectverts[i][az] = getDepthValue(); m_rectverts[0][ax] = v0[ax]; m_rectverts[0][ay] = v0[ay]; @@ -1919,7 +1919,7 @@ // ----------------------------------------------------------------------------- // Read in overlays from the current file and update overlay info accordingly. // ----------------------------------------------------------------------------- -void GLRenderer::overlaysFromObjects() +void GLRenderer::initOverlaysFromObjects() { for (Camera cam : g_Cameras) { if (cam == Free) continue; @@ -1972,8 +1972,8 @@ int i, lastOverlay = -1; bool found = false; - for (i = 0; i < file()->numObjs(); ++i) - { LDObject* obj = file()->obj (i); + for (i = 0; i < file()->getObjectCount(); ++i) + { LDObject* obj = file()->getObject (i); if (obj->isScemantic()) { found = true;
--- a/src/gldraw.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/gldraw.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef GLDRAW_H -#define GLDRAW_H +#ifndef LDFORGE_GLDRAW_H +#define LDFORGE_GLDRAW_H #include <QGLWidget> #include "common.h" @@ -80,23 +80,23 @@ { return m_camera; } - Axis cameraAxis (bool y, Camera camid = (Camera) - 1); - const char* cameraName() const; void clearOverlay(); void compileObject (LDObject* obj); void compileAllObjects(); - double depthValue() const; void drawGLScene(); void endDraw (bool accept); + Axis getCameraAxis (bool y, Camera camid = (Camera) - 1); + const char* getCameraName() const; + double getDepthValue() const; QColor getMainColor(); LDGLOverlay& getOverlay (int newcam); + uchar* getScreencap (int& w, int& h); void hardRefresh(); void initGLData(); - void overlaysFromObjects(); + void initOverlaysFromObjects(); void refresh(); void resetAngles(); void resetAllAngles(); - uchar* screencap (int& w, int& h); void setBackground(); void setCamera (const Camera cam); void setDepthValue (double depth); @@ -132,43 +132,43 @@ Camera cam; }; - CameraIcon m_cameraIcons[7]; - QTimer* m_toolTipTimer; - Qt::MouseButtons m_lastButtons; - Qt::KeyboardModifiers m_keymods; - vertex m_hoverpos; - double m_virtWidth, - m_virtHeight, - m_rotX[7], - m_rotY[7], - m_rotZ[7], - m_panX[7], - m_panY[7], - m_zoom[7]; - bool m_darkbg, - m_rangepick, - m_addpick, - m_drawToolTip, - m_screencap, - m_panning; - QPoint m_pos, - m_globalpos, - m_rangeStart; - QPen m_thickBorderPen, - m_thinBorderPen; - Camera m_camera, - m_toolTipCamera; - GLuint m_axeslist; - int m_width, - m_height, - m_totalmove; - QList<vertex> m_drawedVerts; - bool m_rectdraw; - vertex m_rectverts[4]; - QColor m_bgcolor; - double m_depthValues[6]; - LDGLOverlay m_overlays[6]; - QList<vertex> m_knownVerts; + CameraIcon m_cameraIcons[7]; + QTimer* m_toolTipTimer; + Qt::MouseButtons m_lastButtons; + Qt::KeyboardModifiers m_keymods; + vertex m_hoverpos; + double m_virtWidth, + m_virtHeight, + m_rotX[7], + m_rotY[7], + m_rotZ[7], + m_panX[7], + m_panY[7], + m_zoom[7]; + bool m_darkbg, + m_rangepick, + m_addpick, + m_drawToolTip, + m_screencap, + m_panning; + QPoint m_pos, + m_globalpos, + m_rangeStart; + QPen m_thickBorderPen, + m_thinBorderPen; + Camera m_camera, + m_toolTipCamera; + GLuint m_axeslist; + int m_width, + m_height, + m_totalmove; + QList<vertex> m_drawedVerts; + bool m_rectdraw; + vertex m_rectverts[4]; + QColor m_bgcolor; + double m_depthValues[6]; + LDGLOverlay m_overlays[6]; + QList<vertex> m_knownVerts; void addDrawnVertex (vertex m_hoverpos); LDOverlay* findOverlayObject (Camera cam); @@ -181,7 +181,7 @@ void calcCameraIcons(); // How large is the circle we're drawing right now? - double circleDrawDist (int pos) const; + double getCircleDrawDist (int pos) const; // Clamps an angle to [0, 360] void clampAngle (double& angle) const; @@ -250,4 +250,4 @@ extern const GL::Camera g_Cameras[7]; extern const char* g_CameraNames[7]; -#endif // GLDRAW_H +#endif // LDFORGE_GLDRAW_H
--- a/src/gui.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/gui.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -50,7 +50,7 @@ #include "ui_ldforge.h" #include "moc_gui.cpp" -static bool g_bSelectionLocked = false; +static bool g_isSelectionLocked = false; cfg (Bool, lv_colorize, true); cfg (String, gui_colortoolbar, "16:24:|:1:2:4:14:0:15:|:33:34:36:46"); @@ -231,10 +231,10 @@ else title += fmt (": <anonymous>"); - if (LDFile::current()->numObjs() > 0 && - LDFile::current()->obj (0)->getType() == LDObject::Comment) + if (LDFile::current()->getObjectCount() > 0 && + LDFile::current()->getObject (0)->getType() == LDObject::Comment) { // Append title - LDComment* comm = static_cast<LDComment*> (LDFile::current()->obj (0)); + LDComment* comm = static_cast<LDComment*> (LDFile::current()->getObject (0)); title += fmt (": %1", comm->text); } @@ -276,7 +276,7 @@ // Lock the selection while we do this so that refreshing the object list // doesn't trigger selection updating so that the selection doesn't get lost // while this is done. - g_bSelectionLocked = true; + g_isSelectionLocked = true; for (int i = 0; i < ui->objectList->count(); ++i) delete ui->objectList->item (i); @@ -302,7 +302,7 @@ case LDObject::Triangle: case LDObject::Quad: case LDObject::CndLine: - { for (short i = 0; i < obj->vertices(); ++i) + { for (int i = 0; i < obj->vertices(); ++i) { if (i != 0) descr += ", "; @@ -341,12 +341,12 @@ break; default: - { descr = obj->typeName(); + { descr = obj->getTypeName(); } break; } QListWidgetItem* item = new QListWidgetItem (descr); - item->setIcon (getIcon (obj->typeName())); + item->setIcon (getIcon (obj->getTypeName())); // Use italic font if hidden if (obj->hidden()) @@ -373,7 +373,7 @@ ui->objectList->insertItem (ui->objectList->count(), item); } - g_bSelectionLocked = false; + g_isSelectionLocked = false; updateSelection(); scrollToSelection(); } @@ -391,7 +391,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void ForgeWindow::slot_selectionChanged() -{ if (g_bSelectionLocked == true || LDFile::current() == null) +{ if (g_isSelectionLocked == true || LDFile::current() == null) return; // Update the shared selection array, though don't do this if this was @@ -449,7 +449,7 @@ if (col == null) return; - short newColor = col->index; + int newColor = col->index; for (LDObject* obj : selection()) { if (obj->isColored() == false) @@ -471,12 +471,12 @@ return selection().last()->getIndex() + 1; // Otherwise place the object at the end. - return LDFile::current()->numObjs(); + return LDFile::current()->getObjectCount(); } // ============================================================================= // ----------------------------------------------------------------------------- -void ForgeWindow::fullRefresh() +void ForgeWindow::doFullRefresh() { buildObjList(); m_renderer->hardRefresh(); } @@ -491,7 +491,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void ForgeWindow::updateSelection() -{ g_bSelectionLocked = true; +{ g_isSelectionLocked = true; for (LDObject* obj : LDFile::current()->objects()) obj->setSelected (false); @@ -506,14 +506,14 @@ obj->setSelected (true); } - g_bSelectionLocked = false; + g_isSelectionLocked = false; slot_selectionChanged(); } // ============================================================================= // ----------------------------------------------------------------------------- -short ForgeWindow::getSelectedColor() -{ short result = -1; +int ForgeWindow::getSelectedColor() +{ int result = -1; for (LDObject* obj : selection()) { if (obj->isColored() == false) @@ -531,7 +531,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -LDObject::Type ForgeWindow::uniformSelectedType() +LDObject::Type ForgeWindow::getUniformSelectedType() { LDObject::Type result = LDObject::Unidentified; for (LDObject * obj : selection()) @@ -601,7 +601,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void ForgeWindow::deleteObjVector (QList<LDObject*> objs) +void ForgeWindow::deleteObjects (QList<LDObject*> objs) { for (LDObject * obj : objs) { LDFile::current()->forgetObject (obj); delete obj; @@ -610,7 +610,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void ForgeWindow::deleteByColor (const short colnum) +void ForgeWindow::deleteByColor (const int colnum) { QList<LDObject*> objs; for (LDObject * obj : LDFile::current()->objects()) @@ -620,7 +620,7 @@ objs << obj; } - deleteObjVector (objs); + deleteObjects (objs); } // =============================================================================
--- a/src/gui.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/gui.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef GUI_H -#define GUI_H +#ifndef LDFORGE_GUI_H +#define LDFORGE_GUI_H #include <QMainWindow> #include <QAction> @@ -95,7 +95,7 @@ ForgeWindow(); void buildObjList(); void updateTitle(); - void fullRefresh(); + void doFullRefresh(); void refresh(); int getInsertionPoint(); void updateToolBars(); @@ -105,13 +105,13 @@ void updateEditModeActions(); void updateFileList(); void updateFileListItem (LDFile* f); - short getSelectedColor(); - LDObject::Type uniformSelectedType(); + int getSelectedColor(); + LDObject::Type getUniformSelectedType(); void scrollToSelection(); void spawnContextMenu (const QPoint pos); - void deleteObjVector (QList< LDObject* > objs); + void deleteObjects (QList<LDObject*> objs); int deleteSelection(); - void deleteByColor (const short int colnum); + void deleteByColor (const int colnum); void save (LDFile* f, bool saveAs); inline GLRenderer* R() @@ -210,4 +210,4 @@ } } -#endif // GUI_H +#endif // LDFORGE_GUI_H
--- a/src/gui_actions.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/gui_actions.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -101,7 +101,7 @@ new LDEmpty, }); - g_win->fullRefresh(); + g_win->doFullRefresh(); } // ============================================================================= @@ -147,7 +147,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (Close, CTRL (W)) -{ if (!LDFile::current()->safeToClose()) +{ if (!LDFile::current()->isSafeToClose()) return; delete LDFile::current(); @@ -268,7 +268,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (SelectByColor, CTRL_SHIFT (A)) -{ short colnum = g_win->getSelectedColor(); +{ int colnum = g_win->getSelectedColor(); if (colnum == -1) return; // no consensus on color @@ -288,7 +288,7 @@ { if (selection().isEmpty()) return; - LDObject::Type type = g_win->uniformSelectedType(); + LDObject::Type type = g_win->getUniformSelectedType(); if (type == LDObject::Unidentified) return; @@ -443,7 +443,7 @@ { setlocale (LC_ALL, "C"); int w, h; - uchar* imgdata = g_win->R()->screencap (w, h); + uchar* imgdata = g_win->R()->getScreencap (w, h); QImage img = imageFromScreencap (imgdata, w, h); str root = basename (LDFile::current()->name()); @@ -548,8 +548,8 @@ bool ok; double depth = QInputDialog::getDouble (g_win, "Set Draw Depth", - fmt ("Depth value for %1 Camera:", g_win->R()->cameraName()), - g_win->R()->depthValue(), -10000.0f, 10000.0f, 3, &ok); + fmt ("Depth value for %1 Camera:", g_win->R()->getCameraName()), + g_win->R()->getDepthValue(), -10000.0f, 10000.0f, 3, &ok); if (ok) g_win->R()->setDepthValue (depth); @@ -625,9 +625,9 @@ defval = selection()[0]->getIndex(); int idx = QInputDialog::getInt (null, "Go to line", "Go to line:", defval, - 1, LDFile::current()->numObjs(), 1, &ok); + 1, LDFile::current()->getObjectCount(), 1, &ok); - if (!ok || (obj = LDFile::current()->object (idx - 1)) == null) + if (!ok || (obj = LDFile::current()->getObject (idx - 1)) == null) return; LDFile::current()->clearSelection();
--- a/src/gui_editactions.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/gui_editactions.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -232,8 +232,8 @@ { if (selection().isEmpty()) return; - short colnum; - short defcol = -1; + int colnum; + int defcol = -1; QList<LDObject*> objs = selection(); @@ -242,7 +242,7 @@ defcol = g_win->getSelectedColor(); // Show the dialog to the user now and ask for a color. - if (ColorSelector::getColor (colnum, defcol, g_win)) + if (ColorSelector::selectColor (colnum, defcol, g_win)) { for (LDObject* obj : objs) { if (obj->isColored() == false) continue; @@ -266,7 +266,7 @@ if (type != LDObject::Quad && type != LDObject::Triangle) continue; - short numLines; + int numLines; LDLine* lines[4]; if (type == LDObject::Quad) @@ -287,7 +287,7 @@ lines[2] = new LDLine (tri->getVertex (2), tri->getVertex (0)); } - for (short i = 0; i < numLines; ++i) + for (int i = 0; i < numLines; ++i) { long idx = obj->getIndex() + i + 1; lines[i]->setColor (edgecolor); @@ -421,7 +421,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -static void doRotate (const short l, const short m, const short n) +static void doRotate (const int l, const int m, const int n) { QList<LDObject*> sel = selection(); QList<vertex*> queue; const vertex rotpoint = rotPoint (sel); @@ -447,7 +447,7 @@ // Apply the above matrix to everything for (LDObject* obj : sel) { if (obj->vertices()) - { for (short i = 0; i < obj->vertices(); ++i) + { for (int i = 0; i < obj->vertices(); ++i) { vertex v = obj->getVertex (i); rotateVertex (v, rotpoint, transform); obj->setVertex (i, v); @@ -508,7 +508,7 @@ int num = 0; for (LDObject* obj : selection()) - { for (short i = 0; i < obj->vertices(); ++i) + { for (int i = 0; i < obj->vertices(); ++i) { vertex v = obj->getVertex (i); for (const Axis ax : g_Axes) @@ -574,7 +574,7 @@ if (ui.z->isChecked()) sel << Z; for (LDObject* obj : selection()) - { for (short i = 0; i < obj->vertices(); ++i) + { for (int i = 0; i < obj->vertices(); ++i) { vertex v = obj->getVertex (i); for (Axis ax : sel) @@ -615,7 +615,7 @@ if (ui.z->isChecked()) sel << Z; for (LDObject* obj : selection()) - { for (short i = 0; i < obj->vertices(); ++i) + { for (int i = 0; i < obj->vertices(); ++i) { vertex v = obj->getVertex (i); for (Axis ax : sel) @@ -650,7 +650,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -static bool isColorUsed (short colnum) +static bool isColorUsed (int colnum) { for (LDObject* obj : LDFile::current()->objects()) if (obj->isColored() && obj->color() == colnum) return true; @@ -661,7 +661,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- DEFINE_ACTION (Autocolor, 0) -{ short colnum = 0; +{ int colnum = 0; while (colnum < MAX_COLORS && (getColor (colnum) == null || isColorUsed (colnum))) colnum++; @@ -710,7 +710,7 @@ // Find a spot to place the new comment for ( - obj = LDFile::current()->object (0); + obj = LDFile::current()->getObject (0); obj && obj->next() && !obj->next()->isScemantic(); obj = obj->next() )
--- a/src/history.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/history.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -37,7 +37,7 @@ { if (m_changesets.isEmpty() || pos() == -1) return; - const Changeset& set = changeset (pos()); + const Changeset& set = getChangeset (pos()); g_fullRefresh = false; // Iterate the list in reverse and undo all actions @@ -49,7 +49,7 @@ if (!g_fullRefresh) g_win->refresh(); else - g_win->fullRefresh(); + g_win->doFullRefresh(); updateActions(); } @@ -60,7 +60,7 @@ { if (pos() == (long) m_changesets.size()) return; - const Changeset& set = changeset (pos() + 1); + const Changeset& set = getChangeset (pos() + 1); g_fullRefresh = false; // Redo things - in the order as they were done in the first place @@ -72,7 +72,7 @@ if (!g_fullRefresh) g_win->refresh(); else - g_win->fullRefresh(); + g_win->doFullRefresh(); updateActions(); } @@ -114,7 +114,7 @@ if (m_currentArchive.isEmpty()) return; - while (pos() < size() - 1) + while (pos() < getSize() - 1) m_changesets.removeLast(); m_changesets << m_currentArchive; @@ -139,7 +139,7 @@ // ----------------------------------------------------------------------------- void AddHistory::undo() const { LDFile* f = parent()->file(); - LDObject* obj = f->object (index()); + LDObject* obj = f->getObject (index()); f->forgetObject (obj); delete obj; @@ -171,7 +171,7 @@ // ----------------------------------------------------------------------------- void DelHistory::redo() const { LDFile* f = parent()->file(); - LDObject* obj = f->object (index()); + LDObject* obj = f->getObject (index()); f->forgetObject (obj); delete obj; @@ -183,7 +183,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void EditHistory::undo() const -{ LDObject* obj = LDFile::current()->object (index()); +{ LDObject* obj = LDFile::current()->getObject (index()); LDObject* newobj = parseLine (oldCode()); obj->replace (newobj); g_win->R()->compileObject (newobj); @@ -192,7 +192,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- void EditHistory::redo() const -{ LDObject* obj = LDFile::current()->object (index()); +{ LDObject* obj = LDFile::current()->getObject (index()); LDObject* newobj = parseLine (newCode()); obj->replace (newobj); g_win->R()->compileObject (newobj);
--- a/src/history.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/history.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef HISTORY_H -#define HISTORY_H +#ifndef LDFORGE_HISTORY_H +#define LDFORGE_HISTORY_H #include "common.h" #include "ldtypes.h" @@ -57,7 +57,7 @@ void close(); void add (AbstractHistoryEntry* entry); - inline long size() const + inline long getSize() const { return m_changesets.size(); } @@ -66,7 +66,7 @@ return *this; } - inline const Changeset& changeset (long pos) const + inline const Changeset& getChangeset (long pos) const { return m_changesets[pos]; } @@ -168,6 +168,9 @@ dest (dest) {} }; +// ============================================================================= +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * +// ============================================================================= class SwapHistory : public AbstractHistoryEntry { public: IMPLEMENT_HISTORY_TYPE (Swap) @@ -178,4 +181,4 @@ b (b) {} }; -#endif // HISTORY_H +#endif // LDFORGE_HISTORY_H
--- a/src/ldconfig.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/ldconfig.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -26,7 +26,7 @@ // Helper function for parseLDConfig // ----------------------------------------------------------------------------- static bool parseLDConfigTag (LDConfigParser& pars, char const* tag, str& val) -{ short pos; +{ int pos; // Try find the token and get its position if (!pars.findToken (pos, tag, 1)) @@ -42,7 +42,7 @@ { File* f = openLDrawFile ("LDConfig.ldr", false); if (!f) - { critical (fmt (QObject::tr ("Unable to open LDConfig.ldr for parsing! (%1)"), + { critical (fmt (QObject::tr ("Unable to open LDConfig.ldr for parsing: %1"), strerror (errno))); return; } @@ -58,7 +58,7 @@ // Parse the line LDConfigParser pars (line, ' '); - short code = 0, alpha = 255; + int code = 0, alpha = 255; str name, facename, edgename, valuestr; // Check 0 !COLOUR, parse the name @@ -88,14 +88,14 @@ // Ensure that our colors are correct QColor faceColor (facename), - edgeColor (edgename); + edgeColor (edgename); if (!faceColor.isValid() || !edgeColor.isValid()) continue; // Parse alpha if given. if (parseLDConfigTag (pars, "ALPHA", valuestr)) - alpha = clamp<short> (valuestr.toShort(), 0, 255); + alpha = clamp (valuestr.toInt(), 0, 255); LDColor* col = new LDColor; col->name = name; @@ -119,14 +119,14 @@ // ============================================================================= // ----------------------------------------------------------------------------- -bool LDConfigParser::atBeginning() -{ return (m_pos == -1); +bool LDConfigParser::isAtBeginning() +{ return m_pos == -1; } // ============================================================================= // ----------------------------------------------------------------------------- -bool LDConfigParser::atEnd() -{ return (m_pos == m_tokens.size() - 1); +bool LDConfigParser::isAtEnd() +{ return m_pos == m_tokens.size() - 1; } // ============================================================================= @@ -141,19 +141,19 @@ // ============================================================================= // ----------------------------------------------------------------------------- -bool LDConfigParser::next (str& val) +bool LDConfigParser::getNextToken (str& val) { return getToken (val, ++m_pos); } // ============================================================================= // ----------------------------------------------------------------------------- -bool LDConfigParser::peekNext (str& val) +bool LDConfigParser::peekNextToken (str& val) { return getToken (val, m_pos + 1); } // ============================================================================= // ----------------------------------------------------------------------------- -bool LDConfigParser::findToken (short& result, char const* needle, short args) +bool LDConfigParser::findToken (int& result, char const* needle, int args) { for (int i = 0; i < (m_tokens.size() - args); ++i) { if (m_tokens[i] == needle) { result = i; @@ -172,19 +172,19 @@ // ============================================================================= // ----------------------------------------------------------------------------- -void LDConfigParser::seek (short amount, bool rel) +void LDConfigParser::seek (int amount, bool rel) { m_pos = (rel ? m_pos : 0) + amount; } // ============================================================================= // ----------------------------------------------------------------------------- -size_t LDConfigParser::size() +int LDConfigParser::getSize() { return m_tokens.size(); } // ============================================================================= // ----------------------------------------------------------------------------- -bool LDConfigParser::tokenCompare (short inPos, const char* sOther) +bool LDConfigParser::tokenCompare (int inPos, const char* sOther) { str tok; if (!getToken (tok, inPos))
--- a/src/ldconfig.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/ldconfig.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,33 +16,33 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef LDCONFIG_H -#define LDCONFIG_H +#ifndef LDFORGE_LDCONFIG_H +#define LDFORGE_LDCONFIG_H #include "types.h" #include <QStringList> // ============================================================================= -// StringParser +// LDConfigParser // -// String parsing utility +// String parsing utility for parsing ldconfig.ldr // ============================================================================= class LDConfigParser { public: LDConfigParser (str inText, char sep); - bool atEnd(); - bool atBeginning(); - bool next (str& val); - bool peekNext (str& val); + bool isAtEnd(); + bool isAtBeginning(); + bool getNextToken (str& val); + bool peekNextToken (str& val); bool getToken (str& val, const int pos); - bool findToken (short& result, char const* needle, short args); - size_t size(); + bool findToken (int& result, char const* needle, int args); + int getSize(); void rewind(); - void seek (short amount, bool rel); - bool tokenCompare (short inPos, const char* sOther); + void seek (int amount, bool rel); + bool tokenCompare (int inPos, const char* sOther); - str operator[] (const size_t idx) + str operator[] (const int idx) { return m_tokens[idx]; } @@ -53,4 +53,4 @@ void parseLDConfig(); -#endif // LDCONFIG_H +#endif // LDFORGE_LDCONFIG_H
--- a/src/ldtypes.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/ldtypes.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -77,11 +77,11 @@ { return false; } -str LDObject::typeName() const +str LDObject::getTypeName() const { return ""; } -short LDObject::vertices() const +int LDObject::vertices() const { return 0; } @@ -281,14 +281,14 @@ // ============================================================================= // ----------------------------------------------------------------------------- -static void transformObject (LDObject* obj, matrix transform, vertex pos, short parentcolor) +static void transformObject (LDObject* obj, matrix transform, vertex pos, int parentcolor) { switch (obj->getType()) { case LDObject::Line: case LDObject::CndLine: case LDObject::Triangle: case LDObject::Quad: - for (short i = 0; i < obj->vertices(); ++i) + for (int i = 0; i < obj->vertices(); ++i) { vertex v = obj->getVertex (i); v.transform (transform, pos); obj->setVertex (i, v); @@ -338,8 +338,8 @@ assert (file() != null); #endif - for (int i = 0; i < file()->numObjs(); ++i) - if (file()->obj (i) == this) + for (int i = 0; i < file()->getObjectCount(); ++i) + if (file()->getObject (i) == this) return i; return -1; @@ -373,9 +373,9 @@ } objsToCompile << obj; - objsToCompile << file->obj (target); + objsToCompile << file->getObject (target); - obj->swap (file->obj (target)); + obj->swap (file->getObject (target)); } removeDuplicates (objsToCompile); @@ -390,14 +390,14 @@ // ----------------------------------------------------------------------------- str LDObject::typeName (LDObject::Type type) { LDObject* obj = LDObject::getDefault (type); - str name = obj->typeName(); + str name = obj->getTypeName(); delete obj; return name; } // ============================================================================= // ----------------------------------------------------------------------------- -str LDObject::objectListContents (const QList<LDObject*>& objs) +str LDObject::describeObjects (const QList<LDObject*>& objs) { bool firstDetails = true; str text = ""; @@ -452,10 +452,10 @@ { long idx = getIndex(); assert (idx != -1); - if (idx == (long) file()->numObjs() - 1) + if (idx == (long) file()->getObjectCount() - 1) return null; - return file()->obj (idx + 1); + return file()->getObject (idx + 1); } // ============================================================================= @@ -467,7 +467,7 @@ if (idx == 0) return null; - return file()->obj (idx - 1); + return file()->getObject (idx - 1); } // ============================================================================= @@ -503,28 +503,28 @@ // ============================================================================= // ----------------------------------------------------------------------------- void LDLine::move (vertex vect) -{ for (short i = 0; i < 2; ++i) +{ for (int i = 0; i < 2; ++i) setVertex (i, getVertex (i) + vect); } // ============================================================================= // ----------------------------------------------------------------------------- void LDTriangle::move (vertex vect) -{ for (short i = 0; i < 3; ++i) +{ for (int i = 0; i < 3; ++i) setVertex (i, getVertex (i) + vect); } // ============================================================================= // ----------------------------------------------------------------------------- void LDQuad::move (vertex vect) -{ for (short i = 0; i < 4; ++i) +{ for (int i = 0; i < 4; ++i) setVertex (i, getVertex (i) + vect); } // ============================================================================= // ----------------------------------------------------------------------------- void LDCndLine::move (vertex vect) -{ for (short i = 0; i < 4; ++i) +{ for (int i = 0; i < 4; ++i) setVertex (i, getVertex (i) + vect); } @@ -689,11 +689,11 @@ // ============================================================================= // ----------------------------------------------------------------------------- -READ_ACCESSOR (short, LDObject::color) +READ_ACCESSOR (int, LDObject::color) { return m_color; } -SET_ACCESSOR (short, LDObject::setColor) +SET_ACCESSOR (int, LDObject::setColor) { changeProperty (this, &m_color, val); }
--- a/src/ldtypes.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/ldtypes.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef LDTYPES_H -#define LDTYPES_H +#ifndef LDFORGE_LDTYPES_H +#define LDFORGE_LDTYPES_H #include "common.h" #include "types.h" @@ -35,8 +35,8 @@ virtual void move (vertex where); \ virtual void invert(); -#define LDOBJ_NAME(N) virtual str typeName() const override { return #N; } -#define LDOBJ_VERTICES(V) virtual short vertices() const override { return V; } +#define LDOBJ_NAME(N) virtual str getTypeName() const override { return #N; } +#define LDOBJ_VERTICES(V) virtual int vertices() const override { return V; } #define LDOBJ_SETCOLORED(V) virtual bool isColored() const override { return V; } #define LDOBJ_COLORED LDOBJ_SETCOLORED (true) #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false) @@ -68,7 +68,7 @@ PROPERTY (LDObject*, parent, setParent) PROPERTY (LDFile*, file, setFile) READ_PROPERTY (int32, id, setID) - DECLARE_PROPERTY (short, color, setColor) + DECLARE_PROPERTY (int, color, setColor) public: // Object type codes. Codes are sorted in order of significance. @@ -97,6 +97,7 @@ long getIndex() const; // Index (i.e. line number) of this object virtual LDObject::Type getType() const; // Type enumerator of this object const vertex& getVertex (int i) const; // Get a vertex by index + virtual str getTypeName() const; // Type name of this object virtual bool hasMatrix() const; // Does this object have a matrix and position? (see LDMatrixObject) virtual void invert(); // Inverts this object (winding is reversed) virtual bool isColored() const; // Is this object colored? @@ -111,14 +112,13 @@ void setVertexCoord (int i, Axis ax, double value); // Set a single coordinate of a vertex void swap (LDObject* other); // Swap this object with another. LDObject* topLevelParent(); // What object in the current file ultimately references this? - virtual str typeName() const; // Type name of this object void unselect(); - virtual short vertices() const; // Number of vertices this object has + virtual int vertices() const; // Number of vertices this object has static str typeName (LDObject::Type type); // Get type name by enumerator static LDObject* getDefault (const LDObject::Type type); // Returns a sample object by the given enumerator static void moveObjects (QList<LDObject*> objs, const bool up); // TODO: move this to LDFile? - static str objectListContents (const QList<LDObject*>& objs); // Get a description of a list of LDObjects + static str describeObjects (const QList<LDObject*>& objs); // Get a description of a list of LDObjects static LDObject* fromID (int id); // TODO: make these private! @@ -474,7 +474,7 @@ // Other common LDraw stuff static const str CALicense = "!LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt", NonCALicense = "!LICENSE Not redistributable : see NonCAreadme.txt"; -static const short lores = 16; -static const short hires = 48; +static const int lores = 16; +static const int hires = 48; -#endif // LDTYPES_H +#endif // LDFORGE_LDTYPES_H
--- a/src/messagelog.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/messagelog.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MESSAGELOG_H -#define MESSAGELOG_H +#ifndef LDFORGE_MESSAGELOG_H +#define LDFORGE_MESSAGELOG_H #include <QObject> #include <QDate> @@ -65,4 +65,4 @@ void tick(); }; -#endif // MESSAGELOG_H +#endif // LDFORGE_MESSAGELOG_H
--- a/src/misc.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/misc.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -133,7 +133,7 @@ { bool gotDot = false; for (int i = 0; i < tok.length(); ++i) - { const qchar c = tok[i]; + { const QChar c = tok[i]; // Allow leading hyphen for negatives if (i == 0 && c == '-') @@ -376,11 +376,11 @@ bool RingFinder::Solution::operator> (const RingFinder::Solution& other) const { // If this solution has less components than the other one, this one // is definitely better. - if (components().size() < other.components().size()) + if (getComponents().size() < other.getComponents().size()) return true; // vice versa - if (other.components().size() < components().size()) + if (other.getComponents().size() < getComponents().size()) return false; // Calculate the maximum ring number. Since the solutions have equal @@ -389,12 +389,12 @@ int maxA = 0, maxB = 0; - for (int i = 0; i < components().size(); ++i) - { if (components()[i].num > maxA) - maxA = components()[i].num; + for (int i = 0; i < getComponents().size(); ++i) + { if (getComponents()[i].num > maxA) + maxA = getComponents()[i].num; - if (other.components()[i].num > maxB) - maxB = other.components()[i].num; + if (other.getComponents()[i].num > maxB) + maxB = other.getComponents()[i].num; } if (maxA < maxB)
--- a/src/misc.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/misc.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MISC_H -#define MISC_H +#ifndef LDFORGE_MISC_H +#define LDFORGE_MISC_H #include <QVector> #include "config.h" @@ -89,51 +89,51 @@ // ============================================================================= class RingFinder { public: - struct Component - { int num; - double scale; - }; + struct Component + { int num; + double scale; + }; + + class Solution + { public: + // Components of this solution + inline const QVector<Component>& getComponents() const + { return m_components; + } + + // Add a component to this solution + inline void addComponent (const Component& a) + { m_components.push_back (a); + } - class Solution - { public: - // Components of this solution - inline const QVector<Component>& components() const - { return m_components; - } + // Compare solutions + bool operator> (const Solution& other) const; + + private: + QVector<Component> m_components; + }; + + RingFinder() {} + bool findRings (double r0, double r1); - // Add a component to this solution - void addComponent (const Component& a) - { m_components.push_back (a); - } + inline const Solution* bestSolution() + { return m_bestSolution; + } - // Compare solutions - bool operator> (const Solution& other) const; + inline const QVector<Solution>& allSolutions() const + { return m_solutions; + } + + inline bool operator() (double r0, double r1) + { return findRings (r0, r1); + } private: - QVector<Component> m_components; - }; - - RingFinder() {} - bool findRings (double r0, double r1); - - inline const Solution* bestSolution() - { return m_bestSolution; - } + QVector<Solution> m_solutions; + const Solution* m_bestSolution; + int m_stack; - inline const QVector<Solution>& allSolutions() const - { return m_solutions; - } - - inline bool operator() (double r0, double r1) - { return findRings (r0, r1); - } - -private: - QVector<Solution> m_solutions; - const Solution* m_bestSolution; - int m_stack; - - bool findRingsRecursor (double r0, double r1, Solution& currentSolution); + bool findRingsRecursor (double r0, double r1, Solution& currentSolution); }; extern RingFinder g_RingFinder; @@ -186,4 +186,4 @@ a.erase (pos, a.end()); } -#endif // MISC_H +#endif // LDFORGE_MISC_H
--- a/src/primitives.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/primitives.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -16,6 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +// TODO: I believe the multi-threading is unnecessary here. Get rid of it. + #include <QDir> #include <QThread> #include <QRegExp> @@ -288,7 +290,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -bool primitiveLoaderBusy() +bool isPrimitiveLoaderBusy() { return g_primListerMutex; }
--- a/src/primitives.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/primitives.h Thu Dec 05 13:51:52 2013 +0200 @@ -80,7 +80,7 @@ extern QList<PrimitiveCategory> g_PrimitiveCategories; void loadPrimitives(); -bool primitiveLoaderBusy(); +bool isPrimitiveLoaderBusy(); enum PrimitiveType { Circle, @@ -93,7 +93,7 @@ // ============================================================================= class PrimitivePrompt : public QDialog -{ Q_OBJECT +{ Q_OBJECT public: explicit PrimitivePrompt (QWidget* parent = null, Qt::WindowFlags f = 0);
--- a/src/types.cpp Tue Oct 22 22:14:32 2013 +0300 +++ b/src/types.cpp Thu Dec 05 13:51:52 2013 +0200 @@ -19,7 +19,7 @@ #include <QObject> #include <QStringList> #include <QTextStream> -#include <qfile.h> +#include <QFile> #include <assert.h> #include "common.h" #include "types.h" @@ -181,14 +181,14 @@ // ============================================================================= // ----------------------------------------------------------------------------- matrix::matrix (double vals[]) -{ for (short i = 0; i < 9; ++i) +{ for (int i = 0; i < 9; ++i) m_vals[i] = vals[i]; } // ============================================================================= // ----------------------------------------------------------------------------- matrix::matrix (double fillval) -{ for (short i = 0; i < 9; ++i) +{ for (int i = 0; i < 9; ++i) m_vals[i] = fillval; } @@ -202,8 +202,8 @@ // ============================================================================= // ----------------------------------------------------------------------------- void matrix::puts() const -{ for (short i = 0; i < 3; ++i) - { for (short j = 0; j < 3; ++j) +{ for (int i = 0; i < 3; ++i) + { for (int j = 0; j < 3; ++j) log ("%1\t", m_vals[ (i * 3) + j]); log ("\n"); @@ -215,7 +215,7 @@ str matrix::stringRep() const { str val; - for (short i = 0; i < 9; ++i) + for (int i = 0; i < 9; ++i) { if (i > 0) val += ' '; @@ -237,10 +237,10 @@ { matrix val; val.zero(); - for (short i = 0; i < 3; ++i) - for (short j = 0; j < 3; ++j) - for (short k = 0; k < 3; ++k) - val[ (i * 3) + j] += m_vals[ (i * 3) + k] * other[ (k * 3) + j]; + for (int i = 0; i < 3; ++i) + for (int j = 0; j < 3; ++j) + for (int k = 0; k < 3; ++k) + val[(i * 3) + j] += m_vals[(i * 3) + k] * other[(k * 3) + j]; return val; } @@ -254,7 +254,7 @@ // ============================================================================= // ----------------------------------------------------------------------------- -double matrix::determinant() const +double matrix::getDeterminant() const { return (val (0) * val (4) * val (8)) + (val (1) * val (5) * val (6)) + (val (2) * val (3) * val (7)) - @@ -287,7 +287,7 @@ { m_val = v; } -StringFormatArg::StringFormatArg (const qchar& v) +StringFormatArg::StringFormatArg (const QChar& v) { m_val = v; } @@ -525,17 +525,15 @@ case LDObject::Triangle: case LDObject::Quad: case LDObject::CndLine: - - for (short i = 0; i < obj->vertices(); ++i) + { for (int i = 0; i < obj->vertices(); ++i) calcVertex (obj->getVertex (i)); - - break; + } break; case LDObject::Subfile: { LDSubfile* ref = static_cast<LDSubfile*> (obj); QList<LDObject*> objs = ref->inlineContents (LDSubfile::DeepCacheInline); - for (LDObject * obj : objs) + for (LDObject * obj : objs) { calcObject (obj); delete obj; }
--- a/src/types.h Tue Oct 22 22:14:32 2013 +0300 +++ b/src/types.h Thu Dec 05 13:51:52 2013 +0200 @@ -16,8 +16,8 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef TYPES_H -#define TYPES_H +#ifndef LDFORGE_TYPES_H +#define LDFORGE_TYPES_H #include <QString> #include <QObject> @@ -26,29 +26,27 @@ class LDObject; -typedef QChar qchar; -typedef QString str; class StringConfig; class IntConfig; class FloatConfig; class QFile; class QTextStream; -typedef unsigned int uint; -typedef unsigned short ushort; -typedef unsigned long ulong; -typedef qint8 int8; -typedef qint16 int16; -typedef qint32 int32; -typedef qint64 int64; -typedef quint8 uint8; -typedef quint16 uint16; -typedef quint32 uint32; -typedef quint64 uint64; +using str = QString; +using int8 = qint8; +using int16 = qint16; +using int32 = qint32; +using int64 = qint64; +using uint8 = quint8; +using uint16 = quint16; +using uint32 = quint32; +using uint64 = quint64; -template<class T> using initlist = std::initializer_list<T>; -template<class T, class R> using pair = std::pair<T, R>; -using std::size_t; +template<class T> +using initlist = std::initializer_list<T>; + +template<class T, class R> +using pair = std::pair<T, R>; enum Axis { X, Y, Z }; static const Axis g_Axes[3] = { X, Y, Z }; @@ -67,12 +65,12 @@ matrix (double fillval); matrix (double vals[]); - double determinant () const; - matrix mult (matrix other) const; - void puts () const; - str stringRep () const; - void zero (); - matrix& operator= (matrix other); + double getDeterminant() const; + matrix mult (matrix other) const; + void puts() const; + str stringRep() const; + void zero(); + matrix& operator= (matrix other); inline double& val (int idx) { return m_vals[idx]; @@ -89,6 +87,7 @@ inline double& operator[] (int idx) { return val (idx); } + inline const double& operator[] (int idx) const { return val (idx); } @@ -179,7 +178,7 @@ StringFormatArg (const str& v); StringFormatArg (const char& v); StringFormatArg (const uchar& v); - StringFormatArg (const qchar& v); + StringFormatArg (const QChar& v); #define NUMERIC_FORMAT_ARG(T,C) \ StringFormatArg (const T& v) { \ @@ -342,4 +341,4 @@ static const double pi = 3.14159265358979323846; -#endif // TYPES_H +#endif // LDFORGE_TYPES_H