File indexing completed on 2024-09-22 05:16:07
0001 /* 0002 This file is part of the Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2006-2008 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "selectcontroller.hpp" 0010 0011 // Kasten gui 0012 #include <Kasten/DataSelectable> 0013 #include <Kasten/AbstractView> 0014 // KF 0015 #include <KXMLGUIClient> 0016 #include <KLocalizedString> 0017 #include <KActionCollection> 0018 #include <KStandardAction> 0019 // Qt 0020 #include <QAction> 0021 0022 namespace Kasten { 0023 0024 SelectController::SelectController(KXMLGUIClient* guiClient) 0025 { 0026 mSelectAllAction = KStandardAction::selectAll(this, &SelectController::selectAll, this); 0027 mDeselectAction = KStandardAction::deselect( this, &SelectController::unselect, this); 0028 0029 KActionCollection* actionCollection = guiClient->actionCollection(); 0030 actionCollection->addAction(mSelectAllAction->objectName(), mSelectAllAction); 0031 actionCollection->addAction(mDeselectAction->objectName(), mDeselectAction); 0032 0033 setTargetModel(nullptr); 0034 } 0035 0036 void SelectController::setTargetModel(AbstractModel* model) 0037 { 0038 if (mModel) { 0039 mModel->disconnect(this); 0040 } 0041 0042 mModel = model ? model->findBaseModelWithInterface<If::DataSelectable*>() : nullptr; 0043 mSelectControl = mModel ? qobject_cast<If::DataSelectable*>(mModel) : nullptr; 0044 0045 const bool hasSelectionControl = (mSelectControl != nullptr); 0046 if (hasSelectionControl) { 0047 connect(mModel, SIGNAL(hasSelectedDataChanged(bool)), SLOT(onHasSelectedDataChanged(bool))); 0048 } 0049 0050 mSelectAllAction->setEnabled(hasSelectionControl); 0051 mDeselectAction->setEnabled(hasSelectionControl ? mSelectControl->hasSelectedData() : false); 0052 } 0053 0054 void SelectController::onHasSelectedDataChanged(bool hasSelectedData) 0055 { 0056 mDeselectAction->setEnabled(hasSelectedData); 0057 } 0058 0059 void SelectController::selectAll() 0060 { 0061 mSelectControl->selectAllData(true); 0062 } 0063 0064 void SelectController::unselect() 0065 { 0066 mSelectControl->selectAllData(false); 0067 } 0068 0069 } 0070 0071 #include "moc_selectcontroller.cpp"