File indexing completed on 2024-05-12 05:10:09
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 #ifndef TELLICO_CSVIMPORTER_H 0026 #define TELLICO_CSVIMPORTER_H 0027 0028 #include "textimporter.h" 0029 #include "../datavectors.h" 0030 0031 class CSVImporterWidget; 0032 0033 class KComboBox; 0034 0035 class QSpinBox; 0036 class QLineEdit; 0037 class QPushButton; 0038 class QCheckBox; 0039 class QRadioButton; 0040 class QTableWidget; 0041 class CsvTest; 0042 0043 namespace Tellico { 0044 namespace GUI { 0045 class CollectionTypeCombo; 0046 } 0047 class CSVParser; 0048 namespace Import { 0049 0050 /** 0051 * @author Robby Stephenson 0052 */ 0053 class CSVImporter : public TextImporter { 0054 Q_OBJECT 0055 0056 friend class ::CsvTest; 0057 0058 public: 0059 /** 0060 */ 0061 CSVImporter(const QUrl& url); 0062 ~CSVImporter(); 0063 0064 /** 0065 * @return A pointer to a @ref Data::Collection, or 0 if none can be created. 0066 */ 0067 virtual Data::CollPtr collection() Q_DECL_OVERRIDE; 0068 /** 0069 * The CSVImporter can import any type known to Tellico. 0070 */ 0071 virtual bool canImport(int type) const Q_DECL_OVERRIDE { Q_UNUSED(type); return true; } 0072 /** 0073 */ 0074 virtual QWidget* widget(QWidget* parent) Q_DECL_OVERRIDE; 0075 0076 virtual bool validImport() const Q_DECL_OVERRIDE; 0077 0078 void setCollectionType(int collType); 0079 void setImportColumns(const QList<int>& columns, const QStringList& fieldNames); 0080 void setDelimiter(const QString& delimeter); 0081 void setColumnDelimiter(const QString& delimeter); 0082 void setRowDelimiter(const QString& delimeter); 0083 0084 public Q_SLOTS: 0085 void slotActionChanged(int action) Q_DECL_OVERRIDE; 0086 void slotCancel() Q_DECL_OVERRIDE; 0087 0088 private Q_SLOTS: 0089 void slotTypeChanged(); 0090 void slotFieldChanged(int idx); 0091 void slotFirstRowHeader(bool b); 0092 void slotDelimiter(); 0093 void slotCurrentChanged(int row, int col); 0094 void slotHeaderClicked(int col); 0095 void slotSelectColumn(int col); 0096 void slotSetColumnTitle(); 0097 0098 private: 0099 void fillTable(); 0100 void updateHeader(); 0101 void createCollection(); 0102 void updateFieldCombo(); 0103 0104 int m_collType; 0105 Data::CollPtr m_coll; 0106 Data::CollPtr m_existingCollection; // used to grab fields from current collection in window 0107 QList<int> m_columnsToImport; 0108 QStringList m_fieldsToImport; 0109 bool m_firstRowHeader; 0110 QString m_delimiter; 0111 QString m_colDelimiter; 0112 QString m_rowDelimiter; 0113 bool m_cancelled; 0114 0115 QWidget* m_widget; 0116 GUI::CollectionTypeCombo* m_comboColl; 0117 QCheckBox* m_checkFirstRowHeader; 0118 QRadioButton* m_radioComma; 0119 QRadioButton* m_radioSemicolon; 0120 QRadioButton* m_radioTab; 0121 QRadioButton* m_radioOther; 0122 QLineEdit* m_editOther; 0123 QLineEdit* m_editColDelimiter; 0124 QLineEdit* m_editRowDelimiter; 0125 QTableWidget* m_table; 0126 QSpinBox* m_colSpinBox; 0127 KComboBox* m_comboField; 0128 QPushButton* m_setColumnBtn; 0129 bool m_hasAssignedFields; 0130 bool m_isLibraryThing; 0131 0132 CSVParser* m_parser; 0133 }; 0134 0135 } // end namespace 0136 } // end namespace 0137 #endif