File indexing completed on 2025-02-23 04:34:23
0001 /** 0002 * \file abstractlistedit.h 0003 * Widget to edit a list. 0004 * 0005 * \b Project: Kid3 0006 * \author Urs Fleisch 0007 * \date 2 Jan 2013 0008 * 0009 * Copyright (C) 2013-2024 Urs Fleisch 0010 * 0011 * This file is part of Kid3. 0012 * 0013 * Kid3 is free software; you can redistribute it and/or modify 0014 * it under the terms of the GNU General Public License as published by 0015 * the Free Software Foundation; either version 2 of the License, or 0016 * (at your option) any later version. 0017 * 0018 * Kid3 is distributed in the hope that it will be useful, 0019 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0021 * GNU General Public License for more details. 0022 * 0023 * You should have received a copy of the GNU General Public License 0024 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0025 */ 0026 0027 #pragma once 0028 0029 #include <QWidget> 0030 0031 class QPushButton; 0032 class QAbstractItemView; 0033 class QAbstractItemModel; 0034 0035 /** 0036 * Widget to edit a string list. 0037 */ 0038 class AbstractListEdit : public QWidget { 0039 Q_OBJECT 0040 public: 0041 /** 0042 * Constructor. 0043 * 0044 * @param itemView item view, e.g. a QListView 0045 * @param model item model, e.g. a QStringListModel 0046 * @param parent parent widget 0047 */ 0048 AbstractListEdit(QAbstractItemView* itemView, 0049 QAbstractItemModel* model, QWidget* parent = nullptr); 0050 0051 /** 0052 * Destructor. 0053 */ 0054 ~AbstractListEdit() override = default; 0055 0056 /** 0057 * Disable editing of items. 0058 * When editing is disabled, the Add, Edit and Remove buttons are hidden. 0059 * @param disable true to disable, false (default) to enable editing. 0060 */ 0061 void setEditingDisabled(bool disable); 0062 0063 /** 0064 * Set text for Add button. 0065 * @param text button text 0066 */ 0067 void setAddButtonText(const QString& text); 0068 0069 public slots: 0070 /** 0071 * Add a new item. 0072 */ 0073 virtual void addItem() = 0; 0074 0075 /** 0076 * Remove the selected item. 0077 */ 0078 void removeItem(); 0079 0080 /** 0081 * Edit the selected item. 0082 */ 0083 virtual void editItem() = 0; 0084 0085 /** 0086 * Move the selected item up. 0087 */ 0088 void moveUpItem(); 0089 0090 /** 0091 * Move the selected item down. 0092 */ 0093 void moveDownItem(); 0094 0095 /** 0096 * Change state of buttons according to the current item and the count. 0097 */ 0098 void setButtonEnableState(); 0099 0100 protected: 0101 /** 0102 * Get item view. 0103 * @return item view. 0104 */ 0105 const QAbstractItemView* getItemView() const { return m_itemView; } 0106 0107 /** 0108 * Hide the Edit button. 0109 */ 0110 void hideEditButton(); 0111 0112 private: 0113 QAbstractItemView* m_itemView; 0114 QPushButton* m_addPushButton; 0115 QPushButton* m_moveUpPushButton; 0116 QPushButton* m_moveDownPushButton; 0117 QPushButton* m_editPushButton; 0118 QPushButton* m_removePushButton; 0119 };