File indexing completed on 2024-05-12 16:40:55
0001 /* This file is part of the KDE project 0002 Copyright (C) 2004-2012 Jarosław Staniek <staniek@kde.org> 0003 0004 This library is free software; you can redistribute it and/or 0005 modify it under the terms of the GNU Library General Public 0006 License as published by the Free Software Foundation; either 0007 version 2 of the License, or (at your option) any later version. 0008 0009 This library is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0012 Library General Public License for more details. 0013 0014 You should have received a copy of the GNU Library General Public License 0015 along with this library; see the file COPYING.LIB. If not, write to 0016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0017 * Boston, MA 02110-1301, USA. 0018 */ 0019 0020 #ifndef KEXINAMEDIALOG_H 0021 #define KEXINAMEDIALOG_H 0022 0023 #include "kexiextwidgets_export.h" 0024 #include <core/kexiproject.h> 0025 #include <core/kexipart.h> 0026 0027 #include <QDialog> 0028 0029 class QDialogButtonBox; 0030 class KexiNameWidget; 0031 class KexiNameDialog; 0032 0033 //! Validator that can be used to check validity of data entered into KexiNameDialog 0034 class KEXIEXTWIDGETS_EXPORT KexiNameDialogValidator 0035 { 0036 public: 0037 KexiNameDialogValidator(); 0038 virtual ~KexiNameDialogValidator(); 0039 0040 //! For implementation. Validates data entered into dialog @a dialog. 0041 //! @return true if the data if valid. 0042 virtual bool validate(KexiNameDialog *dialog) const = 0; 0043 }; 0044 0045 //! A dialog displaying object's name and caption and allowing editing. 0046 //! @see KexiNameWidget 0047 class KEXIEXTWIDGETS_EXPORT KexiNameDialog : public QDialog 0048 { 0049 Q_OBJECT 0050 0051 public: 0052 explicit KexiNameDialog(const QString& message, QWidget * parent = 0); 0053 0054 KexiNameDialog(const QString& message, 0055 const QString& nameLabel, const QString& nameText, 0056 const QString& captionLabel, const QString& captionText, 0057 QWidget * parent = 0); 0058 0059 virtual ~KexiNameDialog(); 0060 0061 KexiNameWidget* widget() const; 0062 0063 QDialogButtonBox* buttonBox(); 0064 0065 void setDialogIcon(const QString &iconName); 0066 0067 /*! Shows the dialog as a modal dialog, blocking until the user closes it, like QDialog::exec() 0068 but uses @a project and @a part to check if object of given type and name already exists. 0069 If so, warning or question is displayed. 0070 You can check @a overwriteNeeded after calling this method. 0071 If it's true, user agreed on overwriting, if it's false, user picked 0072 nonexisting name, so no overwrite will be needed. */ 0073 int execAndCheckIfObjectExists(const KexiProject &project, const KexiPart::Part &part, 0074 bool *overwriteNeeded); 0075 0076 //! If set to true, the dialog will ask for overwriting the existing object if needed. 0077 //! If set to false, the dialog will inform about existing object and reject renaming. 0078 //! False by default. 0079 void setAllowOverwriting(bool set); 0080 0081 //! Sets validator that will be used to check validity of data entered into this KexiNameDialog. 0082 //! Validation occurs before any other checks. 0083 //! Passes ownership of @a validator to this name dialog. 0084 //! Previous validator is removed. 0 an be passed. 0085 void setValidator(KexiNameDialogValidator *validator); 0086 0087 protected Q_SLOTS: 0088 void slotTextChanged(); 0089 virtual void accept() override; 0090 void updateSize(); 0091 0092 protected: 0093 void init(); 0094 virtual void showEvent(QShowEvent * event) override; 0095 //! Checks if specified name already exists. 0096 bool canOverwrite(); 0097 0098 private: 0099 class Private; 0100 Private * const d; 0101 }; 0102 0103 #endif