summaryrefslogtreecommitdiffstats
path: root/examples/checklists
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2011-07-10 15:24:15 -0500
commitbd0f3345a938b35ce6a12f6150373b0955b8dd12 (patch)
tree7a520322212d48ebcb9fbe1087e7fca28b76185c /examples/checklists
downloadqt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.tar.gz
qt3-bd0f3345a938b35ce6a12f6150373b0955b8dd12.zip
Add Qt3 development HEAD version
Diffstat (limited to 'examples/checklists')
-rw-r--r--examples/checklists/checklists.cpp162
-rw-r--r--examples/checklists/checklists.doc29
-rw-r--r--examples/checklists/checklists.h35
-rw-r--r--examples/checklists/checklists.pro11
-rw-r--r--examples/checklists/main.cpp24
5 files changed, 261 insertions, 0 deletions
diff --git a/examples/checklists/checklists.cpp b/examples/checklists/checklists.cpp
new file mode 100644
index 0000000..fd17d09
--- /dev/null
+++ b/examples/checklists/checklists.cpp
@@ -0,0 +1,162 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "checklists.h"
+
+#include <qlistview.h>
+#include <qvbox.h>
+#include <qlabel.h>
+#include <qvaluelist.h>
+#include <qstring.h>
+#include <qpushbutton.h>
+#include <qlayout.h>
+
+/*
+ * Constructor
+ *
+ * Create all child widgets of the CheckList Widget
+ */
+
+CheckLists::CheckLists( QWidget *parent, const char *name )
+ : QWidget( parent, name )
+{
+ QHBoxLayout *lay = new QHBoxLayout( this );
+ lay->setMargin( 5 );
+
+ // create a widget which layouts its childs in a column
+ QVBoxLayout *vbox1 = new QVBoxLayout( lay );
+ vbox1->setMargin( 5 );
+
+ // First child: a Label
+ vbox1->addWidget( new QLabel( "Check some items!", this ) );
+
+ // Second child: the ListView
+ lv1 = new QListView( this );
+ vbox1->addWidget( lv1 );
+ lv1->addColumn( "Items" );
+ lv1->setRootIsDecorated( TRUE );
+
+ // create a list with 4 ListViewItems which will be parent items of other ListViewItems
+ QValueList<QListViewItem *> parentList;
+
+ parentList.append( new QCheckListItem( lv1, "Parent Item 1", QCheckListItem::CheckBoxController ) );
+ parentList.append( new QCheckListItem( lv1, "Parent Item 2", QCheckListItem::CheckBoxController ) );
+ parentList.append( new QCheckListItem( lv1, "Parent Item 3", QCheckListItem::CheckBoxController ) );
+ parentList.append( new QCheckListItem( lv1, "Parent Item 4", QCheckListItem::CheckBoxController ) );
+
+ QListViewItem *item = 0;
+ unsigned int num = 1;
+ // go through the list of parent items...
+ for ( QValueList<QListViewItem*>::Iterator it = parentList.begin(); it != parentList.end();
+ ( *it )->setOpen( TRUE ), ++it, num++ ) {
+ item = *it;
+ // ...and create 5 checkable child ListViewItems for each parent item
+ for ( unsigned int i = 1; i <= 5; i++ )
+ (void)new QCheckListItem( item, QString( "%1. Child of Parent %2" ).arg( i ).arg( num ), QCheckListItem::CheckBox );
+ }
+
+ // Create another widget for layouting
+ QVBoxLayout *tmp = new QVBoxLayout( lay );
+ tmp->setMargin( 5 );
+
+ // create a pushbutton
+ QPushButton *copy1 = new QPushButton( " -> ", this );
+ tmp->addWidget( copy1 );
+ copy1->setMaximumWidth( copy1->sizeHint().width() );
+ // connect the SIGNAL clicked() of the pushbutton with the SLOT copy1to2()
+ connect( copy1, SIGNAL( clicked() ), this, SLOT( copy1to2() ) );
+
+ // another widget for layouting
+ QVBoxLayout *vbox2 = new QVBoxLayout( lay );
+ vbox2->setMargin( 5 );
+
+ // and another label
+ vbox2->addWidget( new QLabel( "Check one item!", this ) );
+
+ // create the second listview
+ lv2 = new QListView( this );
+ vbox2->addWidget( lv2 );
+ lv2->addColumn( "Items" );
+ lv2->setRootIsDecorated( TRUE );
+
+ // another widget needed for layouting only
+ tmp = new QVBoxLayout( lay );
+ tmp->setMargin( 5 );
+
+ // create another pushbutton...
+ QPushButton *copy2 = new QPushButton( " -> ", this );
+ lay->addWidget( copy2 );
+ copy2->setMaximumWidth( copy2->sizeHint().width() );
+ // ...and connect its clicked() SIGNAL to the copy2to3() SLOT
+ connect( copy2, SIGNAL( clicked() ), this, SLOT( copy2to3() ) );
+
+ tmp = new QVBoxLayout( lay );
+ tmp->setMargin( 5 );
+
+ // and create a label which will be at the right of the window
+ label = new QLabel( "No Item yet...", this );
+ tmp->addWidget( label );
+}
+
+/*
+ * SLOT copy1to2()
+ *
+ * Copies all checked ListViewItems from the first ListView to
+ * the second one, and inserts them as Radio-ListViewItem.
+ */
+
+void CheckLists::copy1to2()
+{
+ // create an iterator which operates on the first ListView
+ QListViewItemIterator it( lv1 );
+
+ lv2->clear();
+
+ // Insert first a controller Item into the second ListView. Always if Radio-ListViewItems
+ // are inserted into a Listview, the parent item of these MUST be a controller Item!
+ QCheckListItem *item = new QCheckListItem( lv2, "Controller", QCheckListItem::Controller );
+ item->setOpen( TRUE );
+
+ // iterate through the first ListView...
+ for ( ; it.current(); ++it )
+ // ...check state of childs, and...
+ if ( it.current()->parent() )
+ // ...if the item is checked...
+ if ( ( (QCheckListItem*)it.current() )->isOn() )
+ // ...insert a Radio-ListViewItem with the same text into the second ListView
+ (void)new QCheckListItem( item, it.current()->text( 0 ), QCheckListItem::RadioButton );
+
+ if ( item->firstChild() )
+ ( ( QCheckListItem* )item->firstChild() )->setOn( TRUE );
+}
+
+/*
+ * SLOT copy2to3()
+ *
+ * Copies the checked item of the second ListView into the
+ * Label at the right.
+ */
+
+void CheckLists::copy2to3()
+{
+ // create an iterator which operates on the second ListView
+ QListViewItemIterator it( lv2 );
+
+ label->setText( "No Item checked" );
+
+ // iterate through the second ListView...
+ for ( ; it.current(); ++it )
+ // ...check state of childs, and...
+ if ( it.current()->parent() )
+ // ...if the item is checked...
+ if ( ( (QCheckListItem*)it.current() )->isOn() )
+ // ...set the text of the item to the label
+ label->setText( it.current()->text( 0 ) );
+}
+
diff --git a/examples/checklists/checklists.doc b/examples/checklists/checklists.doc
new file mode 100644
index 0000000..417afe6
--- /dev/null
+++ b/examples/checklists/checklists.doc
@@ -0,0 +1,29 @@
+/*
+*/
+/*! \page checklists-example.html
+
+ \ingroup examples
+ \title Listviews with Checkable Items
+
+ This example program shows how to use listviews with different types of
+ checkable items.
+
+ <hr>
+
+ Header file:
+
+ \include checklists/checklists.h
+
+ <hr>
+
+ Implementation:
+
+ \include checklists/checklists.cpp
+
+ <hr>
+
+ Main:
+
+ \include checklists/main.cpp
+*/
+
diff --git a/examples/checklists/checklists.h b/examples/checklists/checklists.h
new file mode 100644
index 0000000..e6cdd1d
--- /dev/null
+++ b/examples/checklists/checklists.h
@@ -0,0 +1,35 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#ifndef CHECKLISTS_H
+#define CHECKLISTS_H
+
+#include <qwidget.h>
+
+class QListView;
+class QLabel;
+
+class CheckLists : public QWidget
+{
+ Q_OBJECT
+
+public:
+ CheckLists( QWidget *parent = 0, const char *name = 0 );
+
+protected:
+ QListView *lv1, *lv2;
+ QLabel *label;
+
+protected slots:
+ void copy1to2();
+ void copy2to3();
+
+};
+
+#endif
diff --git a/examples/checklists/checklists.pro b/examples/checklists/checklists.pro
new file mode 100644
index 0000000..a1a6f12
--- /dev/null
+++ b/examples/checklists/checklists.pro
@@ -0,0 +1,11 @@
+TEMPLATE = app
+TARGET = checklists
+
+CONFIG += qt warn_on release
+DEPENDPATH = ../../include
+
+REQUIRES = large-config
+
+HEADERS = checklists.h
+SOURCES = checklists.cpp \
+ main.cpp
diff --git a/examples/checklists/main.cpp b/examples/checklists/main.cpp
new file mode 100644
index 0000000..2aa2559
--- /dev/null
+++ b/examples/checklists/main.cpp
@@ -0,0 +1,24 @@
+/****************************************************************************
+**
+** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved.
+**
+** This file is part of an example program for Qt. This example
+** program may be used, distributed and modified without limitation.
+**
+*****************************************************************************/
+
+#include "checklists.h"
+#include <qapplication.h>
+
+int main( int argc, char **argv )
+{
+ QApplication a( argc, argv );
+
+ CheckLists checklists;
+ checklists.resize( 650, 350 );
+ checklists.setCaption( "Qt Example - CheckLists" );
+ a.setMainWidget( &checklists );
+ checklists.show();
+
+ return a.exec();
+}