A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQDesignerCustomWidgetInterface</id>
		<title>C++/Qt/QDesignerCustomWidgetInterface - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQDesignerCustomWidgetInterface"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QDesignerCustomWidgetInterface&amp;action=history"/>
		<updated>2026-04-18T22:08:40Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QDesignerCustomWidgetInterface&amp;diff=1204&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QDesignerCustomWidgetInterface&amp;diff=1204&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QDesignerCustomWidgetInterface&amp;diff=1205&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QDesignerCustomWidgetInterface&amp;diff=1205&amp;oldid=prev"/>
				<updated>2010-05-25T10:25:08Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==extends QDesignerCustomWidgetInterface==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
Foundations of Qt Development\Chapter06\designerplugin\circlebar.cpp&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;QPaintEvent&amp;gt;&lt;br /&gt;
#include &amp;lt;QWheelEvent&amp;gt;&lt;br /&gt;
#include &amp;lt;QPainter&amp;gt;&lt;br /&gt;
#include &amp;quot;circlebar.h&amp;quot;&lt;br /&gt;
CircleBar::CircleBar( QWidget *parent ) : QWidget( parent )&lt;br /&gt;
{&lt;br /&gt;
  m_value = 0;&lt;br /&gt;
  &lt;br /&gt;
  QSizePolicy policy( QSizePolicy::Preferred, QSizePolicy::Preferred );&lt;br /&gt;
  policy.setHeightForWidth( true );&lt;br /&gt;
  setSizePolicy( policy );&lt;br /&gt;
}&lt;br /&gt;
CircleBar::CircleBar( int value, QWidget *parent ) : QWidget( parent )&lt;br /&gt;
{&lt;br /&gt;
  m_value = value;&lt;br /&gt;
  &lt;br /&gt;
  QSizePolicy policy( QSizePolicy::Preferred, QSizePolicy::Preferred );&lt;br /&gt;
  policy.setHeightForWidth( true );&lt;br /&gt;
  setSizePolicy( policy );&lt;br /&gt;
}&lt;br /&gt;
int CircleBar::heightForWidth( int width ) const&lt;br /&gt;
{&lt;br /&gt;
  return width;&lt;br /&gt;
}&lt;br /&gt;
QSize CircleBar::sizeHint() const&lt;br /&gt;
{&lt;br /&gt;
  return QSize( 100, 100 );&lt;br /&gt;
}&lt;br /&gt;
int CircleBar::value() const&lt;br /&gt;
{&lt;br /&gt;
  return m_value;&lt;br /&gt;
}&lt;br /&gt;
void CircleBar::setValue( int value )&lt;br /&gt;
{&lt;br /&gt;
  if( value &amp;lt; 0 )&lt;br /&gt;
    value = 0;&lt;br /&gt;
  &lt;br /&gt;
  if( value &amp;gt; 100 )&lt;br /&gt;
    value = 100;&lt;br /&gt;
    &lt;br /&gt;
  if( m_value == value )&lt;br /&gt;
    return;&lt;br /&gt;
    &lt;br /&gt;
  m_value = value;&lt;br /&gt;
  update();&lt;br /&gt;
  emit valueChanged( m_value );&lt;br /&gt;
}&lt;br /&gt;
void CircleBar::paintEvent( QPaintEvent *event )&lt;br /&gt;
{&lt;br /&gt;
  int radius = width()/2;&lt;br /&gt;
  double factor = m_value/100.0;&lt;br /&gt;
  &lt;br /&gt;
  QPainter p( this );&lt;br /&gt;
  p.setPen( Qt::black );&lt;br /&gt;
  p.drawEllipse( 0, 0, width()-1, width()-1 );&lt;br /&gt;
  p.setBrush( Qt::black );&lt;br /&gt;
  p.drawEllipse( int(radius*(1.0-factor)), int(radius*(1.0-factor)), int((width()-1)*factor)+1, int((width()-1)*factor)+1 );&lt;br /&gt;
}&lt;br /&gt;
void CircleBar::wheelEvent( QWheelEvent *event )&lt;br /&gt;
{&lt;br /&gt;
  event-&amp;gt;accept();&lt;br /&gt;
  setValue( value() + event-&amp;gt;delta()/20 );&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Foundations of Qt Development\Chapter06\designerplugin\circlebar.h&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
#ifndef CIRCLEBAR_H&lt;br /&gt;
#define CIRCLEBAR_H&lt;br /&gt;
#include &amp;lt;QWidget&amp;gt;&lt;br /&gt;
#include &amp;lt;QtDesigner&amp;gt;&lt;br /&gt;
class QDESIGNER_WIDGET_EXPORT CircleBar : public QWidget&lt;br /&gt;
{&lt;br /&gt;
  Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
  CircleBar( QWidget *parent = 0 );&lt;br /&gt;
  CircleBar( int value = 0, QWidget *parent = 0 );&lt;br /&gt;
  &lt;br /&gt;
  int value() const;&lt;br /&gt;
  &lt;br /&gt;
  int heightForWidth( int ) const;&lt;br /&gt;
  QSize sizeHint() const;  &lt;br /&gt;
public slots:&lt;br /&gt;
  void setValue( int );&lt;br /&gt;
  &lt;br /&gt;
signals:&lt;br /&gt;
  void valueChanged( int );&lt;br /&gt;
  &lt;br /&gt;
protected:&lt;br /&gt;
  void paintEvent( QPaintEvent* );&lt;br /&gt;
  void wheelEvent( QWheelEvent* );&lt;br /&gt;
  &lt;br /&gt;
private:&lt;br /&gt;
  int m_value;&lt;br /&gt;
};&lt;br /&gt;
#endif // CIRCLEBAR_H&lt;br /&gt;
&lt;br /&gt;
Foundations of Qt Development\Chapter06\designerplugin\circlebarplugin.cpp&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
#include &amp;lt;QtPlugin&amp;gt;&lt;br /&gt;
#include &amp;lt;QExtensionManager&amp;gt;&lt;br /&gt;
#include &amp;lt;QDesignerFormEditorInterface&amp;gt;&lt;br /&gt;
#include &amp;lt;QTimer&amp;gt;&lt;br /&gt;
#include &amp;quot;circlebar.h&amp;quot;&lt;br /&gt;
#include &amp;quot;circlebarplugin.h&amp;quot;&lt;br /&gt;
CircleBarPlugin::CircleBarPlugin( QObject *parent )&lt;br /&gt;
{&lt;br /&gt;
    m_initialized = false;&lt;br /&gt;
}&lt;br /&gt;
bool CircleBarPlugin::isInitialized() const&lt;br /&gt;
{&lt;br /&gt;
    return m_initialized;&lt;br /&gt;
}&lt;br /&gt;
void CircleBarPlugin::initialize( QDesignerFormEditorInterface *core )&lt;br /&gt;
{&lt;br /&gt;
    if( m_initialized )&lt;br /&gt;
        return;&lt;br /&gt;
    m_initialized = true;&lt;br /&gt;
}&lt;br /&gt;
bool CircleBarPlugin::isContainer() const&lt;br /&gt;
{&lt;br /&gt;
    return false;&lt;br /&gt;
}&lt;br /&gt;
QIcon CircleBarPlugin::icon() const&lt;br /&gt;
{&lt;br /&gt;
    return QIcon();&lt;br /&gt;
}&lt;br /&gt;
QString CircleBarPlugin::toolTip() const&lt;br /&gt;
{&lt;br /&gt;
    return &amp;quot;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
QString CircleBarPlugin::whatsThis() const&lt;br /&gt;
{&lt;br /&gt;
    return &amp;quot;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
QString CircleBarPlugin::codeTemplate() const&lt;br /&gt;
{&lt;br /&gt;
    return &amp;quot;&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
QString CircleBarPlugin::includeFile() const&lt;br /&gt;
{&lt;br /&gt;
    return &amp;quot;circlebar.h&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
QString CircleBarPlugin::name() const&lt;br /&gt;
{&lt;br /&gt;
    return &amp;quot;CircleBar&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
QString CircleBarPlugin::domXml() const&lt;br /&gt;
{&lt;br /&gt;
    return &amp;quot;&amp;lt;widget class=\&amp;quot;CircleBar\&amp;quot; name=\&amp;quot;circleBar\&amp;quot;&amp;gt;\n&amp;quot;&lt;br /&gt;
           &amp;quot;&amp;lt;/widget&amp;gt;\n&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
QString CircleBarPlugin::group() const&lt;br /&gt;
{&lt;br /&gt;
    return &amp;quot;Book Widgets&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
QWidget *CircleBarPlugin::createWidget( QWidget *parent )&lt;br /&gt;
{&lt;br /&gt;
    return new CircleBar( parent );&lt;br /&gt;
}&lt;br /&gt;
Q_EXPORT_PLUGIN2( circleBarPlugin, CircleBarPlugin )&lt;br /&gt;
&lt;br /&gt;
Foundations of Qt Development\Chapter06\designerplugin\circlebarplugin.h&lt;br /&gt;
/*&lt;br /&gt;
 * Copyright (c) 2006-2007, Johan Thelin&lt;br /&gt;
 * &lt;br /&gt;
 * All rights reserved.&lt;br /&gt;
 * &lt;br /&gt;
 * Redistribution and use in source and binary forms, with or without modification, &lt;br /&gt;
 * are permitted provided that the following conditions are met:&lt;br /&gt;
 * &lt;br /&gt;
 *     * Redistributions of source code must retain the above copyright notice, &lt;br /&gt;
 *       this list of conditions and the following disclaimer.&lt;br /&gt;
 *     * Redistributions in binary form must reproduce the above copyright notice,  &lt;br /&gt;
 *       this list of conditions and the following disclaimer in the documentation &lt;br /&gt;
 *       and/or other materials provided with the distribution.&lt;br /&gt;
 *     * Neither the name of APress nor the names of its contributors &lt;br /&gt;
 *       may be used to endorse or promote products derived from this software &lt;br /&gt;
 *       without specific prior written permission.&lt;br /&gt;
 * &lt;br /&gt;
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS&lt;br /&gt;
 * &amp;quot;AS IS&amp;quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT&lt;br /&gt;
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR&lt;br /&gt;
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR&lt;br /&gt;
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,&lt;br /&gt;
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,&lt;br /&gt;
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR&lt;br /&gt;
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF&lt;br /&gt;
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING&lt;br /&gt;
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS&lt;br /&gt;
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&lt;br /&gt;
 *&lt;br /&gt;
 */&lt;br /&gt;
#ifndef CIRCLEBARPLUGIN_H&lt;br /&gt;
#define CIRCLEBARPLUGIN_H&lt;br /&gt;
#include &amp;lt;QDesignerCustomWidgetInterface&amp;gt;&lt;br /&gt;
class QExtensionManager;&lt;br /&gt;
class CircleBarPlugin : public QObject, public QDesignerCustomWidgetInterface&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
    Q_INTERFACES(QDesignerCustomWidgetInterface)&lt;br /&gt;
public:&lt;br /&gt;
    CircleBarPlugin( QObject *parent = 0 );&lt;br /&gt;
    bool isContainer() const;&lt;br /&gt;
    bool isInitialized() const;&lt;br /&gt;
    QIcon icon() const;&lt;br /&gt;
    QString codeTemplate() const;&lt;br /&gt;
    QString domXml() const;&lt;br /&gt;
    QString group() const;&lt;br /&gt;
    QString includeFile() const;&lt;br /&gt;
    QString name() const;&lt;br /&gt;
    QString toolTip() const;&lt;br /&gt;
    QString whatsThis() const;&lt;br /&gt;
    QWidget *createWidget( QWidget *parent );&lt;br /&gt;
    void initialize( QDesignerFormEditorInterface *core );&lt;br /&gt;
private:&lt;br /&gt;
    bool m_initialized;&lt;br /&gt;
};&lt;br /&gt;
#endif /* CIRCLEBARPLUGIN_H */&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Model view controller==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the documentation of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef VIEW_H&lt;br /&gt;
#define VIEW_H&lt;br /&gt;
#include &amp;lt;QAbstractItemView&amp;gt;&lt;br /&gt;
#include &amp;lt;QItemSelection&amp;gt;&lt;br /&gt;
#include &amp;lt;QItemSelectionModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QModelIndex&amp;gt;&lt;br /&gt;
#include &amp;lt;QRect&amp;gt;&lt;br /&gt;
#include &amp;lt;QSize&amp;gt;&lt;br /&gt;
#include &amp;lt;QWidget&amp;gt;&lt;br /&gt;
class LinearView : public QAbstractItemView&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    LinearView(QWidget *parent = 0);&lt;br /&gt;
    QRect itemViewportRect(const QModelIndex &amp;amp;index) const;&lt;br /&gt;
    void ensureVisible(const QModelIndex &amp;amp;index);&lt;br /&gt;
    QModelIndex itemAt(int x, int y) const;&lt;br /&gt;
protected slots:&lt;br /&gt;
    /*void dataChanged(const QModelIndex &amp;amp;topLeft, const QModelIndex&lt;br /&gt;
    &amp;amp;bottomRight);*/&lt;br /&gt;
    void rowsInserted(const QModelIndex &amp;amp;parent, int start, int end);&lt;br /&gt;
    void rowsRemoved(const QModelIndex &amp;amp;parent, int start, int end);&lt;br /&gt;
    /*void selectionChanged(const QItemSelection &amp;amp;deselected, const QItemSelection &amp;amp;selected);&lt;br /&gt;
    void verticalScrollbarAction(int action);&lt;br /&gt;
    void horizontalScrollbarAction(int action);*/&lt;br /&gt;
protected:&lt;br /&gt;
    void setSelection(const QRect&amp;amp;, QItemSelectionModel::SelectionFlags command);&lt;br /&gt;
    QRect selectionViewportRect(const QItemSelection &amp;amp;selection) const;&lt;br /&gt;
    QRect itemRect(const QModelIndex &amp;amp;item) const;&lt;br /&gt;
    bool isIndexHidden(const QModelIndex &amp;amp;index) const;&lt;br /&gt;
    int horizontalOffset() const;&lt;br /&gt;
    int verticalOffset() const;&lt;br /&gt;
    QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction,&lt;br /&gt;
                           Qt::KeyboardModifiers modifiers);&lt;br /&gt;
    void paintEvent(QPaintEvent *event);&lt;br /&gt;
    void resizeEvent(QResizeEvent *event);&lt;br /&gt;
    QSize sizeHint() const;&lt;br /&gt;
private:&lt;br /&gt;
    int rows(const QModelIndex &amp;amp;index = QModelIndex()) const;&lt;br /&gt;
    void updateGeometries();&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*!&lt;br /&gt;
    view.cpp&lt;br /&gt;
    Provides a view to represent a one-dimensional sequence of integers&lt;br /&gt;
    obtained from a list model as a series of rows.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;QAbstractItemModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QBrush&amp;gt;&lt;br /&gt;
#include &amp;lt;QItemSelection&amp;gt;&lt;br /&gt;
#include &amp;lt;QPainter&amp;gt;&lt;br /&gt;
#include &amp;lt;QPaintEvent&amp;gt;&lt;br /&gt;
#include &amp;lt;QPen&amp;gt;&lt;br /&gt;
#include &amp;lt;QPoint&amp;gt;&lt;br /&gt;
#include &amp;lt;QResizeEvent&amp;gt;&lt;br /&gt;
#include &amp;lt;QScrollBar&amp;gt;&lt;br /&gt;
#include &amp;lt;QSizePolicy&amp;gt;&lt;br /&gt;
#include &amp;quot;view.h&amp;quot;&lt;br /&gt;
LinearView::LinearView(QWidget *parent)&lt;br /&gt;
    : QAbstractItemView(parent)&lt;br /&gt;
{&lt;br /&gt;
    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the position of the item in viewport coordinates.&lt;br /&gt;
*/&lt;br /&gt;
QRect LinearView::itemViewportRect(const QModelIndex &amp;amp;index) const&lt;br /&gt;
{&lt;br /&gt;
    QRect rect = itemRect(index);&lt;br /&gt;
    QRect result(rect.left() - horizontalScrollBar()-&amp;gt;value(),&lt;br /&gt;
                 rect.top() - verticalScrollBar()-&amp;gt;value(),&lt;br /&gt;
                 rect.width(), viewport()-&amp;gt;height());&lt;br /&gt;
    return result;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the rectangle of the item at position \a index in the&lt;br /&gt;
    model. The rectangle is in contents coordinates.&lt;br /&gt;
*/&lt;br /&gt;
QRect LinearView::itemRect(const QModelIndex &amp;amp;index) const&lt;br /&gt;
{&lt;br /&gt;
    if (!index.isValid())&lt;br /&gt;
        return QRect();&lt;br /&gt;
    else&lt;br /&gt;
        return QRect(index.row(), 0, 1, 1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void LinearView::ensureVisible(const QModelIndex &amp;amp;index)&lt;br /&gt;
{&lt;br /&gt;
    QRect area = viewport()-&amp;gt;rect();&lt;br /&gt;
    QRect rect = itemViewportRect(index);&lt;br /&gt;
    if (rect.left() &amp;lt; area.left())&lt;br /&gt;
        horizontalScrollBar()-&amp;gt;setValue(&lt;br /&gt;
            horizontalScrollBar()-&amp;gt;value() - rect.left());&lt;br /&gt;
    else if (rect.right() &amp;gt; area.right())&lt;br /&gt;
        horizontalScrollBar()-&amp;gt;setValue(&lt;br /&gt;
            horizontalScrollBar()-&amp;gt;value() + rect.left() - area.width());&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the item that covers the coordinate given in the view.&lt;br /&gt;
*/&lt;br /&gt;
QModelIndex LinearView::itemAt(int x, int /* y */) const&lt;br /&gt;
{&lt;br /&gt;
    int row = x + horizontalScrollBar()-&amp;gt;value();&lt;br /&gt;
    return model()-&amp;gt;index(row, 0, QModelIndex());&lt;br /&gt;
}&lt;br /&gt;
//void LinearView::dataChanged(const QModelIndex &amp;amp;/* topLeft */,&lt;br /&gt;
//    const QModelIndex &amp;amp;/* bottomRight */)&lt;br /&gt;
//{&lt;br /&gt;
//    updateGeometries();&lt;br /&gt;
//    if (isVisible())&lt;br /&gt;
//        repaint();&lt;br /&gt;
//}&lt;br /&gt;
void LinearView::rowsInserted(const QModelIndex &amp;amp;/* parent */, int /* start */,&lt;br /&gt;
    int /* end */)&lt;br /&gt;
{&lt;br /&gt;
    updateGeometries();&lt;br /&gt;
    if (isVisible())&lt;br /&gt;
        repaint();&lt;br /&gt;
}&lt;br /&gt;
void LinearView::rowsRemoved(const QModelIndex &amp;amp;/* parent */, int /* start */,&lt;br /&gt;
    int /* end */)&lt;br /&gt;
{&lt;br /&gt;
    updateGeometries();&lt;br /&gt;
    if (isVisible())&lt;br /&gt;
        repaint();&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
void LinearView::verticalScrollbarAction(int action)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
void LinearView::horizontalScrollbarAction(int action)&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
*/&lt;br /&gt;
/*!&lt;br /&gt;
    Select the items in the model that lie within the rectangle specified by&lt;br /&gt;
    \a rect, using the selection \a command.&lt;br /&gt;
*/&lt;br /&gt;
void LinearView::setSelection(const QRect &amp;amp;rect, QItemSelectionModel::SelectionFlags command)&lt;br /&gt;
{&lt;br /&gt;
    QModelIndex leftIndex = itemAt(rect.left(), 0);&lt;br /&gt;
    QModelIndex rightIndex = itemAt(rect.right(), 0);&lt;br /&gt;
    QItemSelection selection(leftIndex, rightIndex);&lt;br /&gt;
    selectionModel()-&amp;gt;select(selection, command);&lt;br /&gt;
}&lt;br /&gt;
QModelIndex LinearView::moveCursor(QAbstractItemView::CursorAction cursorAction,&lt;br /&gt;
                                   Qt::KeyboardModifiers)&lt;br /&gt;
{&lt;br /&gt;
    QModelIndex current = currentIndex();&lt;br /&gt;
    switch (cursorAction) {&lt;br /&gt;
    case MoveLeft:{&lt;br /&gt;
        if (current.row() &amp;gt; 0)&lt;br /&gt;
            return model()-&amp;gt;index(current.row() - 1, 0, QModelIndex());&lt;br /&gt;
        else&lt;br /&gt;
            return model()-&amp;gt;index(0, 0, QModelIndex());&lt;br /&gt;
        break;}&lt;br /&gt;
    case MoveRight:{&lt;br /&gt;
        if (current.row() &amp;lt; rows(current) - 1)&lt;br /&gt;
            return model()-&amp;gt;index(current.row() + 1, 0, QModelIndex());&lt;br /&gt;
        else&lt;br /&gt;
            return model()-&amp;gt;index(rows(current) - 1, 0,QModelIndex());&lt;br /&gt;
        break;}&lt;br /&gt;
    case MoveUp:&lt;br /&gt;
        return current;&lt;br /&gt;
    case MoveDown:&lt;br /&gt;
        return current;&lt;br /&gt;
    case MovePageUp:&lt;br /&gt;
        return current;&lt;br /&gt;
    case MovePageDown:&lt;br /&gt;
        return current;&lt;br /&gt;
    case MoveHome:&lt;br /&gt;
        return model()-&amp;gt;index(0, 0, QModelIndex());&lt;br /&gt;
    case MoveEnd:&lt;br /&gt;
        return model()-&amp;gt;index(rows(current) - 1, 0, QModelIndex());&lt;br /&gt;
    default:&lt;br /&gt;
        return current;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
int LinearView::horizontalOffset() const&lt;br /&gt;
{&lt;br /&gt;
    return horizontalScrollBar()-&amp;gt;value();&lt;br /&gt;
}&lt;br /&gt;
int LinearView::verticalOffset() const&lt;br /&gt;
{&lt;br /&gt;
    return verticalScrollBar()-&amp;gt;value();&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns a rectangle corresponding to the selection in viewport cooridinates.&lt;br /&gt;
*/&lt;br /&gt;
QRect LinearView::selectionViewportRect(const QItemSelection &amp;amp;selection) const&lt;br /&gt;
{&lt;br /&gt;
    int ranges = selection.count();&lt;br /&gt;
    if (ranges == 0)&lt;br /&gt;
        return QRect();&lt;br /&gt;
    // Note that we use the top and bottom functions of the selection range&lt;br /&gt;
    // since the data is stored in rows.&lt;br /&gt;
    int firstRow = selection.at(0).top();&lt;br /&gt;
    int lastRow = selection.at(0).top();&lt;br /&gt;
    for (int i = 0; i &amp;lt; ranges; ++i) {&lt;br /&gt;
        firstRow = qMin(firstRow, selection.at(i).top());&lt;br /&gt;
        lastRow = qMax(lastRow, selection.at(i).bottom());&lt;br /&gt;
    }&lt;br /&gt;
    QModelIndex firstItem = model()-&amp;gt;index(qMin(firstRow, lastRow), 0,&lt;br /&gt;
        QModelIndex());&lt;br /&gt;
    QModelIndex lastItem = model()-&amp;gt;index(qMax(firstRow, lastRow), 0,&lt;br /&gt;
        QModelIndex());&lt;br /&gt;
    QRect firstRect = itemViewportRect(firstItem);&lt;br /&gt;
    QRect lastRect = itemViewportRect(lastItem);&lt;br /&gt;
    return QRect(firstRect.left(), firstRect.top(),&lt;br /&gt;
        lastRect.right() - firstRect.left(), firstRect.height());&lt;br /&gt;
}&lt;br /&gt;
void LinearView::paintEvent(QPaintEvent *event)&lt;br /&gt;
{&lt;br /&gt;
    QPainter painter(viewport());&lt;br /&gt;
    QRect updateRect = event-&amp;gt;rect();&lt;br /&gt;
    QBrush background(Qt::black);&lt;br /&gt;
    QPen foreground(Qt::white);&lt;br /&gt;
    painter.fillRect(updateRect, background);&lt;br /&gt;
    painter.setPen(foreground);&lt;br /&gt;
    QModelIndex firstItem = itemAt(updateRect.left(), updateRect.top());&lt;br /&gt;
    if (!firstItem.isValid())&lt;br /&gt;
        firstItem = model()-&amp;gt;index(0, 0, QModelIndex());&lt;br /&gt;
    QModelIndex lastItem = itemAt(updateRect.right(), updateRect.bottom());&lt;br /&gt;
    if (!lastItem.isValid())&lt;br /&gt;
        lastItem = model()-&amp;gt;index(rows() - 1, 0, QModelIndex());&lt;br /&gt;
    int x = updateRect.left();&lt;br /&gt;
    //int top = updateRect.top();&lt;br /&gt;
    //int bottom = updateRect.bottom();&lt;br /&gt;
    int row = firstItem.row();&lt;br /&gt;
    QModelIndex index = model()-&amp;gt;index(row, 0, QModelIndex());&lt;br /&gt;
    int value = model()-&amp;gt;data(index, Qt::DisplayRole).toInt();&lt;br /&gt;
    int midPoint = viewport()-&amp;gt;height()/2;&lt;br /&gt;
    int y2 = midPoint - int(value * midPoint/255.0);&lt;br /&gt;
    while (row &amp;lt;= lastItem.row()) {&lt;br /&gt;
        QModelIndex index = model()-&amp;gt;index(row, 0, QModelIndex());&lt;br /&gt;
        int value = model()-&amp;gt;data(index, Qt::DisplayRole).toInt();&lt;br /&gt;
        int y1 = y2;&lt;br /&gt;
        y2 = midPoint - int(value * midPoint/255.0);&lt;br /&gt;
        painter.drawLine(x-1, y1, x, y2);&lt;br /&gt;
        ++row; ++x;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
void LinearView::resizeEvent(QResizeEvent * /* event */)&lt;br /&gt;
{&lt;br /&gt;
    updateGeometries();&lt;br /&gt;
}&lt;br /&gt;
void LinearView::updateGeometries()&lt;br /&gt;
{&lt;br /&gt;
    if (viewport()-&amp;gt;width() &amp;lt; rows()) {&lt;br /&gt;
        horizontalScrollBar()-&amp;gt;setPageStep(viewport()-&amp;gt;width());&lt;br /&gt;
        horizontalScrollBar()-&amp;gt;setRange(0, rows() - viewport()-&amp;gt;width() - 1);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
QSize LinearView::sizeHint() const&lt;br /&gt;
{&lt;br /&gt;
    return QSize(rows(), 200);&lt;br /&gt;
}&lt;br /&gt;
int LinearView::rows(const QModelIndex &amp;amp;index) const&lt;br /&gt;
{&lt;br /&gt;
    return model()-&amp;gt;rowCount(model()-&amp;gt;parent(index));&lt;br /&gt;
}&lt;br /&gt;
bool LinearView::isIndexHidden(const QModelIndex &amp;amp;index) const&lt;br /&gt;
{&lt;br /&gt;
    return false;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#ifndef MODEL_H&lt;br /&gt;
#define MODEL_H&lt;br /&gt;
#include &amp;lt;QAbstractListModel&amp;gt;&lt;br /&gt;
#include &amp;lt;QObject&amp;gt;&lt;br /&gt;
#include &amp;lt;qvector.h&amp;gt;&lt;br /&gt;
class LinearModel : public QAbstractListModel&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    LinearModel(QObject *parent = 0)&lt;br /&gt;
        : QAbstractListModel(parent) {}&lt;br /&gt;
    int rowCount(const QModelIndex &amp;amp;parent = QModelIndex()) const;&lt;br /&gt;
    QModelIndex index(int row, int column = 0, const QModelIndex &amp;amp;parent = QModelIndex()) const;&lt;br /&gt;
    QVariant data(const QModelIndex &amp;amp;index, int role) const;&lt;br /&gt;
    Qt::ItemFlags flags(const QModelIndex &amp;amp;index) const;&lt;br /&gt;
    bool setData(const QModelIndex &amp;amp;index, const QVariant &amp;amp;value,&lt;br /&gt;
                 int role = Qt::EditRole);&lt;br /&gt;
    bool insertRows(int position, int rows, const QModelIndex &amp;amp;index = QModelIndex());&lt;br /&gt;
    bool removeRows(int position, int rows, const QModelIndex &amp;amp;index = QModelIndex());&lt;br /&gt;
private:&lt;br /&gt;
    QVector&amp;lt;int&amp;gt; values;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
  model.cpp&lt;br /&gt;
  A simple model that uses a QVector as its data source.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
/*!&lt;br /&gt;
    Returns the number of items in the string list as the number of rows&lt;br /&gt;
    in the model.&lt;br /&gt;
*/&lt;br /&gt;
int LinearModel::rowCount(const QModelIndex &amp;amp;parent) const&lt;br /&gt;
{&lt;br /&gt;
    Q_USING(parent);&lt;br /&gt;
    return values.count();&lt;br /&gt;
}&lt;br /&gt;
/*&lt;br /&gt;
    Returns an appropriate value for the requested data.&lt;br /&gt;
    If the view requests an invalid index, an invalid variant is returned.&lt;br /&gt;
    If a header is requested then we just return the column or row number,&lt;br /&gt;
    depending on the orientation of the header.&lt;br /&gt;
    Any valid index that corresponds to a string in the list causes that&lt;br /&gt;
    string to be returned.&lt;br /&gt;
*/&lt;br /&gt;
/*!&lt;br /&gt;
    Returns a model index for other component to use when referencing the&lt;br /&gt;
    item specified by the given row, column, and type. The parent index&lt;br /&gt;
    is ignored.&lt;br /&gt;
*/&lt;br /&gt;
QModelIndex LinearModel::index(int row, int column, const QModelIndex &amp;amp;parent) const&lt;br /&gt;
{&lt;br /&gt;
    if (parent == QModelIndex() &amp;amp;&amp;amp; row &amp;gt;= 0 &amp;amp;&amp;amp; row &amp;lt; rowCount()&lt;br /&gt;
        &amp;amp;&amp;amp; column == 0)&lt;br /&gt;
        return createIndex(row, column, 0);&lt;br /&gt;
    else&lt;br /&gt;
        return QModelIndex();&lt;br /&gt;
}&lt;br /&gt;
QVariant LinearModel::data(const QModelIndex &amp;amp;index, int role) const&lt;br /&gt;
{&lt;br /&gt;
    Q_UNUSED(role);&lt;br /&gt;
    if (!index.isValid())&lt;br /&gt;
        return QVariant();&lt;br /&gt;
    return values.at(index.row());&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Returns Qt::ItemIsEditable so that all items in the vector can be edited.&lt;br /&gt;
*/&lt;br /&gt;
Qt::ItemFlags LinearModel::flags(const QModelIndex &amp;amp;index) const&lt;br /&gt;
{&lt;br /&gt;
    // all items in the model are editable&lt;br /&gt;
    return QAbstractListModel::flags(index) | Qt::ItemIsEditable;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Changes an item in the string list, but only if the following conditions&lt;br /&gt;
    are met:&lt;br /&gt;
    * The index supplied is valid.&lt;br /&gt;
    * The index corresponds to an item to be shown in a view.&lt;br /&gt;
    * The role associated with editing text is specified.&lt;br /&gt;
    The dataChanged() signal is emitted if the item is changed.&lt;br /&gt;
*/&lt;br /&gt;
bool LinearModel::setData(const QModelIndex &amp;amp;index,&lt;br /&gt;
                          const QVariant &amp;amp;value, int role)&lt;br /&gt;
{&lt;br /&gt;
    if (!index.isValid() || role != Qt::EditRole)&lt;br /&gt;
        return false;&lt;br /&gt;
    values.replace(index.row(), value.toInt());&lt;br /&gt;
    emit dataChanged(index, index);&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Inserts a number of rows into the model at the specified position.&lt;br /&gt;
*/&lt;br /&gt;
bool LinearModel::insertRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    beginInsertRows(parent, position, position + rows - 1);&lt;br /&gt;
    values.insert(position, rows, 0);&lt;br /&gt;
    endInsertRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
/*!&lt;br /&gt;
    Removes a number of rows from the model at the specified position.&lt;br /&gt;
*/&lt;br /&gt;
bool LinearModel::removeRows(int position, int rows, const QModelIndex &amp;amp;parent)&lt;br /&gt;
{&lt;br /&gt;
    beginRemoveRows(QModelIndex(), position, position+rows-1);&lt;br /&gt;
    values.remove(position, rows);&lt;br /&gt;
    endRemoveRows();&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#ifndef WINDOW_H&lt;br /&gt;
#define WINDOW_H&lt;br /&gt;
#include &amp;lt;QMainWindow&amp;gt;&lt;br /&gt;
#include &amp;lt;QString&amp;gt;&lt;br /&gt;
#include &amp;lt;QWidget&amp;gt;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
#include &amp;quot;view.h&amp;quot;&lt;br /&gt;
class MainWindow : public QMainWindow&lt;br /&gt;
{&lt;br /&gt;
    Q_OBJECT&lt;br /&gt;
public:&lt;br /&gt;
    MainWindow::MainWindow(QWidget *parent = 0);&lt;br /&gt;
public slots:&lt;br /&gt;
    void selectOpenFile();&lt;br /&gt;
private:&lt;br /&gt;
    void setupModelView();&lt;br /&gt;
    void openFile(const QString &amp;amp;fileName);&lt;br /&gt;
    LinearModel *model;&lt;br /&gt;
    LinearView *view;&lt;br /&gt;
};&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QAction&amp;gt;&lt;br /&gt;
#include &amp;lt;QDataStream&amp;gt;&lt;br /&gt;
#include &amp;lt;QMenu&amp;gt;&lt;br /&gt;
#include &amp;lt;QMenuBar&amp;gt;&lt;br /&gt;
#include &amp;lt;QFile&amp;gt;&lt;br /&gt;
#include &amp;lt;QFileDialog&amp;gt;&lt;br /&gt;
#include &amp;lt;QListView&amp;gt;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
MainWindow::MainWindow(QWidget *parent)&lt;br /&gt;
    : QMainWindow(parent)&lt;br /&gt;
{&lt;br /&gt;
    setWindowTitle(&amp;quot;Model/View example&amp;quot;);&lt;br /&gt;
    setupModelView();&lt;br /&gt;
    QAction *openAction = new QAction(tr(&amp;quot;&amp;amp;Open&amp;quot;), this);&lt;br /&gt;
    QAction *quitAction = new QAction(tr(&amp;quot;E&amp;amp;xit&amp;quot;), this);&lt;br /&gt;
    QMenu *fileMenu = new QMenu(tr(&amp;quot;&amp;amp;File&amp;quot;), this);&lt;br /&gt;
    fileMenu-&amp;gt;addAction(openAction);&lt;br /&gt;
    fileMenu-&amp;gt;addAction(quitAction);&lt;br /&gt;
    menuBar()-&amp;gt;addMenu(fileMenu);&lt;br /&gt;
    connect(openAction, SIGNAL(triggered()), this, SLOT(selectOpenFile()));&lt;br /&gt;
    connect(quitAction, SIGNAL(triggered()), this, SLOT(close()));&lt;br /&gt;
    setCentralWidget(view);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::setupModelView()&lt;br /&gt;
{&lt;br /&gt;
    model = new LinearModel(this);&lt;br /&gt;
    view = new LinearView(this);&lt;br /&gt;
    view-&amp;gt;setModel(model);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::selectOpenFile()&lt;br /&gt;
{&lt;br /&gt;
    QString fileName = QFileDialog::getOpenFileName(this,&lt;br /&gt;
        tr(&amp;quot;Select a file to open&amp;quot;), &amp;quot;&amp;quot;, tr(&amp;quot;Sound files (*.wav)&amp;quot;));&lt;br /&gt;
    &lt;br /&gt;
    if (!fileName.isEmpty())&lt;br /&gt;
        openFile(fileName);&lt;br /&gt;
}&lt;br /&gt;
void MainWindow::openFile(const QString &amp;amp;fileName)&lt;br /&gt;
{&lt;br /&gt;
    QFile file(fileName);&lt;br /&gt;
    int length = file.size();&lt;br /&gt;
    if (file.open(QFile::ReadOnly)) {&lt;br /&gt;
        model-&amp;gt;removeRows(0, model-&amp;gt;rowCount());&lt;br /&gt;
        int rows = (length - 0x2c)/2;&lt;br /&gt;
        model-&amp;gt;insertRows(0, rows);&lt;br /&gt;
        // Perform some dodgy tricks to extract the data from the file.&lt;br /&gt;
        QDataStream stream(&amp;amp;file);&lt;br /&gt;
        stream.setByteOrder(QDataStream::LittleEndian);&lt;br /&gt;
        Q_INT16 left;&lt;br /&gt;
        Q_INT16 right;&lt;br /&gt;
        for (int row = 0; row &amp;lt; rows; ++row) {&lt;br /&gt;
            QModelIndex index = model-&amp;gt;index(row);&lt;br /&gt;
            stream &amp;gt;&amp;gt; left &amp;gt;&amp;gt; right;&lt;br /&gt;
            model-&amp;gt;setData(index, int(left / 256));&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
/*&lt;br /&gt;
    main.cpp&lt;br /&gt;
    An example of a main window application that used a subclassed model&lt;br /&gt;
    and view to display data from sound files.&lt;br /&gt;
*/&lt;br /&gt;
#include &amp;lt;QApplication&amp;gt;&lt;br /&gt;
#include &amp;quot;model.h&amp;quot;&lt;br /&gt;
#include &amp;quot;view.h&amp;quot;&lt;br /&gt;
#include &amp;quot;window.h&amp;quot;&lt;br /&gt;
/*!&lt;br /&gt;
    The main function for the linear model example. This creates and&lt;br /&gt;
    populates a model with long integers then displays the contents of the&lt;br /&gt;
    model using a QListView widget.&lt;br /&gt;
*/&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    MainWindow *window = new MainWindow;&lt;br /&gt;
    window-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>