00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2010 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef MUTUALLYEXCLUSIVELISTWIDGET_H 00011 #define MUTUALLYEXCLUSIVELISTWIDGET_H 00012 00013 #include <QtGui/QWidget> 00014 00015 class QLabel; 00016 class QListWidget; 00017 class QListWidgetItem; 00018 00019 /** 00020 * A widget that allow users to select an ordered set of items from a master 00021 * list. 00022 * 00023 * The mutually exclusive list widget contains two QListWidget objects: one 00024 * list to contain available items to select, and another list to contain 00025 * the ordered set of items selected from the first list. When an item is 00026 * selected from the available items list it is added to the selected items 00027 * list and no longer appears in the available items list. Both list widgets 00028 * are single selection and cannot be sorted. 00029 * 00030 * The widget also contains Add and Remove buttons to transfer items between 00031 * the two lists, and labels to provide a description of each list. 00032 */ 00033 class MutuallyExclusiveListWidget : public QWidget 00034 { 00035 Q_OBJECT 00036 00037 public: 00038 /** 00039 * Creates a new mutually exclusive list widget with empty lists and default 00040 * labels of "Available Items" and "Selected Items". 00041 * 00042 * @param pParent 00043 * The parent widget. 00044 */ 00045 MutuallyExclusiveListWidget(QWidget* pParent = NULL); 00046 00047 /** 00048 * Destroys the mutually exclusive list widget. 00049 */ 00050 virtual ~MutuallyExclusiveListWidget(); 00051 00052 /** 00053 * Sets the text description of the available items list. 00054 * 00055 * @param label 00056 * The available items list description. 00057 * 00058 * @see setSelectedItemsLabel() 00059 */ 00060 void setAvailableItemsLabel(const QString& label); 00061 00062 /** 00063 * Returns the text description of the available items list. 00064 * 00065 * @return The available items list description. 00066 * 00067 * @see getSelectedItemsLabel() 00068 */ 00069 QString getAvailableItemsLabel() const; 00070 00071 /** 00072 * Sets the list of available items to select from. 00073 * 00074 * This methods clears the existing contents of both the available items 00075 * and selected items lists. The method then populates the available items 00076 * list with the given names. To set initially selected items call 00077 * selectItems() after calling this method. 00078 * 00079 * @param items 00080 * The list of available items. 00081 */ 00082 void setAvailableItems(const QStringList& items); 00083 00084 /** 00085 * Returns the list of remaining available items to select from. 00086 * 00087 * This methods returns only the items in the available items list that 00088 * have not been selected. 00089 * 00090 * @return The list of remaining available items. 00091 * 00092 * @see getSelectedItems() 00093 */ 00094 QStringList getAvailableItems() const; 00095 00096 /** 00097 * Sets the text description of the selected items list. 00098 * 00099 * @param label 00100 * The selected items list description. 00101 * 00102 * @see setAvailableItemsLabel() 00103 */ 00104 void setSelectedItemsLabel(const QString& label); 00105 00106 /** 00107 * Returns the text description of the selected items list. 00108 * 00109 * @return The selected items list description. 00110 * 00111 * @see getAvailableItemsLabel() 00112 */ 00113 QString getSelectedItemsLabel() const; 00114 00115 /** 00116 * Returns the list of selected items. 00117 * 00118 * @return The list of selected items. 00119 * 00120 * @see getAvailableItems() 00121 */ 00122 QStringList getSelectedItems() const; 00123 00124 public slots: 00125 /** 00126 * Moves items from the available items list to the selected items list. 00127 * 00128 * @param items 00129 * The items to move from the available items list to the selected 00130 * items list. 00131 * 00132 * @see removeItems() 00133 */ 00134 void selectItems(const QStringList& items); 00135 00136 /** 00137 * Moves items from the selected items list to the available items list. 00138 * 00139 * @param items 00140 * The items to move from the selected items list to the available 00141 * items list. 00142 * 00143 * @see selectItems() 00144 */ 00145 void removeItems(const QStringList& items); 00146 00147 signals: 00148 /** 00149 * A signal that is emitted when an item moves from the available items list 00150 * to the selected items list. 00151 * 00152 * The signal is emitted when the user clicks the Add button or when the 00153 * selectItems() method is called. If multiple items are moved as a result 00154 * of calling selectItems(), the signal is emitted once for each item. 00155 * 00156 * @param item 00157 * The item that moved from the available items list to the 00158 * selected items list. 00159 */ 00160 void itemSelected(const QString& item); 00161 00162 /** 00163 * A signal that is emitted when an item moves from the selected items list 00164 * to the available items list. 00165 * 00166 * The signal is emitted when the user clicks the Remove button or when the 00167 * removeItems() method is called. If multiple items are moved as a result 00168 * of calling removeItems(), the signal is emitted once for each item. 00169 * 00170 * @param item 00171 * The item that moved from the selected items list to the 00172 * available items list. 00173 */ 00174 void itemRemoved(const QString& item); 00175 00176 protected slots: 00177 /** 00178 * Moves the currently selected item in the available items list to the 00179 * selected items list. 00180 * 00181 * This method is called automatically when the user clicks the Add button, 00182 * and should not need to be called explicitly. 00183 */ 00184 void addSelectedItem(); 00185 00186 /** 00187 * Moves the currently selected item in the selected items list to the 00188 * available items list. 00189 * 00190 * This method is called automatically when the user clicks the Remove 00191 * button, and should not need to be called explicitly. 00192 */ 00193 void removeSelectedItem(); 00194 00195 private: 00196 MutuallyExclusiveListWidget(const MutuallyExclusiveListWidget& rhs); 00197 MutuallyExclusiveListWidget& operator=(const MutuallyExclusiveListWidget& rhs); 00198 void selectAvailableItem(QListWidgetItem* pAvailableItem); 00199 void removeSelectedItem(QListWidgetItem* pSelectedItem); 00200 00201 QLabel* mpAvailableLabel; 00202 QListWidget* mpAvailableList; 00203 QLabel* mpSelectedLabel; 00204 QListWidget* mpSelectedList; 00205 }; 00206 00207 #endif