File indexing completed on 2024-05-12 05:09:47

0001 /***************************************************************************
0002     Copyright (C) 2021 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 #include "fieldwidgetfactory.h"
0026 #include "fieldwidget.h"
0027 #include "linefieldwidget.h"
0028 #include "parafieldwidget.h"
0029 #include "boolfieldwidget.h"
0030 #include "choicefieldwidget.h"
0031 #include "numberfieldwidget.h"
0032 #include "urlfieldwidget.h"
0033 #include "imagefieldwidget.h"
0034 #include "datefieldwidget.h"
0035 #include "tablefieldwidget.h"
0036 #include "ratingfieldwidget.h"
0037 #include "../tellico_debug.h"
0038 
0039 Tellico::GUI::FieldWidget* Tellico::GUI::FieldWidgetFactory::create(Tellico::Data::FieldPtr field_, QWidget* parent_) {
0040   if(field_->hasFlag(Data::Field::NoEdit) ||
0041      field_->hasFlag(Data::Field::Derived)) {
0042     myWarning() << "read-only/dependent field, this shouldn't have been called";
0043     return nullptr;
0044   }
0045   switch(field_->type()) {
0046     case Data::Field::Line:
0047       return new LineFieldWidget(field_, parent_);
0048 
0049     case Data::Field::Para:
0050       return new ParaFieldWidget(field_, parent_);
0051 
0052     case Data::Field::Bool:
0053       return new BoolFieldWidget(field_, parent_);
0054 
0055     case Data::Field::Number:
0056       return new NumberFieldWidget(field_, parent_);
0057 
0058     case Data::Field::Choice:
0059       return new GUI::ChoiceFieldWidget(field_, parent_);
0060 
0061     case Data::Field::Table:
0062     case Data::Field::Table2:
0063       return new TableFieldWidget(field_, parent_);
0064 
0065     case Data::Field::Date:
0066       return new DateFieldWidget(field_, parent_);
0067 
0068     case Data::Field::URL:
0069       return new URLFieldWidget(field_, parent_);
0070 
0071     case Data::Field::Image:
0072       return new ImageFieldWidget(field_, parent_);
0073 
0074     case Data::Field::Rating:
0075       return new RatingFieldWidget(field_, parent_);
0076 
0077     default:
0078       myWarning() << "unknown field type = " << field_->type();
0079       return nullptr;
0080   }
0081 }