File indexing completed on 2024-05-12 05:09:47
0001 /*************************************************************************** 0002 Copyright (C) 2003-2009 Robby Stephenson <robby@periapsis.org> 0003 ***************************************************************************/ 0004 0005 /*************************************************************************** 0006 * * 0007 * This program is free software; you can redistribute it and/or * 0008 * modify it under the terms of the GNU General Public License as * 0009 * published by the Free Software Foundation; either version 2 of * 0010 * the License or (at your option) version 3 or any later version * 0011 * accepted by the membership of KDE e.V. (or its successor approved * 0012 * by the membership of KDE e.V.), which shall act as a proxy * 0013 * defined in Section 14 of version 3 of the license. * 0014 * * 0015 * This program is distributed in the hope that it will be useful, * 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0018 * GNU General Public License for more details. * 0019 * * 0020 * You should have received a copy of the GNU General Public License * 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 0022 * * 0023 ***************************************************************************/ 0024 0025 // The layout borrows heavily from kmsearchpatternedit.cpp in kmail 0026 // which is authored by Marc Mutz <Marc@Mutz.com> under the GPL 0027 0028 #include "filterrulewidgetlister.h" 0029 #include "filterrulewidget.h" 0030 #include "../filter.h" 0031 #include "../tellico_debug.h" 0032 0033 using Tellico::FilterRuleWidgetLister; 0034 0035 namespace { 0036 static const int FILTER_MIN_RULE_WIDGETS = 1; 0037 static const int FILTER_MAX_RULES = 8; 0038 } 0039 0040 FilterRuleWidgetLister::FilterRuleWidgetLister(QWidget* parent_) 0041 : KWidgetLister(FILTER_MIN_RULE_WIDGETS, FILTER_MAX_RULES, parent_) { 0042 // slotClear(); 0043 connect(this, &KWidgetLister::clearWidgets, this, &FilterRuleWidgetLister::signalModified); 0044 } 0045 0046 void FilterRuleWidgetLister::setFilter(Tellico::FilterPtr filter_) { 0047 // if(mWidgetList.first()) { // move this below next 'if'? 0048 // mWidgetList.first()->blockSignals(true); 0049 // } 0050 0051 if(filter_->isEmpty()) { 0052 slotClear(); 0053 // mWidgetList.first()->blockSignals(false); 0054 return; 0055 } 0056 0057 const int count = filter_->count(); 0058 if(count > mMaxWidgets) { 0059 myDebug() << "more rules than allowed!"; 0060 } 0061 0062 // set the right number of widgets 0063 setNumberOfShownWidgetsTo(qMax(count, mMinWidgets)); 0064 0065 // load the actions into the widgets 0066 int i = 0; 0067 for( ; i < filter_->count(); ++i) { 0068 static_cast<FilterRuleWidget*>(mWidgetList.at(i))->setRule(filter_->at(i)); 0069 } 0070 for( ; i < mWidgetList.count(); ++i) { // clear any remaining 0071 static_cast<FilterRuleWidget*>(mWidgetList.at(i))->reset(); 0072 } 0073 0074 // mWidgetList.first()->blockSignals(false); 0075 } 0076 0077 void FilterRuleWidgetLister::reset() { 0078 slotClear(); 0079 } 0080 0081 void FilterRuleWidgetLister::setFocus() { 0082 if(!mWidgetList.isEmpty()) { 0083 mWidgetList.at(0)->setFocus(); 0084 } 0085 } 0086 0087 QWidget* FilterRuleWidgetLister::createWidget(QWidget* parent_) { 0088 FilterRuleWidget* w = new FilterRuleWidget(static_cast<Tellico::FilterRule*>(nullptr), parent_); 0089 connect(w, &FilterRuleWidget::signalModified, this, &FilterRuleWidgetLister::signalModified); 0090 return w; 0091 } 0092 0093 void FilterRuleWidgetLister::clearWidget(QWidget* widget_) { 0094 if(widget_) { 0095 static_cast<FilterRuleWidget*>(widget_)->reset(); 0096 } 0097 } 0098 0099 QList<QWidget*> FilterRuleWidgetLister::widgetList() const { 0100 return mWidgetList; 0101 }