# HG changeset patch # User Teemu Piippo # Date 1656434635 -10800 # Node ID cf9a854b56a90ac404a75c977797ee193135d8c6 # Parent 9ca53009bc5cbd0e1aaaea7bc7698e6e58d677a4 Remove functional.h diff -r 9ca53009bc5c -r cf9a854b56a9 CMakeLists.txt --- a/CMakeLists.txt Tue Jun 28 19:36:03 2022 +0300 +++ b/CMakeLists.txt Tue Jun 28 19:43:55 2022 +0300 @@ -97,7 +97,6 @@ src/circularprimitive.h src/colors.h src/documentmanager.h - src/functional.h src/geometry.h src/invert.h src/ldrawalgorithm.h diff -r 9ca53009bc5c -r cf9a854b56a9 src/basics.h --- a/src/basics.h Tue Jun 28 19:36:03 2022 +0300 +++ b/src/basics.h Tue Jun 28 19:43:55 2022 +0300 @@ -38,7 +38,6 @@ #include #include #include "src/geometry.h" -#include "src/functional.h" #include "src/typeconversions.h" template diff -r 9ca53009bc5c -r cf9a854b56a9 src/functional.h --- a/src/functional.h Tue Jun 28 19:36:03 2022 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,190 +0,0 @@ -/* - * LDForge: LDraw parts authoring CAD - * Copyright (C) 2020 Teemu Piippo - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once -#include -#include -#include -#include -#include - -namespace fn -{ - template - class InsertIterator; -} - -/** - * Like std::back_inserter but calls x.insert(v) instead - */ -template -class fn::InsertIterator -{ -public: - InsertIterator(C& container) : - container{container} {} - auto operator*() - { - return *this; - } - auto operator++() - { - return *this; - } - auto operator++(int) - { - return *this; - } - template - auto operator=(T&& value) - { - this->container.insert(std::forward(value)); - return *this; - } -private: - C& container; -}; - -namespace fn -{ - // Constructs a fn::InsertIterator - template - InsertIterator makeInsertIterator(C& container) - { - return InsertIterator{container}; - } - - // Constructs a back_inserter for std::vector - template - auto makeDefaultInserter(std::vector& vec) - { - return std::back_inserter(vec); - } - -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - // In Qt6 QVector is now a QList instead, so we need to disable this - // Constructs a back_inserter for QVector - template - auto makeDefaultInserter(QVector& vec) - { - return std::back_inserter(vec); - } -#endif - - template - auto makeDefaultInserter(QList& vec) - { - return std::back_inserter(vec); - } - - // Constructs an fn::InsertIterator for QSet - template - auto makeDefaultInserter(QSet& vec) - { - return InsertIterator(vec); - } - - // Changes the value type of C - template - struct ChangeContainerValueType - { - }; - - // Changes the value type of std::vector - template - struct ChangeContainerValueType, TT> - { - using type = std::vector; - }; - -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - // Changes the value type of QVector - template - struct ChangeContainerValueType, TT> - { - using type = QVector; - }; -#endif - - // Changes the value type of QSet - template - struct ChangeContainerValueType, TT> - { - using type = QSet; - }; - - // Changes the value type of QList - template - struct ChangeContainerValueType, TT> - { - using type = QList; - }; - - // Changes the value type of C - template - using ChangeContainerValueType_t = typename ChangeContainerValueType::type; - - /** - * \brief Applies \c function to all elements of \c container - * \param container Container to iterate - * \param function Function to apply - * \param Rt result type. If not provided, a suitable result type is deduced from inputs - * \returns mapped result container - */ - template - auto map(C&& container, Fn&& function) - { - using value_t = decltype(*std::declval().begin()); - using newvalue_t = std::result_of_t; - using result_t = std::conditional_t< - std::is_same_v, - ChangeContainerValueType_t, newvalue_t>, - Rt>; - result_t result; - result.reserve(std::end(container) - std::begin(container)); - std::transform(std::begin(container), std::end(container), makeDefaultInserter(result), function); - return result; - } -} - -template -bool any(T&& container, Fn&& f) -{ - for (auto&& x : container) - { - if (f(x)) - { - return true; - } - } - return false; -} - - -template -bool all(T&& container, Fn&& f) -{ - for (auto&& x : container) - { - if (not f(x)) - { - return false; - } - } - return true; -} diff -r 9ca53009bc5c -r cf9a854b56a9 src/main.cpp --- a/src/main.cpp Tue Jun 28 19:36:03 2022 +0300 +++ b/src/main.cpp Tue Jun 28 19:43:55 2022 +0300 @@ -398,6 +398,17 @@ return subWindow; } +static QSet resolveIdsFromSelection(const ModelData* data) +{ + const auto selection = data->itemSelectionModel->selection(); + QSet selectedIndexes; + for (const QModelIndex& qindex : selection.indexes()) { + const std::size_t row = unsigned_cast(qindex.row()); + selectedIndexes.insert(data->model->idAt(row)); + } + return selectedIndexes; +} + int main(int argc, char *argv[]) { doQtRegistrations(); @@ -513,12 +524,7 @@ [modelId, &documents, &toolWidgets]{ ModelData* data = findModelData(&documents, modelId); if (data != nullptr) { - auto resolveIndex = [&data](const QModelIndex& index){ - return data->model->idAt(unsigned_cast(index.row())); - }; - const auto selection = data->itemSelectionModel->selection(); - const auto indices = fn::map>(selection.indexes(), resolveIndex); - data->canvas->setSelection(indices); + data->canvas->setSelection(resolveIdsFromSelection(data)); /* if (indices.size() == 1) { opt index = data->model->find(*indices.begin());