-rw-r--r-- | library/categorymenu.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/library/categorymenu.cpp b/library/categorymenu.cpp index e733107..5d7adf7 100644 --- a/library/categorymenu.cpp +++ b/library/categorymenu.cpp | |||
@@ -15,39 +15,74 @@ | |||
15 | ** | 15 | ** |
16 | ** Contact info@trolltech.com if any conditions of this licensing are | 16 | ** Contact info@trolltech.com if any conditions of this licensing are |
17 | ** not clear to you. | 17 | ** not clear to you. |
18 | ** | 18 | ** |
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | 20 | ||
21 | #include "categorymenu.h" | 21 | #include "categorymenu.h" |
22 | #include "backend/categories.h" | 22 | #include "backend/categories.h" |
23 | #include "categoryselect.h" | 23 | #include "categoryselect.h" |
24 | #include <qstring.h> | 24 | #include <qstring.h> |
25 | #include <qmap.h> | 25 | #include <qmap.h> |
26 | 26 | ||
27 | /*! | ||
28 | \class CategoryMenu | ||
29 | \brief The CategoryMenu widget aids in filtering records or files by Category. | ||
30 | |||
31 | The CategoryMenu widget provides a popup menu that will make filtering records | ||
32 | or files by category much easier. The widget will lookup the available | ||
33 | categories for an application, populate the menu, and keep a track of which | ||
34 | categories are being filtered against. A set of categories can be tested | ||
35 | by the isSelected() function to see if a record or file containing those | ||
36 | categories would be allowed through by the filter. | ||
37 | |||
38 | \warning Currently this class is not suitable for extending. | ||
39 | |||
40 | \ingroup qtopiaemb | ||
41 | */ | ||
42 | |||
43 | /*! | ||
44 | \fn void CategoryMenu::categoryChange() | ||
45 | This signal is emitted when the user selects a different category in the | ||
46 | menu, hence changing what records or files should be selected. | ||
47 | */ | ||
48 | |||
49 | /*! | ||
50 | Creates a new CategoryMenu with \a parent and \a name. The menu will be | ||
51 | populated with the available categories for \a application. | ||
52 | |||
53 | If \a globals is TRUE then it will also poplulate the menu with the | ||
54 | global categories. | ||
55 | */ | ||
27 | CategoryMenu::CategoryMenu( const QString &n, bool ig = TRUE, | 56 | CategoryMenu::CategoryMenu( const QString &n, bool ig = TRUE, |
28 | QWidget *parent, const char *name ) : | 57 | QWidget *parent, const char *name ) : |
29 | QPopupMenu(parent, name), | 58 | QPopupMenu(parent, name), |
30 | appName(n), | 59 | appName(n), |
31 | includeGlobal(ig) | 60 | includeGlobal(ig) |
32 | { | 61 | { |
33 | currentMid = 1; | 62 | currentMid = 1; |
34 | reload(); | 63 | reload(); |
35 | connect(this, SIGNAL(activated(int)), this, SLOT(mapMenuId(int))); | 64 | connect(this, SIGNAL(activated(int)), this, SLOT(mapMenuId(int))); |
36 | } | 65 | } |
37 | 66 | ||
67 | /*! | ||
68 | Destroys a CategoryMenu. | ||
69 | */ | ||
38 | CategoryMenu::~CategoryMenu( ) | 70 | CategoryMenu::~CategoryMenu( ) |
39 | { | 71 | { |
40 | } | 72 | } |
41 | 73 | ||
74 | /*! | ||
75 | Repopulates the widget's list of available categories. | ||
76 | */ | ||
42 | void CategoryMenu::reload() | 77 | void CategoryMenu::reload() |
43 | { | 78 | { |
44 | clear(); | 79 | clear(); |
45 | Categories c; | 80 | Categories c; |
46 | 81 | ||
47 | c.load(categoryFileName()); | 82 | c.load(categoryFileName()); |
48 | 83 | ||
49 | QStringList sl = c.labels(appName, includeGlobal); | 84 | QStringList sl = c.labels(appName, includeGlobal); |
50 | int mid = 1; | 85 | int mid = 1; |
51 | 86 | ||
52 | insertItem(tr("All"), mid); | 87 | insertItem(tr("All"), mid); |
53 | mid++; | 88 | mid++; |
@@ -57,54 +92,71 @@ void CategoryMenu::reload() | |||
57 | for (QStringList::Iterator it = sl.begin(); | 92 | for (QStringList::Iterator it = sl.begin(); |
58 | it != sl.end(); ++it ) { | 93 | it != sl.end(); ++it ) { |
59 | int cid = c.id(appName, *it); | 94 | int cid = c.id(appName, *it); |
60 | insertItem(*it, mid); | 95 | insertItem(*it, mid); |
61 | menuToId.insert(mid, cid); | 96 | menuToId.insert(mid, cid); |
62 | idToMenu.insert(cid, mid); | 97 | idToMenu.insert(cid, mid); |
63 | mid++; | 98 | mid++; |
64 | } | 99 | } |
65 | 100 | ||
66 | setItemChecked(currentMid, TRUE ); | 101 | setItemChecked(currentMid, TRUE ); |
67 | } | 102 | } |
68 | 103 | ||
104 | /*! | ||
105 | \internal | ||
106 | */ | ||
69 | void CategoryMenu::mapMenuId(int id) | 107 | void CategoryMenu::mapMenuId(int id) |
70 | { | 108 | { |
71 | if (id == currentMid) | 109 | if (id == currentMid) |
72 | return; | 110 | return; |
73 | setItemChecked( currentMid, FALSE ); | 111 | setItemChecked( currentMid, FALSE ); |
74 | setItemChecked( id, TRUE ); | 112 | setItemChecked( id, TRUE ); |
75 | currentMid = id; | 113 | currentMid = id; |
76 | 114 | ||
77 | emit categoryChange(); | 115 | emit categoryChange(); |
78 | } | 116 | } |
79 | 117 | ||
118 | /*! | ||
119 | Returns TRUE if a record or file with the set of category ids \a cUids | ||
120 | is allowed by the current selection in the CategoryMenu. | ||
121 | Otherwise returns FALSE. | ||
122 | */ | ||
80 | bool CategoryMenu::isSelected(const QArray<int> &cUids) const | 123 | bool CategoryMenu::isSelected(const QArray<int> &cUids) const |
81 | { | 124 | { |
82 | if (currentMid == 1) | 125 | if (currentMid == 1) |
83 | return TRUE; | 126 | return TRUE; |
84 | 127 | ||
85 | if (currentMid == 2 && cUids.count() == 0) | 128 | if (currentMid == 2 && cUids.count() == 0) |
86 | return TRUE; | 129 | return TRUE; |
87 | 130 | ||
88 | if (cUids.contains(menuToId[currentMid])) | 131 | if (cUids.contains(menuToId[currentMid])) |
89 | return TRUE; | 132 | return TRUE; |
90 | 133 | ||
91 | return FALSE; | 134 | return FALSE; |
92 | } | 135 | } |
93 | 136 | ||
137 | /*! | ||
138 | Sets the menu to have \a newCatUid as the currently selected Category. | ||
139 | */ | ||
94 | void CategoryMenu::setCurrentCategory( int newCatUid ) | 140 | void CategoryMenu::setCurrentCategory( int newCatUid ) |
95 | { | 141 | { |
96 | if (!idToMenu.contains(newCatUid)) | 142 | if (!idToMenu.contains(newCatUid)) |
97 | return; | 143 | return; |
98 | 144 | ||
99 | mapMenuId(idToMenu[newCatUid]); | 145 | mapMenuId(idToMenu[newCatUid]); |
100 | } | 146 | } |
101 | 147 | ||
148 | /*! | ||
149 | Sets the menu to allow all category sets. | ||
150 | */ | ||
102 | void CategoryMenu::setCurrentCategoryAll( ) | 151 | void CategoryMenu::setCurrentCategoryAll( ) |
103 | { | 152 | { |
104 | mapMenuId(1); | 153 | mapMenuId(1); |
105 | } | 154 | } |
106 | 155 | ||
156 | /*! | ||
157 | Sets the menu to allow only empty category sets. | ||
158 | */ | ||
107 | void CategoryMenu::setCurrentCategoryUnfiled( ) | 159 | void CategoryMenu::setCurrentCategoryUnfiled( ) |
108 | { | 160 | { |
109 | mapMenuId(2); | 161 | mapMenuId(2); |
110 | } | 162 | } |