# HG changeset patch # User Santeri Piippo # Date 1381930842 -10800 # Node ID bebe09014dd611d6a592b5504ab404b6839449d8 # Parent f6534d591f801e2332d2c8ceb26feb6e29771f87 removed the List class in favor of QList diff -r f6534d591f80 -r bebe09014dd6 src/configDialog.cpp --- a/src/configDialog.cpp Wed Oct 16 16:05:51 2013 +0300 +++ b/src/configDialog.cpp Wed Oct 16 16:40:42 2013 +0300 @@ -432,7 +432,7 @@ return; QListWidgetItem* item = ui->quickColorList->selectedItems() [0]; - quickColors.erase (getItemRow (item, quickColorItems)); + quickColors.removeAt (getItemRow (item, quickColorItems)); updateQuickColorList(); } diff -r f6534d591f80 -r bebe09014dd6 src/download.cpp --- a/src/download.cpp Wed Oct 16 16:05:51 2013 +0300 +++ b/src/download.cpp Wed Oct 16 16:40:42 2013 +0300 @@ -227,7 +227,7 @@ { const int row = ui->progress->rowCount(); // Don't download files repeadetly. - if (m_filesToDownload.find (dest) != -1u) + if (m_filesToDownload.indexOf (dest) != -1) return; modifyDest (dest); diff -r f6534d591f80 -r bebe09014dd6 src/file.cpp --- a/src/file.cpp Wed Oct 16 16:05:51 2013 +0300 +++ b/src/file.cpp Wed Oct 16 16:40:42 2013 +0300 @@ -133,12 +133,7 @@ delete obj; // Remove this file from the list of files - for (int i = 0; i < g_loadedFiles.size(); ++i) - { if (g_loadedFiles[i] == this) - { g_loadedFiles.erase (i); - break; - } - } + g_loadedFiles.removeOne (this); // If we just closed the current file, we need to set the current // file as something else. @@ -907,14 +902,14 @@ void LDFile::forgetObject (LDObject* obj) { int idx = obj->getIndex(); m_history.add (new DelHistory (idx, obj)); - m_objects.erase (idx); + m_objects.removeAt (idx); obj->setFile (null); } // ============================================================================= // ----------------------------------------------------------------------------- bool safeToCloseAll() -{ for (LDFile * f : g_loadedFiles) +{ for (LDFile* f : g_loadedFiles) if (!f->safeToClose()) return false; @@ -959,18 +954,18 @@ { List filesUsed = getFilesUsed (LDFile::current()); // Anything that's explicitly opened must not be closed -for (LDFile * file : g_loadedFiles) + for (LDFile* file : g_loadedFiles) if (!file->implicit()) filesUsed << file; // Remove duplicated entries - filesUsed.makeUnique(); + removeDuplicates (filesUsed); // Close all open files that aren't in filesUsed -for (LDFile * file : g_loadedFiles) + for (LDFile* file : g_loadedFiles) { bool isused = false; - for (LDFile * usedFile : filesUsed) + for (LDFile* usedFile : filesUsed) { if (file == usedFile) { isused = true; break; diff -r f6534d591f80 -r bebe09014dd6 src/gldraw.cpp --- a/src/gldraw.cpp Wed Oct 16 16:05:51 2013 +0300 +++ b/src/gldraw.cpp Wed Oct 16 16:40:42 2013 +0300 @@ -1013,11 +1013,11 @@ addDrawnVertex (closest); } - if (wasRight && m_drawedVerts.size() > 0) + if (wasRight && !m_drawedVerts.isEmpty()) { // Remove the last vertex - m_drawedVerts.erase (m_drawedVerts.size() - 1); + m_drawedVerts.removeLast(); - if (m_drawedVerts.size() == 0) + if (m_drawedVerts.isEmpty()) m_rectdraw = false; } @@ -1145,7 +1145,7 @@ { List oldsel = g_win->sel(); g_win->sel().clear(); - for (LDObject * obj : oldsel) + for (LDObject* obj : oldsel) { obj->setSelected (false); compileObject (obj); } @@ -1220,19 +1220,14 @@ // If this is an additive single pick and the object is currently selected, // we remove it from selection instead. if (!m_rangepick && m_addpick) - { bool removed = false; + { int pos = g_win->sel().indexOf (obj); - for (int i = 0; i < g_win->sel().size(); ++i) - { if (g_win->sel() [i] == obj) - { g_win->sel().erase (i); - obj->setSelected (false); - removed = true; - removedObj = obj; - } + if (pos != -1) + { g_win->sel().removeAt (i); + obj->setSelected (false); + removedObj = obj; + break; } - - if (removed) - break; } g_win->sel() << obj; @@ -1241,13 +1236,13 @@ delete[] pixeldata; // Remove duplicated entries - g_win->sel().makeUnique(); + removeDuplicates (g_win->sel()); // Update everything now. g_win->updateSelection(); // Recompile the objects now to update their color -for (LDObject * obj : g_win->sel()) + for (LDObject* obj : g_win->sel()) compileObject (obj); if (removedObj) @@ -1538,7 +1533,7 @@ // Mark in known vertices of this object List verts = getVertices (obj); m_knownVerts << verts; - m_knownVerts.makeUnique(); + removeDuplicates (m_knownVerts); obj->m_glinit = true; } diff -r f6534d591f80 -r bebe09014dd6 src/history.cpp --- a/src/history.cpp Wed Oct 16 16:05:51 2013 +0300 +++ b/src/history.cpp Wed Oct 16 16:40:42 2013 +0300 @@ -111,11 +111,11 @@ setOpened (false); - if (m_currentArchive.size() == 0) + if (m_currentArchive.isEmpty()) return; while (pos() < size() - 1) - m_changesets.erase (size() - 1); + m_changesets.removeLast(); m_changesets << m_currentArchive; m_currentArchive.clear(); diff -r f6534d591f80 -r bebe09014dd6 src/ldtypes.cpp --- a/src/ldtypes.cpp Wed Oct 16 16:05:51 2013 +0300 +++ b/src/ldtypes.cpp Wed Oct 16 16:40:42 2013 +0300 @@ -253,18 +253,13 @@ // ----------------------------------------------------------------------------- LDObject::~LDObject() { // Remove this object from the selection array if it is there. - for (int i = 0; i < g_win->sel().size(); ++i) - if (g_win->sel() [i] == this) - g_win->sel().erase (i); + g_win->sel().removeOne (this); // Delete the GL lists GL::deleteLists (this); // Remove this object from the list of LDObjects - int pos; - - if ((pos = g_LDObjects.find (this)) != -1) - g_LDObjects.erase (pos); + g_LDObjects.removeOne (this); } // ============================================================================= @@ -366,11 +361,11 @@ obj->swap (file->obj (target)); } - objsToCompile.makeUnique(); + removeDuplicates (objsToCompile); // The objects need to be recompiled, otherwise their pick lists are left with // the wrong index colors which messes up selection. -for (LDObject * obj : objsToCompile) + for (LDObject* obj : objsToCompile) g_win->R()->compileObject (obj); } diff -r f6534d591f80 -r bebe09014dd6 src/messagelog.cpp --- a/src/messagelog.cpp Wed Oct 16 16:05:51 2013 +0300 +++ b/src/messagelog.cpp Wed Oct 16 16:40:42 2013 +0300 @@ -97,7 +97,7 @@ { bool lineChanged; if (!m_lines[i].update (lineChanged)) - m_lines.erase (i--); + m_lines.removeAt (i--); changed |= lineChanged; } diff -r f6534d591f80 -r bebe09014dd6 src/misc.h --- a/src/misc.h Wed Oct 16 16:05:51 2013 +0300 +++ b/src/misc.h Wed Oct 16 16:40:42 2013 +0300 @@ -161,4 +161,10 @@ { return isZero (a - (int) a); } +template void removeDuplicates (QList& a) +{ std::sort (a.begin(), a.end()); + typename QList::iterator pos = std::unique (a.begin(), a.end()); + a.erase (pos, a.end()); +} + #endif // MISC_H diff -r f6534d591f80 -r bebe09014dd6 src/primitives.cpp --- a/src/primitives.cpp Wed Oct 16 16:05:51 2013 +0300 +++ b/src/primitives.cpp Wed Oct 16 16:40:42 2013 +0300 @@ -185,17 +185,18 @@ { // Shouldn't happen.. but catch it anyway. PrimitiveCategory cat; cat.setName (g_Other); - unmatched = & (g_PrimitiveCategories << cat); + g_PrimitiveCategories << cat; + unmatched = &g_PrimitiveCategories.last(); } -for (Primitive & prim : g_primitives) + for (Primitive & prim : g_primitives) { bool matched = false; prim.cat = null; // Go over the categories and their regexes, if and when there's a match, // the primitive's category is set to the category the regex beloings to. - for (PrimitiveCategory & cat : g_PrimitiveCategories) - { for (PrimitiveCategory::RegexEntry & entry : cat.regexes) + for (PrimitiveCategory& cat : g_PrimitiveCategories) + { for (PrimitiveCategory::RegexEntry& entry : cat.regexes) { switch (entry.type) { case PrimitiveCategory::Filename: // f-regex, check against filename diff -r f6534d591f80 -r bebe09014dd6 src/primitives.h --- a/src/primitives.h Wed Oct 16 16:05:51 2013 +0300 +++ b/src/primitives.h Wed Oct 16 16:40:42 2013 +0300 @@ -104,7 +104,7 @@ void hiResToggled (bool on); }; -void makeCircle (int segs, int divs, double radius, List< QLineF >& lines); +void makeCircle (int segs, int divs, double radius, List& lines); LDFile* generatePrimitive (PrimitiveType type, int segs, int divs, int num); // Gets a primitive by the given specs. If the primitive cannot be found, it will diff -r f6534d591f80 -r bebe09014dd6 src/types.h --- a/src/types.h Wed Oct 16 16:05:51 2013 +0300 +++ b/src/types.h Wed Oct 16 16:40:42 2013 +0300 @@ -46,6 +46,7 @@ typedef quint32 uint32; typedef quint64 uint64; +template using List = QList; template using initlist = std::initializer_list; template using pair = std::pair; using std::size_t; @@ -165,197 +166,6 @@ }; // ============================================================================= -// ----------------------------------------------------------------------------- -class Line -{ public: - Line() {} - Line (const vertex& v0, const vertex v1) : - m_v0 (v0), - m_v1 (v1) {} - - inline const vertex& getVertex (int i) const - { assert (i == 0 || i == 1); - return (i == 0) ? m_v0 : m_v1; - } - - inline void setVertex (int i, const vertex& a) - { assert (i == 0 || i == 1); - (i == 0) ? m_v0 : m_v1 = a; - } - - inline const vertex& v0() const - { return m_v0; - } - - inline const vertex& v1() const - { return m_v1; - } - - inline void setV0 (const vertex& a) - { m_v0 = a; - } - - inline void setV1 (const vertex& a) - { m_v1 = a; - } - - private: - vertex m_v0, - m_v1; -}; - -// ============================================================================= -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -// ============================================================================= -// List -// -// Array class that wraps around std::deque -// ============================================================================= -template class List -{ public: - typedef typename std::deque::iterator Iterator; - typedef typename std::deque::const_iterator ConstIterator; - typedef typename std::deque::reverse_iterator ReverseIterator; - typedef typename std::deque::const_reverse_iterator ConstReverseIterator; - - List() {} - List (initlist vals) - { m_vect = vals; - } - - inline Iterator begin() - { return m_vect.begin(); - } - - inline ConstIterator begin() const - { return m_vect.cbegin(); - } - - inline Iterator end() - { return m_vect.end(); - } - - inline ConstIterator end() const - { return m_vect.cend(); - } - - inline ReverseIterator rbegin() - { return m_vect.rbegin(); - } - - inline ConstReverseIterator crbegin() const - { return m_vect.crbegin(); - } - - inline ReverseIterator rend() - { return m_vect.rend(); - } - - inline ConstReverseIterator crend() const - { return m_vect.crend(); - } - - void erase (int pos) - { assert (pos < size()); - m_vect.erase (m_vect.begin() + pos); - } - - T& push_back (const T& value) - { m_vect.push_back (value); - return m_vect[m_vect.size() - 1]; - } - - void push_back (const List& vals) - { for (const T& val : vals) - push_back (val); - } - - bool pop (T& val) - { if (size() == 0) - return false; - - val = m_vect[size() - 1]; - erase (size() - 1); - return true; - } - - T& operator<< (const T& value) - { return push_back (value); - } - - void operator<< (const List& vals) - { push_back (vals); - } - - bool operator>> (T& value) - { return pop (value); - } - - List reverse() const - { List rev; - - for (auto it = end() - 1; it != begin(); --it) - rev << *it; - - return rev; - } - - void clear() - { m_vect.clear(); - } - - void insert (int pos, const T& value) - { m_vect.insert (m_vect.begin() + pos, value); - } - - void makeUnique() - { // Remove duplicate entries. For this to be effective, the List must be - // sorted first. - sort(); - Iterator pos = std::unique (begin(), end()); - resize (std::distance (begin(), pos)); - } - - int size() const - { return m_vect.size(); - } - - T& operator[] (int n) - { assert (n < size()); - return m_vect[n]; - } - - const T& operator[] (int n) const - { assert (n < size()); - return m_vect[n]; - } - - void resize (std::ptrdiff_t size) - { m_vect.resize (size); - } - - void sort() - { std::sort (begin(), end()); - } - - int find (const T& needle) - { int i = 0; - - for (const T & hay : *this) - { if (hay == needle) - return i; - - i++; - } - - return -1; - } - - private: - std::deque m_vect; -}; - -// ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= // StringFormatArg