MCPcopy Create free account
hub / github.com/KDE/labplot / sortColumns

Method sortColumns

src/backend/spreadsheet/Spreadsheet.cpp:756–1116  ·  view source on GitHub ↗

! * Clears all values in the specified columns. * @param cols The columns in the spreadsheet to clear. */

Source from the content-addressed store, hash-verified

754 * @param cols The columns in the spreadsheet to clear.
755 */
756void Spreadsheet::sortColumns(Column* leading, const QVector<Column*>& cols, bool ascending) {
757 DEBUG(Q_FUNC_INFO << ", ascending = " << ascending)
758 if (cols.isEmpty())
759 return;
760
761 // the normal QPair comparison does not work properly with descending sorting
762 // therefore we use our own compare functions
763 // TODO: check this. a < b vs. a.first < b.first
764 class CompareFunctions {
765 public:
766 static bool doubleLess(QPair<double, int> a, QPair<double, int> b) {
767 return a.first < b.first;
768 }
769 static bool doubleGreater(QPair<double, int> a, QPair<double, int> b) {
770 return a.first > b.first;
771 }
772 static bool integerLess(QPair<int, int> a, QPair<int, int> b) {
773 return a.first < b.first;
774 }
775 static bool integerGreater(QPair<int, int> a, QPair<int, int> b) {
776 return a.first > b.first;
777 }
778 static bool bigIntLess(QPair<qint64, int> a, QPair<qint64, int> b) {
779 return a.first < b.first;
780 }
781 static bool bigIntGreater(QPair<qint64, int> a, QPair<qint64, int> b) {
782 return a.first > b.first;
783 }
784 static bool QStringLess(const QPair<QString, int>& a, const QPair<QString, int>& b) {
785 return a < b;
786 }
787 static bool QStringGreater(const QPair<QString, int>& a, const QPair<QString, int>& b) {
788 return a > b;
789 }
790 static bool QDateTimeLess(const QPair<QDateTime, int>& a, const QPair<QDateTime, int>& b) {
791 return a < b;
792 }
793 static bool QDateTimeGreater(const QPair<QDateTime, int>& a, const QPair<QDateTime, int>& b) {
794 return a > b;
795 }
796 };
797
798 WAIT_CURSOR;
799 beginMacro(i18n("%1: sort columns", name()));
800
801 if (!leading) { // sort separately
802 DEBUG(" sort separately")
803 for (auto* col : cols) {
804 int rows = col->rowCount();
805 std::unique_ptr<Column> tempCol(new Column(QStringLiteral("temp"), col->columnMode()));
806
807 switch (col->columnMode()) {
808 case AbstractColumn::ColumnMode::Double: {
809 QVector<QPair<double, int>> map;
810
811 for (int i = 0; i < rows; i++)
812 if (col->isValid(i))
813 map.append(QPair<double, int>(col->valueAt(i), i));

Callers

nothing calls this directly

Calls 15

appendMethod · 0.80
setFromColumnMethod · 0.80
setMaskedMethod · 0.80
isEmptyMethod · 0.45
rowCountMethod · 0.45
columnModeMethod · 0.45
isValidMethod · 0.45
valueAtMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
isMaskedMethod · 0.45

Tested by

no test coverage detected