summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael D Scull <ext-michael.scull@nokia.com>2010-06-23 15:19:49 (GMT)
committerDavid Boddie <dboddie@trolltech.com>2010-07-07 15:10:04 (GMT)
commitca10c2c5a8190cac9c2ae0526f2e250add09d6f2 (patch)
treeb139acbf3f7a5cfd25a9980f78324ff6abeca27a
parent6de484f195366b560e10f95b04d2f0e7303a2b63 (diff)
downloadQt-ca10c2c5a8190cac9c2ae0526f2e250add09d6f2.zip
Qt-ca10c2c5a8190cac9c2ae0526f2e250add09d6f2.tar.gz
Qt-ca10c2c5a8190cac9c2ae0526f2e250add09d6f2.tar.bz2
correction of snippet tags
-rwxr-xr-xdoc/src/tutorials/modelview.qdoc41
-rwxr-xr-xexamples/tutorials/modelview/._.DS_Storebin0 -> 4096 bytes
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/main.cpp2
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/modelview.cpp3
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/modelview.h3
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/mymodel.cpp2
-rwxr-xr-xexamples/tutorials/modelview/1_readonly/mymodel.h2
-rwxr-xr-xexamples/tutorials/modelview/2_formatting/mymodel.cpp3
-rwxr-xr-xexamples/tutorials/modelview/3_changingmodel/mymodel.cpp7
-rwxr-xr-xexamples/tutorials/modelview/4_headers/mymodel.cpp3
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mymodel.cpp8
-rwxr-xr-xexamples/tutorials/modelview/5_edit/mymodel.h2
-rwxr-xr-xexamples/tutorials/modelview/6_treeview/modelview.cpp2
-rwxr-xr-xexamples/tutorials/modelview/7_selections/modelview.cpp6
-rwxr-xr-xexamples/tutorials/modelview/qmake.pro10
15 files changed, 57 insertions, 37 deletions
diff --git a/doc/src/tutorials/modelview.qdoc b/doc/src/tutorials/modelview.qdoc
index 1be4b46..3c73a80 100755
--- a/doc/src/tutorials/modelview.qdoc
+++ b/doc/src/tutorials/modelview.qdoc
@@ -1,9 +1,7 @@
/*!
- \page modelview.html
- \startpage {index.html}{Qt Reference Documentation}
- \contentspage Tutorials
\contentspage{modelview.html}{Crash Course in Model/View Programming}
+ \page modelview.html
\title Crash Course in Model/View Programming
Contents:
@@ -71,16 +69,16 @@ Below are 7 very simple and independent applications that show different sides o
We start with an application that uses a \l QTableView to show data. We will add editing capabilities later.
-------------------------------------------------------------main.cpp---------------------
- \snippet examples/tutorials/modelview/1_readonly/main.cpp
+ \snippet examples/tutorials/modelview/1_readonly/main.cpp Quoting ModelView Tutorial
We have the usual main() function;
-------------------------------------------------------------modelview.h---------------------
- \snippet examples/tutorials/modelview/1_readonly/modelview.h
+ \snippet examples/tutorials/modelview/1_readonly/modelview.h Quoting ModelView Tutorial
The application is a \l QMainWindow that holds a \l QTableView.
-------------------------------------------------------------modelview.cpp---------------------
- \snippet examples/tutorials/modelview/1_readonly/modelview.cpp
+ \snippet examples/tutorials/modelview/1_readonly/modelview.cpp Quoting ModelView Tutorial
Here is the interesting part: We use \c tableView->setModel(new MyModel(this) ); to instantiate the Model and pass its pointer to \l {QTableView::}{tableView()} OR \l QTableView::tableView() OR \l QTableView::tableView . \l {QTableView::}{tableView} will invoke the methods of the pointer it has received to find out two things:
\list
@@ -92,13 +90,13 @@ The model needs some code to respond to this.
We have a table data set, so let's start with QAbstractTableModel since it is easier to use.
-------------------------------------------------------------mymodel.h---------------------
- \snippet examples/tutorials/modelview/1_readonly/mymodel.h
+ \snippet examples/tutorials/modelview/1_readonly/mymodel.h Quoting ModelView Tutorial
QAbstractTableModel requires the implementation of three abstract methods.
-------------------------------------------------------------mymodel.cpp---------------------
- \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp
+ \snippet examples/tutorials/modelview/1_readonly/mymodel.cpp Quoting ModelView Tutorial
The number of rows and columns is set by \c MyModel::rowCount() and \c MyModel::columnCount().
When the view has to know what the cell 's text is, it calls the \l{QAbstractItemModel::data()}{data()} method. Row and column information is specified with parameter \c index and the role is set to Qt::Display Role. Other roles are covered in the next section. In our example, the data that should be displayed is generated. In a real application, \c MyModel would have a member called \c MyData, which serves as the target for all reading and writing operations.
@@ -114,7 +112,7 @@ In addition to controlling what text the view displays, the model also controls
In fact, nothing except for the \l{QAbstractItemModel::data()}{data()} method needs to be changed to set fonts, background colour, alignment and a checkbox. Here is the \l{QAbstractItemModel::data()}{data()} method that produces the result shown above:
-------------------------------------------------------------mymodel.cpp---------------------
- \snippet examples/tutorials/modelview/2_formatting/mymodel.cpp
+ \snippet examples/tutorials/modelview/2_formatting/mymodel.cpp Quoting ModelView Tutorial
Each formatting property will be requested from the model with a separate call to the \l{QAbstractItemModel::data()}{data()} method. The \c role parameter is used to let the model know which property is being requested:
@@ -178,7 +176,6 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const
Something is missing to make the clock tick. We need to tell the view every second that the time has changed and that it needs to be read again. We do this with a timer. In the constructor, we set its interval to 1 second and it connect its timeout signal.
-?????(include section from 3_changingmodel/mymodel.cpp)?????
\code
MyModel::MyModel(QObject *parent)
:QAbstractTableModel(parent)
@@ -193,7 +190,6 @@ MyModel::MyModel(QObject *parent)
Here is the corresponding slot:
-?????(include section from 3_changingmodel/mymodel.cpp)?????
\code
void MyModel::timerHit()
@@ -215,8 +211,6 @@ Headers can be hidden via a view method.
The header content, however , is set via the model, so we reimplement the \l{QAbstractItemModel::headerData()}{headerData()} method:
-
-?????(include section from 4_headers/mymodel.cpp)?????
\code
QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const
{
@@ -244,11 +238,10 @@ In this example, we are going to build an application that automatically populat
The model decides whether editing capabilities are available . We only have to modify the model in order for the available editing capabilities to be enabled. This is done by reimplementing the following virtual methods: \l{QAbstractItemModel::setData()}{setData()} and \l{QAbstractItemModel::flags()}{flags()}.
-------------------------------------------------------------mymodel.h---------------------
- \snippet examples/tutorials/modelview/5_edit/mymodel.h
+ \snippet examples/tutorials/modelview/5_edit/mymodel.h Quoting ModelView Tutorial
We use \c QStringList m_gridData to store our data. This makes \c m_gridData the core of MyModel. The rest of \c MyModel acts like a wrapper and adapts \c m_gridData to the QAbstractItemModel interface. We have also introduced the \l{QAbstractItemModel::editCompleted()}{editCompleted()} signal, which makes it possible to transfer the modified text to the window title.
-?????(include section from 5_edit/mymodel.cpp)?????
\code
#include "mymodel.h"
@@ -264,16 +257,10 @@ MyModel::MyModel(QObject *parent)
\endcode
In the constructor, we fill \c QStringList gridData with 6 items. (one item for every field in the table)
-?????(include section from 5_edit/mymodel.cpp)?????
-\code
-HIER FEHLT WAS!!!
-\endcode
+ \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_e
\l{QAbstractItemModel::setData()}{setData()} will be called each time the user edits a cell. The \c index parameter tells us which field has been edited and \c value provides the result of the editing process. The role will always be set to \c Qt::EditRole because our cells only contain text. If a checkbox were present and user permissions are set to allow the checkbox to be selected, calls would also be made with the role set to \c Qt::CheckStateRole.
-?????(include section from 5_edit/mymodel.cpp)?????
-\code
-HIER FEHLT WAS!!!
-\endcode
+ \snippet examples/tutorials/modelview/5_edit/mymodel.cpp quoting mymodel_f
Various properties of a cell can be adjusted with \l{QAbstractItemModel::flags()}{flags()}. Returning \c Qt::ItemIsEditable | Qt::ItemIsEnabled is enough to show an editor that a cell has been selected. If editing one cell modifies more data than the data in that particular cell, the model must emit a \l{QAbstractItemModel::dataChanged()}{dataChanged()} signal in order for the data that has been changed to be read.
@@ -292,7 +279,7 @@ This is how our example model looks so far:
We want to, however, present a real tree. We have wrapped our data in the examples above in order to make a model. This time we use QStandardItemModel, which is a container for hierarchical data that also implements QAbstractItemModel. To show a tree, QStandardItemModel must be populated with QStandardItems, which are able to hold all the standard properties of items like text, fonts, checkboxes or brushes. \image tree_2_with_algorithm.png
-------------------------------------------------------------modelview.cpp---------------------
- \snippet examples/tutorials/modelview/6_treeview/modelview.cpp
+ \snippet examples/tutorials/modelview/6_treeview/modelview.cpp Quoting ModelView Tutorial
We simply instantiate a QStandardItemModel and add a couple of QStandardItems to the constructor. We can then make a hierarchical data structure because a QStandardItem can hold other QStandardItems. Nodes are collapsed and expanded within the view.
@@ -302,7 +289,6 @@ We want to access a selected item's content in order to output it into the windo
So let's create a couple of items:
-?????(include section from 7_selections/modelview.cpp)?????
\code
#include <QTreeView>
#include <QStandardItemModel>
@@ -351,10 +337,7 @@ ModelView::ModelView(QWidget *parent)
Views manage selections within a separate selection model, which can be retrieved with the \l{QAbstractItemModel::selectionModel()}{selectionModel()} method. We retrieve the selection Model in order to connect a slot to its \l{QAbstractItemModel::selectionChanged()}{selectionChanged()} signal.
-?????(include section from 7_selections/modelview.cpp)?????
-\code
-HIER FEHLT WAS!!!
-\endcode
+ \snippet examples/tutorials/modelview/7_selections/modelview.cpp quoting modelview_b
We get the model index that corresponds to the selection by calling
\c treeView->selectionModel()->currentIndex() and we get the the field's string by using the model index. Then we just calculate the item's \c hierarchyLevel. Top level items do not have parents and the \l{QAbstractItemModel::parent()}{parent()} method will return a default constructed QModelIndex(). This is why we use the \l{QAbstractItemModel::parent()}{parent()} method to iterate to the top level while counting the steps performed during iteration.
diff --git a/examples/tutorials/modelview/._.DS_Store b/examples/tutorials/modelview/._.DS_Store
new file mode 100755
index 0000000..338bd7b
--- /dev/null
+++ b/examples/tutorials/modelview/._.DS_Store
Binary files differ
diff --git a/examples/tutorials/modelview/1_readonly/main.cpp b/examples/tutorials/modelview/1_readonly/main.cpp
index 998503c..bdf740c 100755
--- a/examples/tutorials/modelview/1_readonly/main.cpp
+++ b/examples/tutorials/modelview/1_readonly/main.cpp
@@ -1,3 +1,4 @@
+//! [Quoting ModelView Tutorial]
#include <QtGui/QApplication>
#include "modelview.h"
@@ -8,3 +9,4 @@ int main(int argc, char *argv[])
w.show();
return a.exec();
}
+//! [Quoting ModelView Tutorial] \ No newline at end of file
diff --git a/examples/tutorials/modelview/1_readonly/modelview.cpp b/examples/tutorials/modelview/1_readonly/modelview.cpp
index becd61d..14311f9 100755
--- a/examples/tutorials/modelview/1_readonly/modelview.cpp
+++ b/examples/tutorials/modelview/1_readonly/modelview.cpp
@@ -1,3 +1,4 @@
+//! [Quoting ModelView Tutorial]
#include <QTableView>
#include "modelview.h"
#include "mymodel.h"
@@ -9,4 +10,4 @@ ModelView::ModelView(QWidget *parent)
setCentralWidget(tableView);
tableView->setModel(new MyModel(this) );
}
-
+//! [Quoting ModelView Tutorial] \ No newline at end of file
diff --git a/examples/tutorials/modelview/1_readonly/modelview.h b/examples/tutorials/modelview/1_readonly/modelview.h
index f1b63bd..93b6b90 100755
--- a/examples/tutorials/modelview/1_readonly/modelview.h
+++ b/examples/tutorials/modelview/1_readonly/modelview.h
@@ -1,6 +1,8 @@
+//! [Quoting ModelView Tutorial]
#ifndef MODELVIEW_H
#define MODELVIEW_H
+
#include <QtGui/QMainWindow>
class QTableView; //forward declaration
@@ -16,3 +18,4 @@ public:
};
#endif // MODELVIEW_H
+//! [Quoting ModelView Tutorial] \ No newline at end of file
diff --git a/examples/tutorials/modelview/1_readonly/mymodel.cpp b/examples/tutorials/modelview/1_readonly/mymodel.cpp
index ff3e2d2..3386907 100755
--- a/examples/tutorials/modelview/1_readonly/mymodel.cpp
+++ b/examples/tutorials/modelview/1_readonly/mymodel.cpp
@@ -1,3 +1,4 @@
+//! [Quoting ModelView Tutorial]
#include "mymodel.h"
MyModel::MyModel(QObject *parent)
@@ -28,3 +29,4 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const
}
return QVariant();
}
+//! [Quoting ModelView Tutorial] \ No newline at end of file
diff --git a/examples/tutorials/modelview/1_readonly/mymodel.h b/examples/tutorials/modelview/1_readonly/mymodel.h
index 01ae6cb..aac1bf0 100755
--- a/examples/tutorials/modelview/1_readonly/mymodel.h
+++ b/examples/tutorials/modelview/1_readonly/mymodel.h
@@ -1,3 +1,4 @@
+//! [Quoting ModelView Tutorial]
#ifndef MYMODEL_H
#define MYMODEL_H
@@ -14,3 +15,4 @@ public:
};
#endif // MYMODEL_H
+//! [Quoting ModelView Tutorial] \ No newline at end of file
diff --git a/examples/tutorials/modelview/2_formatting/mymodel.cpp b/examples/tutorials/modelview/2_formatting/mymodel.cpp
index 48b1134..916dabc 100755
--- a/examples/tutorials/modelview/2_formatting/mymodel.cpp
+++ b/examples/tutorials/modelview/2_formatting/mymodel.cpp
@@ -3,6 +3,7 @@
#include "mymodel.h"
#include <QDebug>
+//! [Quoting ModelView Tutorial]
MyModel::MyModel(QObject *parent)
:QAbstractTableModel(parent)
{
@@ -70,4 +71,4 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const
}
return QVariant();
}
-
+//! [Quoting ModelView Tutorial]
diff --git a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp
index d594175..fa7f566 100755
--- a/examples/tutorials/modelview/3_changingmodel/mymodel.cpp
+++ b/examples/tutorials/modelview/3_changingmodel/mymodel.cpp
@@ -3,7 +3,7 @@
#include <QBrush>
#include "mymodel.h"
-
+//! [quoting mymodel_a]
MyModel::MyModel(QObject *parent)
:QAbstractTableModel(parent)
{
@@ -13,7 +13,7 @@ MyModel::MyModel(QObject *parent)
connect(timer, SIGNAL(timeout()) , this, SLOT(timerHit()) );
timer->start();
}
-
+//! [quoting mymodel_a]
//-------------------------------------------------------
int MyModel::rowCount(const QModelIndex & /*parent */ ) const
{
@@ -43,6 +43,7 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const
}
//-------------------------------------------------------
+//! [quoting mymodel_b ]
void MyModel::timerHit()
{
//we identify the top left cell
@@ -50,4 +51,4 @@ void MyModel::timerHit()
//emit a signal to make the view reread identified data
emit dataChanged ( topLeft, topLeft );
}
-
+//! [quoting mymodel_b ]
diff --git a/examples/tutorials/modelview/4_headers/mymodel.cpp b/examples/tutorials/modelview/4_headers/mymodel.cpp
index a032fe5..7891c80 100755
--- a/examples/tutorials/modelview/4_headers/mymodel.cpp
+++ b/examples/tutorials/modelview/4_headers/mymodel.cpp
@@ -29,7 +29,7 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const
return QVariant();
}
-
+//! [quoting mymodel_c]
QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role == Qt::DisplayRole)
@@ -48,3 +48,4 @@ QVariant MyModel::headerData(int section, Qt::Orientation orientation, int role)
}
return QVariant();
}
+//! [quoting mymodel_c] \ No newline at end of file
diff --git a/examples/tutorials/modelview/5_edit/mymodel.cpp b/examples/tutorials/modelview/5_edit/mymodel.cpp
index c64a6b7..ef45bc3 100755
--- a/examples/tutorials/modelview/5_edit/mymodel.cpp
+++ b/examples/tutorials/modelview/5_edit/mymodel.cpp
@@ -1,3 +1,4 @@
+//! [quoting mymodel_d]
#include "mymodel.h"
const int COLS= 3;
@@ -9,7 +10,9 @@ MyModel::MyModel(QObject *parent)
//gridData needs to have 6 element, one for each table cell
m_gridData << "1/1" << "1/2" << "1/3" << "2/1" << "2/2" << "2/3" ;
}
+//! [quoting mymodel_d]
+//! [quoting mymodel_e]
//-------------------------------------------------------
int MyModel::rowCount(const QModelIndex & /*parent*/ ) const
{
@@ -31,8 +34,11 @@ QVariant MyModel::data(const QModelIndex &index, int role ) const
}
return QVariant();
}
+//! [quoting mymodel_e]
//-----------------------------------------------------------------
+
+//! [quoting mymodel_f]
bool MyModel::setData ( const QModelIndex & index, const QVariant & value, int role )
{
if(role == Qt::EditRole)
@@ -55,4 +61,4 @@ int MyModel::modelIndexToOffset(const QModelIndex & index) const
{
return index.row()*COLS + index.column();
}
-
+//! [quoting mymodel_f]
diff --git a/examples/tutorials/modelview/5_edit/mymodel.h b/examples/tutorials/modelview/5_edit/mymodel.h
index f8fac77..1612fa0 100755
--- a/examples/tutorials/modelview/5_edit/mymodel.h
+++ b/examples/tutorials/modelview/5_edit/mymodel.h
@@ -1,3 +1,4 @@
+//! [Quoting ModelView Tutorial]
#ifndef MYMODEL_H
#define MYMODEL_H
@@ -22,3 +23,4 @@ signals:
};
#endif // MYMODEL_H
+//! [Quoting ModelView Tutorial] \ No newline at end of file
diff --git a/examples/tutorials/modelview/6_treeview/modelview.cpp b/examples/tutorials/modelview/6_treeview/modelview.cpp
index a5488f7..b5b4d06 100755
--- a/examples/tutorials/modelview/6_treeview/modelview.cpp
+++ b/examples/tutorials/modelview/6_treeview/modelview.cpp
@@ -1,3 +1,4 @@
+//! [Quoting ModelView Tutorial]
#include <QTreeView>
#include <QStandardItemModel>
#include <QStandardItem>
@@ -38,3 +39,4 @@ QList<QStandardItem *> ModelView::prepareColumn(const QString &first,
colItems << new QStandardItem(third);
return colItems;
}
+//! [Quoting ModelView Tutorial] \ No newline at end of file
diff --git a/examples/tutorials/modelview/7_selections/modelview.cpp b/examples/tutorials/modelview/7_selections/modelview.cpp
index 49c5bb8..eac6df9 100755
--- a/examples/tutorials/modelview/7_selections/modelview.cpp
+++ b/examples/tutorials/modelview/7_selections/modelview.cpp
@@ -1,3 +1,4 @@
+//! [quoting modelview_a]
#include <QTreeView>
#include <QStandardItemModel>
#include <QItemSelectionModel>
@@ -41,8 +42,11 @@ ModelView::ModelView(QWidget *parent)
connect(selectionModel, SIGNAL(selectionChanged ( const QItemSelection & , const QItemSelection & )),
this, SLOT(selectionChangedSlot(const QItemSelection & , const QItemSelection & )));
}
+//! [quoting modelview_a]
//------------------------------------------------------------------------------------
+
+//! [quoting modelview_b]
void ModelView::selectionChangedSlot(const QItemSelection & /*newSelection*/, const QItemSelection & /*oldSelection*/)
{
const QModelIndex index = treeView->selectionModel()->currentIndex();
@@ -58,6 +62,6 @@ void ModelView::selectionChangedSlot(const QItemSelection & /*newSelection*/, co
.arg(hierarchyLevel);
setWindowTitle(showString);
}
-
+//! [quoting modelview_b]
diff --git a/examples/tutorials/modelview/qmake.pro b/examples/tutorials/modelview/qmake.pro
new file mode 100755
index 0000000..7f684ba
--- /dev/null
+++ b/examples/tutorials/modelview/qmake.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+
+SUBDIRS = 1_readonly \
+ 2_formatting \
+ 3_changingmodel \
+ 4_headers \
+ 5_edit \
+ 6_treeview \
+ 7_selections
+