File indexing completed on 2024-04-28 05:08:19

0001 /***************************************************************************
0002     Copyright (C) 2001-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_ENTRYEDITDIALOG_H
0026 #define TELLICO_ENTRYEDITDIALOG_H
0027 
0028 #include "observer.h"
0029 #include "gui/fieldwidget.h"
0030 
0031 #include <QDialog>
0032 #include <QHash>
0033 
0034 namespace Tellico {
0035   namespace GUI {
0036     class TabWidget;
0037   }
0038 
0039 /**
0040  * @author Robby Stephenson
0041  */
0042 class EntryEditDialog : public QDialog, public Observer {
0043 Q_OBJECT
0044 
0045 // needed for completion object support
0046 friend class GUI::FieldWidget;
0047 
0048 public:
0049   EntryEditDialog(QWidget* parent);
0050   ~EntryEditDialog();
0051 
0052   /**
0053    * Checks to see if any data needs to be saved. Returns @p true if it's ok to continue with
0054    * saving or closing the widget.
0055    *
0056    * @return Returns @p true if either the data has not been modified or the user to save or discard the new data.
0057    */
0058   bool queryModified();
0059   /**
0060    * Deletes and resets the layout of the tabs.
0061    *
0062    * @param coll A pointer to the collection whose fields should be used for setting up the layout
0063    */
0064   void resetLayout(Data::CollPtr coll);
0065   /**
0066    * Clears all of the input controls in the widget. The pointer to the
0067    * current entry is nullified, but not the pointer to the current collection.
0068    */
0069   void clear();
0070 
0071   virtual void    addEntries(Data::EntryList entries) Q_DECL_OVERRIDE;
0072   virtual void modifyEntries(Data::EntryList entries) Q_DECL_OVERRIDE;
0073 
0074   virtual void    addField(Data::CollPtr coll, Data::FieldPtr field) Q_DECL_OVERRIDE;
0075   /**
0076    * Updates a widget when its field has been modified. The category may have changed, completions may have
0077    * been added or removed, or what-have-you.
0078    *
0079    * @param coll A pointer to the parent collection
0080    * @param oldField A pointer to the old field, which should have the same name as the new one
0081    * @param newField A pointer to the new field
0082    */
0083   virtual void modifyField(Data::CollPtr coll, Data::FieldPtr oldField, Data::FieldPtr newField) Q_DECL_OVERRIDE;
0084   /**
0085    * Removes a field from the editor.
0086    *
0087    * @param field The field to be removed
0088    */
0089   virtual void removeField(Data::CollPtr, Data::FieldPtr field) Q_DECL_OVERRIDE;
0090 
0091 public Q_SLOTS:
0092   /**
0093    * Called when the Close button is clicked. It just hides the dialog.
0094    */
0095   virtual void slotClose();
0096   /**
0097    * Resets the widget, deleting all of its contents
0098    */
0099   void slotReset();
0100   /**
0101    * Handles clicking the New button. The old entry pointer is destroyed and a
0102    * new one is created, but not added to any collection.
0103    */
0104   void slotHandleNew();
0105   /**
0106    * Handles clicking the Save button. All the values in the entry widgets are
0107    * copied into the entry object. @ref signalSaveEntry is made. The widget is cleared,
0108    * and the first tab is shown.
0109    */
0110   void slotHandleSave();
0111   /**
0112    * This slot is called whenever anything is modified. It's public so I can call it
0113    * from a @ref FieldEditWidget.
0114    */
0115   void slotSetModified(bool modified=true);
0116   /**
0117    * Sets the contents of the input controls to match the contents of a list of entries.
0118    *
0119    * @param list A list of the entries. The data in the first one will be inserted in the controls, and
0120    * the widgets will be enabled or not, depending on whether the rest of the entries match the first one.
0121    */
0122   void setContents(Tellico::Data::EntryList entries);
0123   /**
0124    * Override the implementation to check whether the entry needs to be modified
0125    */
0126   virtual void reject() Q_DECL_OVERRIDE;
0127 
0128 protected Q_SLOTS:
0129   void slotHelp();
0130 
0131 private Q_SLOTS:
0132   void fieldValueChanged(Tellico::Data::FieldPtr field);
0133   void fieldChanged(Tellico::Data::FieldPtr field);
0134 
0135 private:
0136   /**
0137    * Sets the contents of the input controls to match the contents of a entry.
0138    *
0139    * @param entry A pointer to the entry
0140    * @param highlight An optional string to highlight
0141    */
0142   void setEntry(Data::EntryPtr entry);
0143   /**
0144    * Updates the completion objects in the edit boxes to include values
0145    * contained in a certain entry.
0146    *
0147    * @param entry A pointer to the entry
0148    */
0149   void updateCompletions(Data::EntryPtr entry);
0150   virtual void showEvent(QShowEvent* event) Q_DECL_OVERRIDE;
0151   virtual void hideEvent(QHideEvent* event) Q_DECL_OVERRIDE;
0152   virtual void closeEvent(QCloseEvent* event) Q_DECL_OVERRIDE;
0153 
0154   Data::CollPtr m_currColl;
0155   Data::EntryList m_currEntries;
0156   GUI::TabWidget* m_tabs;
0157   QHash<QString, GUI::FieldWidget*> m_widgetDict;
0158 
0159   QPushButton* m_newButton;
0160   QPushButton* m_saveButton;
0161 
0162   bool m_modified;
0163   Data::FieldList m_modifiedFields;
0164   bool m_isOrphan;
0165   bool m_isWorking;
0166   bool m_needReset;
0167 };
0168 
0169 } // end namespace
0170 #endif