File indexing completed on 2024-04-28 16:32:04
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_KERNEL_H 0026 #define TELLICO_KERNEL_H 0027 0028 #include "datavectors.h" 0029 #include "borrower.h" 0030 0031 class QUndoStack; 0032 class QWidget; 0033 class QString; 0034 class QStringList; 0035 class QUndoCommand; 0036 class QUrl; 0037 0038 namespace Tellico { 0039 class Filter; 0040 namespace Data { 0041 class Collection; 0042 } 0043 0044 /** 0045 * @author Robby Stephenson 0046 */ 0047 class Kernel { 0048 0049 public: 0050 static Kernel* self() { return s_self; } 0051 /** 0052 * Initializes the singleton. Should just be called once, from Tellico::MainWindow 0053 */ 0054 static void init(QWidget* parent) { if(!s_self) s_self = new Kernel(parent); } 0055 0056 /** 0057 * Returns a pointer to the parent widget. This is mainly used for error dialogs and the like. 0058 * 0059 * @return The widget pointer 0060 */ 0061 QWidget* widget() { return m_widget; } 0062 0063 /** 0064 * Returns the url of the current document. 0065 * 0066 * @return The URL 0067 */ 0068 QUrl URL() const; 0069 0070 int collectionType() const; 0071 QString collectionTypeName() const; 0072 0073 void sorry(const QString& text, QWidget* widget=nullptr); 0074 0075 void beginCommandGroup(const QString& name); 0076 void endCommandGroup(); 0077 void resetHistory(); 0078 0079 bool addField(Data::FieldPtr field); 0080 bool modifyField(Data::FieldPtr field); 0081 bool removeField(Data::FieldPtr field); 0082 0083 void addEntries(Data::EntryList entries, bool checkFields); 0084 void modifyEntries(Data::EntryList oldEntries, Data::EntryList newEntries, const QStringList& modifiedFields); 0085 void updateEntry(Data::EntryPtr oldEntry, Data::EntryPtr newEntry, bool overWrite); 0086 void removeEntries(Data::EntryList entries); 0087 0088 bool addLoans(Data::EntryList entries); 0089 bool modifyLoan(Data::LoanPtr loan); 0090 bool removeLoans(Data::LoanList loans); 0091 0092 void addFilter(FilterPtr filter); 0093 bool modifyFilter(FilterPtr filter); 0094 bool removeFilter(FilterPtr filter); 0095 0096 void reorderFields(const Data::FieldList& fields); 0097 0098 void appendCollection(Data::CollPtr coll); 0099 void mergeCollection(Data::CollPtr coll); 0100 void replaceCollection(Data::CollPtr coll); 0101 0102 void renameCollection(); 0103 QUndoStack* commandHistory() { return m_commandHistory; } 0104 0105 int askAndMerge(Data::EntryPtr entry1, Data::EntryPtr entry2, Data::FieldPtr field, 0106 QString value1 = QString(), QString value2 = QString()); 0107 0108 private: 0109 static Kernel* s_self; 0110 0111 // all constructors are private 0112 Kernel(QWidget* parent); 0113 Q_DISABLE_COPY(Kernel) 0114 ~Kernel(); 0115 0116 void doCommand(QUndoCommand* command); 0117 0118 QWidget* m_widget; 0119 QUndoStack* m_commandHistory; 0120 }; 0121 0122 } // end namespace 0123 #endif