On 04/17/2011 06:46 AM, Vincent van Ravesteijn wrote:
On 13-4-2011 16:26, venom00 wrote:

+                               // Try to cast to the most common widgets and 
looks in it's content by each
+                               // It's bad OOP, it would be nice to have a 
QWidget::toString() overloaded by
+                               // each widget, but this would require to 
change Qt or subclass each widget.
+                               // Note that we have to ignore the amperstand 
symbol
+                               if (QAbstractButton * button = 
qobject_cast<QAbstractButton *>(children[child_index])) {
+                                       widget_matches = (new 
QString(button->text()))->replace('&', "")
+                                               .contains(search, 
Qt::CaseInsensitive);
+
+                               } else if (QGroupBox * group_box = 
qobject_cast<QGroupBox *>(children[child_index])) {
+                                       widget_matches = (new 
QString(group_box->title()))->replace('&', "")
+                                               .contains(search, 
Qt::CaseInsensitive);
+
+                               } else if (QLabel * label = qobject_cast<QLabel 
*>(children[child_index])) {
+                                       widget_matches = (new 
QString(label->text()))->replace('&', "")
+                                               .contains(search, 
Qt::CaseInsensitive);
+
+                               } else if (QLineEdit * line_edit = 
qobject_cast<QLineEdit *>(children[child_index])) {
+                                       widget_matches = (new 
QString(line_edit->text()))->replace('&', "")
+                                               .contains(search, 
Qt::CaseInsensitive);
+
+                               } else if (QListWidget * list_widget = 
qobject_cast<QListWidget *>(children[child_index])) {
+                                       widget_matches = 
(list_widget->findItems(search, Qt::MatchContains)).count() != 0;
+
+                               } else if (QTreeWidget * tree_view = 
qobject_cast<QTreeWidget *>(children[child_index])) {
+                                       widget_matches = 
(tree_view->findItems(search, Qt::MatchContains)).count() != 0;
+
+                               } else if (QComboBox * combo_box = 
qobject_cast<QComboBox *>(children[child_index])) {
+                                       widget_matches = 
(combo_box->findText(search, Qt::MatchContains)) != -1;
+
+                               } else {
+                                       continue;
+                               }
+

This is really ugly, but I can't think of how to solve it right now.

Would using typeid help a little bit?

rh

Reply via email to