Changeset 22879
- Timestamp:
- 2014-10-22T21:27:42+02:00 (10 years ago)
- Location:
- trunk/OMEdit/OMEditGUI
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/OMEdit/OMEditGUI/Plotting/VariablesWidget.cpp
r22866 r22879 686 686 } 687 687 return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); 688 } 689 690 bool VariableTreeProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const 691 { 692 QVariant l = (left.model() ? left.model()->data(left) : QVariant()); 693 QVariant r = (right.model() ? right.model()->data(right) : QVariant()); 694 return StringHandler::naturalSort(l.toString(), r.toString()); 688 695 } 689 696 -
trunk/OMEdit/OMEditGUI/Plotting/VariablesWidget.h
r22866 r22879 138 138 VariableTreeProxyModel(QObject *parent = 0); 139 139 protected: 140 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; 140 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const; 141 virtual bool lessThan(const QModelIndex &left, const QModelIndex &right) const; 141 142 }; 142 143 -
trunk/OMEdit/OMEditGUI/Util/StringHandler.cpp
r22347 r22879 1285 1285 return false; 1286 1286 } 1287 1288 bool StringHandler::naturalSort(const QString &s1, const QString &s2) { 1289 int i1 = 0; // index in string 1290 int i2 = 0; 1291 while (true) { 1292 if (s2.length() == i2) // both strings identical or s1 larger than s2 1293 return s1.length() == i1 ? true : false; 1294 if (s1.length() == i1) return true; // s1 smaller than s2 1295 1296 unsigned short u1 = s1[i1].unicode(); 1297 unsigned short u2 = s2[i2].unicode(); 1298 1299 if (u1 >= '0' && u1 <= '9' && u2 >= '0' && u2 <= '9') { 1300 // parse both numbers completely and compare them 1301 quint64 n1 = 0; // the parsed number 1302 quint64 n2 = 0; 1303 int l1 = 0; // length of the number 1304 int l2 = 0; 1305 do { 1306 ++l1; 1307 n1 = n1 * 10 + u1 - '0'; 1308 if (++i1 == s1.length()) break; 1309 u1 = s1[i1].unicode(); 1310 } while (u1 >= '0' && u1 <= '9'); 1311 do { 1312 ++l2; 1313 n2 = n2 * 10 + u2 - '0'; 1314 if (++i2 == s2.length()) break; 1315 u2 = s2[i2].unicode(); 1316 } while (u2 >= '0' && u2 <= '9'); 1317 // compare two numbers 1318 if (n1 < n2) return true; 1319 if (n1 > n2) return false; 1320 // only accept identical numbers if they also have the same length 1321 // (same number of leading zeros) 1322 if (l1 < l2) return true; 1323 if (l1 > l2) return false; 1324 } else { 1325 // compare digit with non-digit or two non-digits 1326 if (u1 < u2) return true; 1327 if (u1 > u2) return false; 1328 ++i1; 1329 ++i2; 1330 } 1331 } 1332 } -
trunk/OMEdit/OMEditGUI/Util/StringHandler.h
r22007 r22879 132 132 static bool isCFile(QString extension); 133 133 static bool isModelicaFile(QString extension); 134 static bool naturalSort(const QString &s1, const QString &s2); 134 135 protected: 135 136 static QString mLastOpenDir;
Note: See TracChangeset
for help on using the changeset viewer.