summaryrefslogtreecommitdiffstats
path: root/tools/designer/src/lib/uilib/resourcebuilder.cpp
blob: bedac3b57d3c581acaa50a8323b9384798a5b819 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Designer of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/

#include "resourcebuilder_p.h"
#include "ui4_p.h"
#include <QtCore/QVariant>
#include <QtCore/QFileInfo>
#include <QtCore/QDir>
#include <QtGui/QPixmap>
#include <QtGui/QIcon>

QT_BEGIN_NAMESPACE

#ifdef QFORMINTERNAL_NAMESPACE
namespace QFormInternal {
#endif

QResourceBuilder::QResourceBuilder()
{

}

QResourceBuilder::~QResourceBuilder()
{

}

int QResourceBuilder::iconStateFlags(const DomResourceIcon *dpi)
{
    int rc = 0;
    if (dpi->hasElementNormalOff())
        rc |= NormalOff;
    if (dpi->hasElementNormalOn())
        rc |= NormalOn;
    if (dpi->hasElementDisabledOff())
        rc |= DisabledOff;
    if (dpi->hasElementDisabledOn())
        rc |= DisabledOn;
    if (dpi->hasElementActiveOff())
        rc |= ActiveOff;
    if (dpi->hasElementActiveOn())
        rc |= ActiveOn;
    if (dpi->hasElementSelectedOff())
        rc |= SelectedOff;
    if (dpi->hasElementSelectedOn())
        rc |= SelectedOn;
    return rc;
}

QVariant QResourceBuilder::loadResource(const QDir &workingDirectory, const DomProperty *property) const
{
    switch (property->kind()) {
        case DomProperty::Pixmap: {
            const DomResourcePixmap *dpx = property->elementPixmap();
            QPixmap pixmap(QFileInfo(workingDirectory, dpx->text()).absoluteFilePath());
            return qVariantFromValue(pixmap);
        }
        case DomProperty::IconSet: {
            const DomResourceIcon *dpi = property->elementIconSet();
            if (const int flags = iconStateFlags(dpi)) { // new, post 4.4 format
                QIcon icon;
                if (flags & NormalOff)
                    icon.addFile(QFileInfo(workingDirectory, dpi->elementNormalOff()->text()).absoluteFilePath(), QSize(), QIcon::Normal, QIcon::Off);
                if (flags & NormalOn)
                    icon.addFile(QFileInfo(workingDirectory, dpi->elementNormalOn()->text()).absoluteFilePath(), QSize(), QIcon::Normal, QIcon::On);
                if (flags & DisabledOff)
                    icon.addFile(QFileInfo(workingDirectory, dpi->elementDisabledOff()->text()).absoluteFilePath(), QSize(), QIcon::Disabled, QIcon::Off);
                if (flags & DisabledOn)
                    icon.addFile(QFileInfo(workingDirectory, dpi->elementDisabledOn()->text()).absoluteFilePath(), QSize(), QIcon::Disabled, QIcon::On);
                if (flags & ActiveOff)
                    icon.addFile(QFileInfo(workingDirectory, dpi->elementActiveOff()->text()).absoluteFilePath(), QSize(), QIcon::Active, QIcon::Off);
                if (flags & ActiveOn)
                    icon.addFile(QFileInfo(workingDirectory, dpi->elementActiveOn()->text()).absoluteFilePath(), QSize(), QIcon::Active, QIcon::On);
                if (flags & SelectedOff)
                    icon.addFile(QFileInfo(workingDirectory, dpi->elementSelectedOff()->text()).absoluteFilePath(), QSize(), QIcon::Selected, QIcon::Off);
                if (flags & SelectedOn)
                    icon.addFile(QFileInfo(workingDirectory, dpi->elementSelectedOn()->text()).absoluteFilePath(), QSize(), QIcon::Selected, QIcon::On);
                return qVariantFromValue(icon);
            } else { // 4.3 legacy
                const QIcon icon(QFileInfo(workingDirectory, dpi->text()).absoluteFilePath());
                return qVariantFromValue(icon);
            }
        }
            break;
        default:
            break;
    }
    return QVariant();
}

QVariant QResourceBuilder::toNativeValue(const QVariant &value) const
{
    return value;
}

DomProperty *QResourceBuilder::saveResource(const QDir &workingDirectory, const QVariant &value) const
{
    Q_UNUSED(workingDirectory)
    Q_UNUSED(value)
    return 0;
}

bool QResourceBuilder::isResourceProperty(const DomProperty *p) const
{
    switch (p->kind()) {
        case DomProperty::Pixmap:
        case DomProperty::IconSet:
            return true;
        default:
            break;
    }
    return false;
}

bool QResourceBuilder::isResourceType(const QVariant &value) const
{
    switch (value.type()) {
        case QVariant::Pixmap:
        case QVariant::Icon:
            return true;
        default:
            break;
    }
    return false;
}

#ifdef QFORMINTERNAL_NAMESPACE
} // namespace QFormInternal
#endif

QT_END_NAMESPACE
nts - \previouspage Using Models and Views - \nextpage Creating New Models - - \title Model Classes + \section1 Model classes - \tableofcontents + Before examining how selections are handled, you may find it + useful to examine the concepts used in the model/view framework. - \section1 Basic Concepts + \section2 Basic concepts In the model/view architecture, the model provides a standard interface that views and delegates use to access data. In Qt, the standard @@ -401,11 +324,11 @@ Models also notify any attached views about changes to data through the signals and slots mechanism. - This chapter describes some basic concepts that are central to the way + This section describes some basic concepts that are central to the way item of data are accessed by other components via a model class. More - advanced concepts are discussed in later chapters. + advanced concepts are discussed in later sections. - \section2 Model Indexes + \section3 Model indexes To ensure that the representation of the data is kept separate from the way it is accessed, the concept of a \e{model index} is introduced. Each @@ -435,7 +358,7 @@ and the model index of a parent item. The following sections describe and explain these properties in detail. - \section2 Rows and Columns + \section3 Rows and columns In its most basic form, a model can be accessed as a simple table in which items are located by their row and column numbers. \e{This does not mean @@ -468,7 +391,7 @@ section. \endtable - \section2 Parents of Items + \section3 Parents of items The table-like interface to item data provided by models is ideal when using data in a table or list view; the row and column number system maps @@ -501,7 +424,7 @@ \snippet doc/src/snippets/code/doc_src_model-view-programming.qdoc 5 \endtable - \section2 Item Roles + \section3 Item roles Items in a model can perform various \e roles for other components, allowing different kinds of data to be supplied for different situations. @@ -534,7 +457,7 @@ interpret or ignore this information as required. It is also possible to define additional roles for application-specific purposes. - \section2 Summary of Concepts + \section3 Summary \list \o Model indexes give views and delegates information about the location @@ -546,17 +469,16 @@ components, such as views and delegates. \o If a valid model index is specified for the parent item when an index is requested using \l{QAbstractItemModel::index()}{index()}, the index - returned will refer to an item beneath that parent item in the - model. + returned refers to an item beneath that parent item in the model. The index obtained refers to a child of that item. \o If an invalid model index is specified for the parent item when an index is requested using \l{QAbstractItemModel::index()}{index()}, the index - returned will refer to a top-level item in the model. + returned refers to a top-level item in the model. \o The \l{Qt::ItemDataRole}{role} distinguishes between the different kinds of data associated with an item. \endlist - \section2 Using Model Indexes + \section2 Using model indexes To demonstrate how data can be retrieved from a model, using model indexes, we set up a QFileSystemModel without a view and display the @@ -610,26 +532,16 @@ to the model. \endlist + \section2 Further reading - \section1 Further Reading - - New models can be created by implementing the standard interface provided - by QAbstractItemModel. In the \l{Creating New Models} chapter, we will - demonstrate this by creating a convenient ready-to-use model for holding - lists of strings. -*/ - -/*! - \page model-view-view.html - \contentspage model-view-programming.html Contents - \previouspage Creating New Models - \nextpage Handling Selections in Item Views + New models can be created by implementing the standard interface + provided by QAbstractItemModel. In the \l{Creating New Models} + section, we demonstrate this by creating a convenient ready-to-use + model for holding lists of strings. - \title View Classes + \section1 View classes - \tableofcontents - - \section1 Concepts + \section2 Concepts In the model/view architecture, the view obtains items of data from the model and presents them to the user. The way that the data is @@ -668,7 +580,7 @@ subclassed from the QHeaderView class to provide more specialized labels for views. - \section1 Using an Existing View + \section2 Using an existing view Qt provides three ready-to-use view classes that present data from models in ways that are familiar to most users. @@ -686,7 +598,7 @@ facilities, and can be customized to suit the needs of more specialized user interfaces. - \section2 Using a Model + \section3 Using a model We take the string list model that \l{Creating New Models}{we created as an example model}, set it up with some data, and construct a view to @@ -697,8 +609,8 @@ Note that the \c StringListModel is declared as a \l QAbstractItemModel. This allows us to use the abstract interface to the model, and - ensures that the code will still work even if we replace the string list - model with a different model in the future. + ensures that the code still works, even if we replace the string list + model with a different model. The list view provided by \l QListView is sufficient for presenting the items in the string list model. We construct the view, and set up @@ -721,7 +633,7 @@ list model. Since the model is editable, the view automatically allows each item in the list to be edited using the default delegate. - \section2 Using Multiple Views onto the Same Model + \section3 Using multiple views of a model Providing multiple views onto the same model is simply a matter of setting the same model for each view. In the following code we create @@ -745,7 +657,7 @@ selection model. This can be useful in certain situations but, for many applications, a shared selection model is desirable. - \section1 Handling Selections of Items + \section2 Handling selections of items The mechanism for handling selections of items within views is provided by the \l QItemSelectionModel class. All of the standard views construct @@ -758,13 +670,12 @@ when we want to provide multiple consistent views onto the same model data. - Generally, unless you are subclassing a model or view, you will not - need to manipulate the contents of selections directly. However, the - interface to the selection model can be accessed, if required, and - this is explored in the chapter on - \l{Handling Selections in Item Views}. + Generally, unless you are subclassing a model or view, you don't + need to manipulate the contents of selections directly. However, + the interface to the selection model can be accessed, if required, + and this is explored in \l{Handling Selections in Item Views}. - \section2 Sharing Selections Between Views + \section3 Sharing selections among views Although it is convenient that the view classes provide their own selection models by default, when we use more than one view onto the @@ -788,19 +699,9 @@ each view; for example, a contiguous selection in a table view can be represented as a fragmented set of highlighted items in a tree view. -*/ - -/*! - \page model-view-delegate.html - \contentspage model-view-programming.html Contents - \previouspage Handling Selections in Item Views - \nextpage Item View Convenience Classes - - \title Delegate Classes - - \tableofcontents + \section1 Delegate classes - \section1 Concepts + \section2 Concepts Unlike the Model-View-Controller pattern, the model/view design does not include a completely separate component for managing interaction with @@ -821,13 +722,13 @@ Editors for delegates can be implemented either by using widgets to manage the editing process or by handling events directly. - The first approach is covered later in this chapter, and it is also + The first approach is covered later in this section, and it is also shown in the \l{Spin Box Delegate Example}{Spin Box Delegate} example. The \l{Pixelator Example}{Pixelator} example shows how to create a custom delegate that performs specialized rendering for a table view. - \section1 Using an Existing Delegate + \section2 Using an existing delegate The standard views provided with Qt use instances of \l QItemDelegate to provide editing facilities. This default implementation of the @@ -845,15 +746,15 @@ necessary to use this function when setting the delegate for a custom view. - \section1 A Simple Delegate + \section2 A simple delegate - The delegate implemented here uses a \l QSpinBox to provide editing - facilities, and is mainly intended for use with models that display - integers. Although we set up a custom integer-based table model for - this purpose, we could easily have used \l QStandardItemModel instead - since the custom delegate will control data entry. We construct a - table view to display the contents of the model, and this will use - the custom delegate for editing. + The delegate implemented here uses a \l QSpinBox to provide + editing facilities, and is mainly intended for use with models + that display integers. Although we set up a custom integer-based + table model for this purpose, we could easily have used \l + QStandardItemModel instead, since the custom delegate controls + data entry. We construct a table view to display the contents of + the model, and this will use the custom delegate for editing. \img spinboxdelegate-example.png @@ -866,7 +767,7 @@ Note that no editor widgets are set up when the delegate is constructed. We only construct an editor widget when it is needed. - \section2 Providing an Editor + \section3 Providing an editor In this example, when the table view needs to provide an editor, it asks the delegate to provide an editor widget that is appropriate @@ -906,7 +807,7 @@ the model, in which case we would need to cast the widget to the appropriate type before accessing its member functions. - \section2 Submitting Data to the Model + \section3 Submitting data to the model When the user has finished editing the value in the spin box, the view asks the delegate to store the edited value in the model by calling the @@ -935,7 +836,7 @@ delegate with different kinds of models because \l{QVariant} provides sensible default values for unexpected data. - \section2 Updating the Editor's Geometry + \section3 Updating the editor's geometry It is the responsibility of the delegate to manage the editor's geometry. The geometry must be set when the editor is created, and @@ -951,7 +852,7 @@ position the editor in relation to the other elements in the item. \target EditingHints - \section2 Editing Hints + \section3 Editing hints After editing, delegates should provide hints to the other components about the result of the editing process, and provide hints that will @@ -982,19 +883,10 @@ Delegates do not have to emit these hints, but those that do not will be less integrated into applications, and will be less usable than those that emit hints to support common editing actions. -*/ - -/*! - \page model-view-selection.html - \contentspage model-view-programming.html Contents - \previouspage View Classes - \nextpage Delegate Classes - \title Handling Selections in Item Views + \section1 Handling selections in item views - \tableofcontents - - \section1 Concepts + \section2 Concepts The selection model used in the item view classes offers many improvements over the selection model used in Qt 3. It provides a more general @@ -1022,8 +914,7 @@ after its application through the use of certain types of selection commands. These are discussed later in this section. - - \section2 Current Item and Selected Items + \section3 Current item & selected items In a view, there is always a current item and a selected item - two independent states. An item can be the current item and selected at the @@ -1068,8 +959,7 @@ be informed of changes to the selection model via the signals and slots mechanism. - - \section1 Using a Selection Model + \section2 Using a selection model The standard view classes provide default selection models that can be used in most applications. A selection model belonging to one view @@ -1088,8 +978,7 @@ each having a different effect on the selections already present in the selection model. - - \section2 Selecting Items + \section3 Selecting items To demonstrate some of the principal features of selections, we construct an instance of a custom table model with 32 items in total, and open a @@ -1122,12 +1011,12 @@ The selection of items can be modified using various operations that are defined by the selection flags. The selection that results from - these operations may have a complex structure, but will be represented + these operations may have a complex structure, but it is represented efficiently by the selection model. The use of different selection flags to manipulate the selected items is described when we examine how to update a selection. - \section2 Reading the Selection State + \section3 Reading the selection state The model indexes stored in the selection model can be read using the \l{QItemSelectionModel::selectedIndexes()}{selectedIndexes()} @@ -1176,7 +1065,7 @@ Monitoring selections made by the user is straightforward with these signals, but we can also update the selection model directly. - \section2 Updating a Selection + \section3 Updating a selection Selection commands are provided by a combination of selection flags, defined by \l{QItemSelectionModel::SelectionFlag}. @@ -1215,7 +1104,7 @@ with a command that is a combination of \l{QItemSelectionModel::SelectionFlag}{Select} and \l{QItemSelectionModel::SelectionFlag}{Rows}, the - entire row containing the item referred to will be selected. + entire row containing the item referred to is selected. The following code demonstrates the use of the \l{QItemSelectionModel::SelectionFlag}{Rows} and \l{QItemSelectionModel::SelectionFlag}{Columns} flags: @@ -1248,7 +1137,7 @@ has the effect of resetting the selection model's collection of model indexes. - \section2 Selecting All Items in a Model + \section3 Selecting all items in a model To select all items in a model, it is necessary to create a selection for each level of the model that covers all items in that @@ -1271,19 +1160,8 @@ \l{QAbstractItemModel::hasChildren()}{hasChildren()} function is used to determine whether any given item is the parent of another level of items. -*/ - -/*! - \page model-view-creating-models.html - \contentspage model-view-programming.html Contents - \previouspage Model Classes - \nextpage View Classes - - \title Creating New Models - \tableofcontents - - \section1 Introduction + \section1 Creating new models The separation of functionality between the model/view components allows models to be created that can take advantage of existing views. This @@ -1301,9 +1179,9 @@ for interfaces to simpler non-hierarchical data structures, and are easier to use as a starting point for simple list and table models. - In this chapter, we create a simple read-only model to explore + In this section, we create a simple read-only model to explore the basic principles of the model/view architecture. Later in this - chapter, we will adapt this simple model so that items can be modified + section, we adapt this simple model so that items can be modified by the user. For an example of a more complex model, see the @@ -1312,21 +1190,21 @@ The requirements of QAbstractItemModel subclasses is described in more detail in the \l{Model Subclassing Reference} document. - \section1 Designing a Model + \section2 Designing a model - When creating a new model for an existing data structure, it is important - to consider which type of model should be used to provide an interface - onto the data. If the data structure can be represented as a - list or table of items, you can subclass QAbstractListModel or - QAbstractTableModel since these classes provide suitable default - implementations for many functions. + When creating a new model for an existing data structure, it is + important to consider which type of model should be used to + provide an interface onto the data. If the data structure can be + represented as a list or table of items, you can subclass + QAbstractListModel or QAbstractTableModel since these classes + provide suitable default implementations for many functions. - However, if the underlying data structure can only be represented by a - hierarchical tree structure, it is necessary to subclass + However, if the underlying data structure can only be represented + by a hierarchical tree structure, it is necessary to subclass QAbstractItemModel. This approach is taken in the \l{itemviews/simpletreemodel}{Simple Tree Model} example. - In this chapter, we will implement a simple model based on a list of + In this section, we implement a simple model based on a list of strings, so the QAbstractListModel provides an ideal base class on which to build. @@ -1338,7 +1216,7 @@ interact with it using the standard API. The model described below provides a custom constructor for just this purpose. - \section1 A Read-Only Example Model + \section2 A read-only example model The model implemented here is a simple, non-hierarchical, read-only data model based on the standard QStringListModel class. It has a \l QStringList @@ -1355,7 +1233,6 @@ functions as there are default implementations for most of the interface. The class declaration is as follows: - \snippet doc/src/snippets/stringlistmodel/model.h 0 \snippet doc/src/snippets/stringlistmodel/model.h 1 \codeline @@ -1379,7 +1256,7 @@ The list of strings is stored internally in the \c stringList private member variable. - \section2 Dimensions of The Model + \section3 Dimensions of the model We want the number of rows in the model to be the same as the number of strings in the string list. We implement the @@ -1394,7 +1271,7 @@ reimplement the \l{QAbstractItemModel::columnCount()}{columnCount()} function. - \section2 Model Headers and Data + \section3 Model headers & data For items in the view, we want to return the strings in the string list. The \l{QAbstractItemModel::data()}{data()} function is responsible for @@ -1433,7 +1310,7 @@ \l{Qt::ItemDataRole}{ToolTipRole} that views can use to display information about items in a tooltip. - \section1 An Editable Model + \section2 An editable model The read-only model shows how simple choices could be presented to the user but, for many applications, an editable list model is much more @@ -1447,7 +1324,7 @@ \snippet doc/src/snippets/stringlistmodel/model.h 2 \snippet doc/src/snippets/stringlistmodel/model.h 3 - \section2 Making the Model Editable + \section3 Making the model editable A delegate checks whether an item is editable before creating an editor. The model must let the delegate know that its items are @@ -1473,7 +1350,7 @@ \l{Qt::ItemDataRole}{EditRole} since this is the role used by the standard item delegate. For boolean values, however, you can use Qt::CheckStateRole and set the Qt::ItemIsUserCheckable flag; a - checkbox will then be used for editing the value. The underlying + checkbox is then used for editing the value. The underlying data in this model is the same for all roles, so this detail just makes it easier to integrate the model with standard components. @@ -1487,7 +1364,7 @@ \snippet doc/src/snippets/stringlistmodel/model.cpp 1 - \section2 Inserting and Removing Rows + \section3 Inserting & removing rows It is possible to change the number of rows and columns in a model. In the string list model it only makes sense to change the number of rows, so we @@ -1536,39 +1413,29 @@ operation and let other components know that the dimensions of the model have changed. - \section1 Next Steps + \section2 Next steps We can display the data provided by this model, or any other model, using the \l QListView class to present the model's items in the form of a vertical list. For the string list model, this view also provides a default editor so that the items can be manipulated. We examine the possibilities made available by - the standard view classes in the chapter on \l{View Classes}. + the standard view classes in \l{View Classes}. The \l{Model Subclassing Reference} document discusses the requirements of QAbstractItemModel subclasses in more detail, and provides a guide to the virtual functions that must be implemented to enable various features in different types of models. -*/ - -/*! - \page model-view-convenience.html - \contentspage model-view-programming.html Contents - \previouspage Delegate Classes - \nextpage Using Drag and Drop with Item Views - - \title Item View Convenience Classes - \tableofcontents + \section1 Item view convenience classes - \section1 Overview - - Alongside the model/view classes, Qt 4 also includes standard widgets to - provide classic item-based container widgets. These behave in a similar - way to the item view classes in Qt 3, but have been rewritten to use the - underlying model/view framework for performance and maintainability. The - old item view classes are still available in the compatibility library - (see the \l{porting4.html}{Porting Guide} for more information). + Qt 4 also introduced some standard widgets to provide classic + item-based container widgets. These behave in a similar way to the + item view classes in Qt 3, but have been rewritten to use the + underlying model/view framework for performance and + maintainability. The old item view classes are still available in + the compatibility library (see the \l{porting4.html}{Porting + Guide} for more information). The item-based widgets have been given names which reflect their uses: \c QListWidget provides a list of items, \c QTreeWidget displays a @@ -1577,7 +1444,7 @@ class which implements common behavior for item selection and header management. - \section1 List Widgets + \section2 List widgets Single level lists of items are typically displayed using a \c QListWidget and a number of \c{QListWidgetItem}s. A list widget is constructed in the @@ -1612,8 +1479,7 @@ \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 4 \snippet doc/src/snippets/qlistwidget-using/mainwindow.cpp 5 - - \section1 Tree Widgets + \section2 Tree widgets Trees or hierarchical lists of items are provided by the \c QTreeWidget and \c QTreeWidgetItem classes. Each item in the tree widget can have @@ -1668,8 +1534,7 @@ \snippet doc/src/snippets/qtreewidget-using/mainwindow.cpp 8 \snippet doc/src/snippets/qtreewidget-using/mainwindow.cpp 9 - - \section1 Table Widgets + \section2 Table widgets Tables of items similar to those found in spreadsheet applications are constructed with the \c QTableWidget and \c QTableWidgetItem. These @@ -1693,7 +1558,7 @@ Note that the rows and columns in the table begin at zero. - \section1 Common Features + \section2 Common features There are a number of item-based features common to each of the convenience classes that are available through the same interfaces @@ -1702,7 +1567,7 @@ Look at the list of \l{Model/View Classes} for each of the widgets for more details about the use of each function used. - \section2 Hidden Items + \section3 Hidden items It is sometimes useful to be able to hide items in an item view widget rather than remove them. Items for all of the above widgets can be @@ -1713,7 +1578,7 @@ Since this operation is item-based, the same function is available for all three convenience classes. - \section2 Selections + \section3 Selections The way items are selected is controlled by the widget's selection mode (\l{QAbstractItemView::SelectionMode}). @@ -1764,7 +1629,7 @@ current item may not lie within the selection, depending on the way the user formed the selection. - \section2 Searching + \section3 Searching It is often useful to be able to find items within an item view widget, either as a developer or as a service to present to users. All three @@ -1782,19 +1647,8 @@ The above code causes items in a tree widget to be selected if they contain the text given in the search string. This pattern can also be used in the list and table widgets. -*/ - -/*! - \page model-view-dnd.html - \contentspage model-view-programming.html Contents - \previouspage Item View Convenience Classes - \nextpage Proxy Models - \title Using Drag and Drop with Item Views - - \tableofcontents - - \section1 Overview + \section1 Using drag & drop with item views Qt's drag and drop infrastructure is fully supported by the model/view framework. Items in lists, tables, and trees can be dragged within the views, and data can be @@ -1813,7 +1667,7 @@ See also the \l{Model Subclassing Reference} for more information about enabling drag and drop support in new models. - \section1 Using Convenience Views + \section2 Using convenience views Each of the types of item used with QListWidget, QTableWidget, and QTreeWidget is configured to use a different set of flags by default. For example, each @@ -1852,7 +1706,7 @@ \snippet doc/src/snippets/qlistwidget-dnd/mainwindow.cpp 1 - \section1 Using Model/View Classes + \section2 Using model/view classes Setting up a view for drag and drop follows the same pattern used with the convenience views. For example, a QListView can be set up in the same way as a @@ -1874,7 +1728,7 @@ of QAbstractItemModel::removeRows(), either directly or by inheriting the implementation from its base class. - \section2 Enabling Drag and Drop for Items + \section3 Enabling drag & drop for items Models indicate to views which items can be dragged, and which will accept drops, by reimplementing the QAbstractItemModel::flags() function to provide suitable @@ -1894,7 +1748,7 @@ obtain a default set of flags by calling its implementation of the flags() function. - \section2 Encoding Exported Data + \section3 Encoding exported data When items of data are exported from a model in a drag and drop operation, they are encoded into an appropriate format corresponding to one or more MIME types. @@ -1923,7 +1777,7 @@ and that stream operators must be implemented for them. See the QMetaObject class description for details. - \section2 Inserting Dropped Data into a Model + \section3 Inserting dropped data into a model The way that any given model handles dropped data depends on both its type (list, table, or tree) and the way its contents is likely to be presented to @@ -1988,7 +1842,7 @@ example shown here, the model only has one level, so this approach is not appropriate. - \section2 Decoding Imported Data + \section3 Decoding imported data Each implementation of \l{QAbstractItemModel::dropMimeData()}{dropMimeData()} must also decode the data and insert it into the model's underlying data structure. @@ -2007,19 +1861,8 @@ QAbstractItemModel::insertRows() and QAbstractItemModel::setData() functions. \sa {Item Views Puzzle Example} -*/ - -/*! - \page model-view-proxy-models.html - \contentspage model-view-programming.html Contents - \previouspage Using Drag and Drop with Item Views - \nextpage Model Subclassing Reference - \title Proxy Models - - \tableofcontents - - \section1 Overview + \section1 Proxy models In the model/view framework, items of data supplied by a single model can be shared by any number of views, and each of these can possibly represent the same information @@ -2042,7 +1885,7 @@ framework ensure that each view is updated appropriately no matter how many proxy models are placed between itself and the source model. - \section1 Using Proxy Models + \section2 Using proxy models Proxy models can be inserted between an existing model and any number of views. Qt is supplied with a standard proxy model, QSortFilterProxyModel, that is usually @@ -2061,7 +1904,7 @@ in applications. More specialized proxy models can be created by subclassing this classes and implementing the required comparison operations. - \section1 Customizing Proxy Models + \section2 Customizing proxy models Generally, the type of processing used in a proxy model involves mapping each item of data from its original location in the source model to either a different location in @@ -2074,7 +1917,7 @@ being supplied to views, and also allows the contents of a source model to be supplied to views as pre-sorted data. - \section2 Custom Filtering Models + \section3 Custom filtering models The QSortFilterProxyModel class provides a filtering model that is fairly versatile, and which can be used in a variety of common situations. For advanced users, @@ -2095,7 +1938,7 @@ return true to ensure that all items are passed through to views; reimplementations of these functions should return false to filter out individual rows and columns. - \section2 Custom Sorting Models + \section3 Custom sorting models QSortFilterProxyModel instances use Qt's built-in qStableSort() function to set up mappings between items in the source model and those in the proxy model, allowing a @@ -2103,18 +1946,8 @@ source model. To provide custom sorting behavior, reimplement the \l{QSortFilterProxyModel::lessThan()}{lessThan()} function to perform custom comparisons. -*/ - -/*! - \page model-view-model-subclassing.html - \contentspage model-view-programming.html Contents - \previouspage Proxy Models - - \title Model Subclassing Reference - \tableofcontents - - \section1 Introduction + \section1 Model subclassing reference Model subclasses need to provide implementations of many of the virtual functions defined in the QAbstractItemModel base class. The number of these functions that need @@ -2143,13 +1976,13 @@ For more information, see the \l {"Item View Classes" Chapter of C++ GUI Programming with Qt 4}. - \section1 Item Data Handling + \section2 Item data handling Models can provide varying levels of access to the data they provide: They can be simple read-only components, some models may support resizing operations, and others may allow items to be edited. - \section2 Read-Only Access + \section2 Read-Only access To provide read-only access to data provided by a model, the following functions \e{must} be implemented in the model's subclass: @@ -2185,7 +2018,7 @@ provide this function because it is already implemented in QAbstractListModel. \endtable - \section2 Editable Items + \section3 Editable items Editable models allow items of data to be modified, and may also provide functions to allow rows and columns to be inserted and removed. To enable @@ -2211,7 +2044,7 @@ signal to inform other components of the change. \endtable - \section2 Resizable Models + \section3 Resizable models All types of model can support the insertion and removal of rows. Table models and hierarchical models can also support the insertion and removal of columns. @@ -2271,7 +2104,7 @@ it is necessary to emit the \l{QAbstractItemModel::layoutChanged()}{layoutChanged()} signal to cause any attached views to be updated. - \section2 Lazy Population of Model Data + \section3 Lazy population of model data Lazy population of model data effectively allows requests for information about the model to be deferred until it is actually needed by views. @@ -2305,13 +2138,12 @@ children may be displayed incorrectly in some views until the user attempts to view the non-existent child items. - - \section1 Navigation and Model Index Creation + \section2 Navigation & model index creation Hierarchical models need to provide functions that views can call to navigate the tree-like structures they expose, and obtain model indexes for items. - \section2 Parents and Children + \section3 Parents & children Since the structure exposed to views is determined by the underlying data structure, it is up to each model subclass to create its own model indexes @@ -2335,7 +2167,7 @@ models to supply some unique identifier to this function to ensure that the model index can be re-associated with its corresponding item later on. - \section1 Drag and Drop Support and MIME Type Handling + \section2 Drag & drop support and MIME type handling The model/view classes support drag and drop operations, providing default behavior that is sufficient for many applications. However, it is also possible to customize @@ -2347,7 +2179,7 @@ The \l{#Convenience Views}{Convenience Views} section provides an overview of this behavior. - \section2 MIME Data + \section3 MIME data By default, the built-in models and views use an internal MIME type (\c{application/x-qabstractitemmodeldatalist}) to pass around information about @@ -2394,7 +2226,7 @@ the QMimeData::setImageData(), QMimeData::setColorData(), and QMimeData::setHtml() functions. - \section2 Accepting Dropped Data + \section3 Accepting dropped data When a drag and drop operation is performed over a view, the underlying model is queried to determine which types of operation it supports and the MIME types @@ -2466,7 +2298,7 @@ For more information about drag and drop with item views, refer to \l{Using Drag and Drop with Item Views}. - \section2 Convenience Views + \section3 Convenience views The convenience views (QListWidget, QTableWidget, and QTreeWidget) override the default drag and drop functionality to provide less flexible, but more @@ -2477,7 +2309,7 @@ into the model. For more information on drag and drop in convenience views, you can see \l{Using Drag and Drop with Item Views}. - \section1 Performance Optimization for Large Amounts of Data + \section2 Performance optimization for large amounts of data The \l{QAbstractItemModel::}{canFetchMore()} function checks if the parent has more data available and returns true or false accordingly. The @@ -2498,4 +2330,23 @@ \l{QAbstractItemModel::}{canFetchMore()} and \l{QAbstractItemModel::} {fetchMore()} must be reimplemented as their default implementation returns false and does nothing. + + \keyword Model/View Classes + \section1 The model/view classes + + These classes use the model/view design pattern in which the + underlying data (in the model) is kept separate from the way the + data is presented and manipulated by the user (in the view). + + \annotatedlist model-view + + \section1 Related examples + + \list + \o \l{itemviews/dirview}{Dir View} + \o \l{itemviews/spinboxdelegate}{Spin Box Delegate} + \o \l{itemviews/pixelator}{Pixelator} + \o \l{itemviews/simpletreemodel}{Simple Tree Model} + \o \l{itemviews/chart}{Chart} + \endlist */ diff --git a/doc/src/template/style/style.css b/doc/src/template/style/style.css index c155d9b..47fe2e0 100755 --- a/doc/src/template/style/style.css +++ b/doc/src/template/style/style.css @@ -39,7 +39,7 @@ h1, h2, h3, h4, h5, h6 { font-size: 100%; - font-weight: normal; +/* font-weight: normal; */ } q:before, q:after { @@ -949,6 +949,11 @@ margin-left: 15px; } + .wrap .content .toc .level3 + { + margin-left: 30px; + } + .content .toc li { font: normal 10px/1.2 Verdana; diff --git a/tools/qdoc3/doc.cpp b/tools/qdoc3/doc.cpp index 5716626..280f055 100644 --- a/tools/qdoc3/doc.cpp +++ b/tools/qdoc3/doc.cpp @@ -2746,18 +2746,6 @@ Doc::SectioningUnit Doc::granularity() const } } -#if notyet // ### -Doc::SectioningUnit Doc::sectioningUnit() const -{ - if (priv == 0 || priv->extra == 0) { - return DocPrivateExtra().sectioningUnit; - } - else { - return priv->extra->sectioningUnit; - } -} -#endif - const QSet &Doc::parameterNames() const { return priv == 0 ? *null_Set_QString() : priv->params; diff --git a/tools/qdoc3/htmlgenerator.cpp b/tools/qdoc3/htmlgenerator.cpp index 16df0c0..b103981 100644 --- a/tools/qdoc3/htmlgenerator.cpp +++ b/tools/qdoc3/htmlgenerator.cpp @@ -4060,10 +4060,13 @@ int HtmlGenerator::hOffset(const Node *node) case Node::Class: return 2; case Node::Fake: + return 1; +#if 0 if (node->doc().briefText().isEmpty()) return 1; else return 2; +#endif case Node::Enum: case Node::Typedef: case Node::Function: -- cgit v0.12 From 90abe364b7e9b0aa201a3e0ed0b043643519e21b Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 26 May 2010 13:09:49 +0200 Subject: Make test work with shadow builds again. Broken by 0cdf33e9acb00b8f3654e8268253a3fb7c5db92c, which assumes the binary and sources are in the same directory. The fix reverts the code back to how it was in 4.5 (where it still works with shadow builds). Reviewed-by: Denis Dzyubenko --- tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp index dac631b..1f65ae7 100644 --- a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp +++ b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp @@ -56,7 +56,7 @@ #elif defined(Q_OS_WINCE) #define LACKEYDIR SRCDIR #else -#define LACKEYDIR SRCDIR "../lackey" +#define LACKEYDIR "../lackey" #endif Q_DECLARE_METATYPE(QSharedMemory::SharedMemoryError) @@ -421,7 +421,7 @@ void tst_QSharedMemory::readOnly() QString program = LACKEYDIR "/lackey"; QStringList arguments; rememberKey("readonly_segfault"); - arguments << LACKEYDIR "/scripts/readonly_segfault.js"; + arguments << SRCDIR "../lackey/scripts/readonly_segfault.js"; // ### on windows disable the popup somehow QProcess p; @@ -734,7 +734,7 @@ void tst_QSharedMemory::simpleProcessProducerConsumer() rememberKey("market"); - QStringList arguments = QStringList() << LACKEYDIR "/scripts/producer.js"; + QStringList arguments = QStringList() << SRCDIR "../lackey/scripts/producer.js"; QProcess producer; producer.setProcessChannelMode(QProcess::ForwardedChannels); producer.start( LACKEYDIR "/lackey", arguments); @@ -744,7 +744,7 @@ void tst_QSharedMemory::simpleProcessProducerConsumer() QList consumers; unsigned int failedProcesses = 0; for (int i = 0; i < processes; ++i) { - QStringList arguments = QStringList() << LACKEYDIR "/scripts/consumer.js"; + QStringList arguments = QStringList() << SRCDIR "../lackey/scripts/consumer.js"; QProcess *p = new QProcess; p->setProcessChannelMode(QProcess::ForwardedChannels); #ifdef Q_OS_WINCE -- cgit v0.12 From 9b4ff3deb28b3d642dc4480207f2f23841cf26e9 Mon Sep 17 00:00:00 2001 From: Mirko Damiani Date: Mon, 8 Feb 2010 16:09:24 +0100 Subject: Added native key support to QSharedMemory API. Methods setNativeKey() and nativeKey() were added to QSharedMemory API. Shared memory's native key is returned by nativeKey() and it is set with either setKey() or setNativeKey(). setKey() leads to a native key that is platform independent while setNativeKey() directly sets the native key without any mangling. When using setNativeKey(), key() returns a null string and shared memory's system semaphore is not set. This means that is up to the user to define a such protection mechanism (i.e. lock() can't be used on native keys). QSharedMemory tests were updated. Merge-request: 1497 Reviewed-by: Benjamin Poulain Reviewed-by: Andreas Aardal Hanssen --- src/corelib/kernel/qsharedmemory.cpp | 120 +++++++++++++++------ src/corelib/kernel/qsharedmemory.h | 2 + src/corelib/kernel/qsharedmemory_p.h | 1 + src/corelib/kernel/qsharedmemory_symbian.cpp | 11 +- src/corelib/kernel/qsharedmemory_unix.cpp | 15 ++- src/corelib/kernel/qsharedmemory_win.cpp | 13 +-- .../auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp | 26 +++-- 7 files changed, 123 insertions(+), 65 deletions(-) diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp index fe93ebc..d5f4052 100644 --- a/src/corelib/kernel/qsharedmemory.cpp +++ b/src/corelib/kernel/qsharedmemory.cpp @@ -142,9 +142,12 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key, remain. Do not mix using QtSharedMemory and QSharedMemory. Port everything to QSharedMemory. - \warning QSharedMemory changes the key in a Qt-specific way. - It is therefore currently not possible to use the shared memory of - non-Qt applications with QSharedMemory. + \warning QSharedMemory changes the key in a Qt-specific way, unless otherwise + specified. Interoperation with non-Qt applications is achieved by first creating + a default shared memory with QSharedMemory() and then setting a native key with + setNativeKey(). When using native keys, shared memory is not protected against + multiple accesses on it (e.g. unable to lock()) and a user-defined mechanism + should be used to achieve a such protection. */ /*! @@ -153,8 +156,8 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key, Constructs a shared memory object with the given \a parent. The shared memory object's key is not set by the constructor, so the shared memory object does not have an underlying shared memory - segment attached. The key must be set with setKey() before create() - or attach() can be used. + segment attached. The key must be set with setKey() or setNativeKey() + before create() or attach() can be used. \sa setKey() */ @@ -191,24 +194,52 @@ QSharedMemory::~QSharedMemory() } /*! - Sets a new \a key for this shared memory object. If \a key and the - current key are the same, the function returns without doing - anything. If the shared memory object is attached to an underlying - shared memory segment, it will \l {detach()} {detach} from it before - setting the new key. This function does not do an attach(). - - \sa key() isAttached() - */ + Sets a new \a key for this shared memory object. + The \a key is first converted to a unicode string accepted by all supported platforms, + (see nativeKey()). If \a key and the current key are the same, the function returns + without doing anything. If the shared memory object is attached to an underlying + shared memory segment, it will \l {detach()} {detach} from it before setting the new key. + This function does not do an attach(). + + \sa key() nativeKey() isAttached() +*/ void QSharedMemory::setKey(const QString &key) { Q_D(QSharedMemory); - if (key == d->key) + if (key == d->key && d->makePlatformSafeKey(key) == d->nativeKey) return; if (isAttached()) detach(); d->cleanHandle(); d->key = key; + d->nativeKey = d->makePlatformSafeKey(key); +} + +/*! + \since 4.7 + Sets a new native \a key for this shared memory object. + The specified \a key is used as-is, without any conversion. The \a key has to be + in a valid format for the current operating system (e.g. under Unix a valid \a key + corresponds to a filename). Be aware that the application might not be portable. + This function returns without doing anything if the \a key equals the current + native key. If the shared memory object is attached to an underlying shared memory + segment, it will \l {detach()} {detach} from it before setting the new key. + This function does not do an attach(). + + \sa nativeKey() key() isAttached() +*/ +void QSharedMemory::setNativeKey(const QString &key) +{ + Q_D(QSharedMemory); + if (key == d->nativeKey && d->key.isNull()) + return; + + if (isAttached()) + detach(); + d->cleanHandle(); + d->key = QString(); + d->nativeKey = key; } bool QSharedMemoryPrivate::initKey() @@ -251,13 +282,14 @@ bool QSharedMemoryPrivate::initKey() } /*! - Returns the key assigned to this shared memory. The key is the - identifier used by the operating system to identify the shared - memory segment. When QSharedMemory is used for interprocess - communication, the key is how each process attaches to the shared - memory segment through which the IPC occurs. - - \sa setKey() + Returns the key assigned with setKey() to this shared memory. + The key is the identifier used by Qt applications to identify the shared + memory segment. The actual native key used by the operating system is returned + by nativeKey(). A null string is returned if the key was specified using setNativeKey(). + When QSharedMemory is used for interprocess communication, the key is how each + process attaches to the shared memory segment through which the IPC occurs. + + \sa setKey() setNativeKey() */ QString QSharedMemory::key() const { @@ -266,13 +298,31 @@ QString QSharedMemory::key() const } /*! - Creates a shared memory segment of \a size bytes with the key passed - to the constructor or set with setKey(), attaches to the new shared - memory segment with the given access \a mode, and returns \tt true. - If a shared memory segment identified by the key already exists, the - attach operation is not performed, and \tt false is returned. When - the return value is \tt false, call error() to determine which error - occurred. + \since 4.7 + Returns the native key assigned with setKey() or setNativeKey() to this shared memory. + The native key is the identifier used by the operating system to identify the + shared memory segment. When using setKey(), the native key is obtained by + converting the specified key into a format accepted by all supported platforms. + When using setNativeKey(), the native key actually corresponds to the specified key + without any conversion. When QSharedMemory is used for interprocess communication, + the key is how each process attaches to the shared memory segment through which + the IPC occurs. + + \sa setKey() setNativeKey() +*/ +QString QSharedMemory::nativeKey() const +{ + Q_D(const QSharedMemory); + return d->nativeKey; +} + +/*! + Creates a shared memory segment of \a size bytes with the key passed to the + constructor, set with setKey() or set with setNativeKey(), then attaches to + the new shared memory segment with the given access \a mode and returns + \tt true. If a shared memory segment identified by the key already exists, + the attach operation is not performed and \tt false is returned. When the + return value is \tt false, call error() to determine which error occurred. \sa error() */ @@ -294,7 +344,7 @@ bool QSharedMemory::create(int size, AccessMode mode) QString function = QLatin1String("QSharedMemory::create"); #ifndef QT_NO_SYSTEMSEMAPHORE QSharedMemoryLocker lock(this); - if (!d->tryLocker(&lock, function)) + if (!d->key.isNull() && !d->tryLocker(&lock, function)) return false; #endif @@ -338,7 +388,7 @@ int QSharedMemory::size() const /*! Attempts to attach the process to the shared memory segment identified by the key that was passed to the constructor or to a - call to setKey(). The access \a mode is \l {QSharedMemory::} + call to setKey() or setNativeKey(). The access \a mode is \l {QSharedMemory::} {ReadWrite} by default. It can also be \l {QSharedMemory::} {ReadOnly}. Returns true if the attach operation is successful. If false is returned, call error() to determine which error occurred. @@ -355,7 +405,7 @@ bool QSharedMemory::attach(AccessMode mode) return false; #ifndef QT_NO_SYSTEMSEMAPHORE QSharedMemoryLocker lock(this); - if (!d->tryLocker(&lock, QLatin1String("QSharedMemory::attach"))) + if (!d->key.isNull() && !d->tryLocker(&lock, QLatin1String("QSharedMemory::attach"))) return false; #endif @@ -395,7 +445,7 @@ bool QSharedMemory::detach() #ifndef QT_NO_SYSTEMSEMAPHORE QSharedMemoryLocker lock(this); - if (!d->tryLocker(&lock, QLatin1String("QSharedMemory::detach"))) + if (!d->key.isNull() && !d->tryLocker(&lock, QLatin1String("QSharedMemory::detach"))) return false; #endif @@ -451,9 +501,9 @@ const void *QSharedMemory::data() const by this process and returns true. If another process has locked the segment, this function blocks until the lock is released. Then it acquires the lock and returns true. If this function returns false, - it means either that you have ignored a false return from create() - or attach(), or that QSystemSemaphore::acquire() failed due to an - unknown system error. + it means that you have ignored a false return from create() or attach(), + that you have set the key with setNativeKey() or that + QSystemSemaphore::acquire() failed due to an unknown system error. \sa unlock(), data(), QSystemSemaphore::acquire() */ diff --git a/src/corelib/kernel/qsharedmemory.h b/src/corelib/kernel/qsharedmemory.h index fba939c..5673f43 100644 --- a/src/corelib/kernel/qsharedmemory.h +++ b/src/corelib/kernel/qsharedmemory.h @@ -85,6 +85,8 @@ public: void setKey(const QString &key); QString key() const; + void setNativeKey(const QString &key); + QString nativeKey() const; bool create(int size, AccessMode mode = ReadWrite); int size() const; diff --git a/src/corelib/kernel/qsharedmemory_p.h b/src/corelib/kernel/qsharedmemory_p.h index a52f8b3..632a6e9 100644 --- a/src/corelib/kernel/qsharedmemory_p.h +++ b/src/corelib/kernel/qsharedmemory_p.h @@ -122,6 +122,7 @@ public: void *memory; int size; QString key; + QString nativeKey; QSharedMemory::SharedMemoryError error; QString errorString; #ifndef QT_NO_SYSTEMSEMAPHORE diff --git a/src/corelib/kernel/qsharedmemory_symbian.cpp b/src/corelib/kernel/qsharedmemory_symbian.cpp index 9b84eb56..091c2b5 100644 --- a/src/corelib/kernel/qsharedmemory_symbian.cpp +++ b/src/corelib/kernel/qsharedmemory_symbian.cpp @@ -107,16 +107,14 @@ bool QSharedMemoryPrivate::cleanHandle() bool QSharedMemoryPrivate::create(int size) { - // Get a windows acceptable key - QString safeKey = makePlatformSafeKey(key); QString function = QLatin1String("QSharedMemory::create"); - if (safeKey.isEmpty()) { + if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: key error").arg(function); return false; } - TPtrC ptr(qt_QString2TPtrC(safeKey)); + TPtrC ptr(qt_QString2TPtrC(nativeKey)); TInt err = chunk.CreateGlobal(ptr, size, size); @@ -136,14 +134,13 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode /* mode */) // Grab a pointer to the memory block if (!chunk.Handle()) { QString function = QLatin1String("QSharedMemory::handle"); - QString safeKey = makePlatformSafeKey(key); - if (safeKey.isEmpty()) { + if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: unable to make key").arg(function); return false; } - TPtrC ptr(qt_QString2TPtrC(safeKey)); + TPtrC ptr(qt_QString2TPtrC(nativeKey)); TInt err = KErrNoMemory; diff --git a/src/corelib/kernel/qsharedmemory_unix.cpp b/src/corelib/kernel/qsharedmemory_unix.cpp index a5f79c2..064979b 100644 --- a/src/corelib/kernel/qsharedmemory_unix.cpp +++ b/src/corelib/kernel/qsharedmemory_unix.cpp @@ -116,21 +116,20 @@ key_t QSharedMemoryPrivate::handle() return unix_key; // don't allow making handles on empty keys - if (key.isEmpty()) { + if (nativeKey.isEmpty()) { errorString = QSharedMemory::tr("%1: key is empty").arg(QLatin1String("QSharedMemory::handle:")); error = QSharedMemory::KeyError; return 0; } // ftok requires that an actual file exists somewhere - QString fileName = makePlatformSafeKey(key); - if (!QFile::exists(fileName)) { + if (!QFile::exists(nativeKey)) { errorString = QSharedMemory::tr("%1: UNIX key file doesn't exist").arg(QLatin1String("QSharedMemory::handle:")); error = QSharedMemory::NotFound; return 0; } - unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); + unix_key = ftok(QFile::encodeName(nativeKey).constData(), 'Q'); if (-1 == unix_key) { errorString = QSharedMemory::tr("%1: ftok failed").arg(QLatin1String("QSharedMemory::handle:")); error = QSharedMemory::KeyError; @@ -181,7 +180,7 @@ bool QSharedMemoryPrivate::create(int size) { // build file if needed bool createdFile = false; - int built = createUnixKeyFile(makePlatformSafeKey(key)); + int built = createUnixKeyFile(nativeKey); if (built == -1) { errorString = QSharedMemory::tr("%1: unable to make key").arg(QLatin1String("QSharedMemory::handle:")); error = QSharedMemory::KeyError; @@ -194,7 +193,7 @@ bool QSharedMemoryPrivate::create(int size) // get handle if (!handle()) { if (createdFile) - QFile::remove(makePlatformSafeKey(key)); + QFile::remove(nativeKey); return false; } @@ -210,7 +209,7 @@ bool QSharedMemoryPrivate::create(int size) setErrorString(function); } if (createdFile && error != QSharedMemory::AlreadyExists) - QFile::remove(makePlatformSafeKey(key)); + QFile::remove(nativeKey); return false; } @@ -295,7 +294,7 @@ bool QSharedMemoryPrivate::detach() } // remove file - if (!QFile::remove(makePlatformSafeKey(key))) + if (!QFile::remove(nativeKey)) return false; } return true; diff --git a/src/corelib/kernel/qsharedmemory_win.cpp b/src/corelib/kernel/qsharedmemory_win.cpp index 0f5fdc7..0cdb123 100644 --- a/src/corelib/kernel/qsharedmemory_win.cpp +++ b/src/corelib/kernel/qsharedmemory_win.cpp @@ -99,18 +99,17 @@ HANDLE QSharedMemoryPrivate::handle() { if (!hand) { QString function = QLatin1String("QSharedMemory::handle"); - QString safeKey = makePlatformSafeKey(key); - if (safeKey.isEmpty()) { + if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: unable to make key").arg(function); return false; } #ifndef Q_OS_WINCE - hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)safeKey.utf16()); + hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)nativeKey.utf16()); #else // This works for opening a mapping too, but always opens it with read/write access in // attach as it seems. - hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 0, (wchar_t*)safeKey.utf16()); + hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 0, (wchar_t*)nativeKey.utf16()); #endif if (!hand) { setErrorString(function); @@ -133,17 +132,15 @@ bool QSharedMemoryPrivate::cleanHandle() bool QSharedMemoryPrivate::create(int size) { - // Get a windows acceptable key - QString safeKey = makePlatformSafeKey(key); QString function = QLatin1String("QSharedMemory::create"); - if (safeKey.isEmpty()) { + if (nativeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: key error").arg(function); return false; } // Create the file mapping. - hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)safeKey.utf16()); + hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)nativeKey.utf16()); setErrorString(function); // hand is valid when it already exists unlike unix so explicitly check diff --git a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp index 1f65ae7..dc071ab 100644 --- a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp +++ b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp @@ -225,11 +225,17 @@ void tst_QSharedMemory::key_data() { QTest::addColumn("constructorKey"); QTest::addColumn("setKey"); - - QTest::newRow("null, null") << QString() << QString(); - QTest::newRow("null, one") << QString() << QString("one"); - QTest::newRow("one, two") << QString("one") << QString("two"); - QTest::newRow("invalid") << QString("o/e") << QString("t/o"); + QTest::addColumn("setNativeKey"); + + QTest::newRow("null, null, null") << QString() << QString() << QString(); + QTest::newRow("one, null, null") << QString("one") << QString() << QString(); + QTest::newRow("null, one, null") << QString() << QString("one") << QString(); + QTest::newRow("null, null, one") << QString() << QString() << QString("one"); + QTest::newRow("one, two, null") << QString("one") << QString("two") << QString(); + QTest::newRow("one, null, two") << QString("one") << QString() << QString("two"); + QTest::newRow("null, one, two") << QString() << QString("one") << QString("two"); + QTest::newRow("one, two, three") << QString("one") << QString("two") << QString("three"); + QTest::newRow("invalid") << QString("o/e") << QString("t/o") << QString("|x"); } /*! @@ -239,11 +245,17 @@ void tst_QSharedMemory::key() { QFETCH(QString, constructorKey); QFETCH(QString, setKey); + QFETCH(QString, setNativeKey); QSharedMemory sm(constructorKey); QCOMPARE(sm.key(), constructorKey); + QCOMPARE(sm.nativeKey().isEmpty(), constructorKey.isEmpty()); sm.setKey(setKey); QCOMPARE(sm.key(), setKey); + QCOMPARE(sm.nativeKey().isEmpty(), setKey.isEmpty()); + sm.setNativeKey(setNativeKey); + QVERIFY(sm.key().isNull()); + QCOMPARE(sm.nativeKey(), setNativeKey); QCOMPARE(sm.isAttached(), false); QCOMPARE(sm.error(), QSharedMemory::NoError); @@ -262,7 +274,7 @@ void tst_QSharedMemory::create_data() QTest::addColumn("error"); QTest::newRow("null key") << QString() << 1024 - << false << QSharedMemory::LockError; + << false << QSharedMemory::KeyError; QTest::newRow("-1 size") << QString("negsize") << -1 << false << QSharedMemory::InvalidSize; QTest::newRow("nor size") << QString("norsize") << 1024 @@ -302,7 +314,7 @@ void tst_QSharedMemory::attach_data() QTest::addColumn("exists"); QTest::addColumn("error"); - QTest::newRow("null key") << QString() << false << QSharedMemory::LockError; + QTest::newRow("null key") << QString() << false << QSharedMemory::KeyError; QTest::newRow("doesn't exists") << QString("doesntexists") << false << QSharedMemory::NotFound; QTest::newRow("already exists") << QString(EXISTING_SHARE) << true << QSharedMemory::NoError; } -- cgit v0.12 From 26f3dbf0e20dbaf131bbbb35440b1ecb40b3f405 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 26 May 2010 14:00:15 +0200 Subject: Improved documentation for QSharedMemory's key/setKey functions. --- src/corelib/kernel/qsharedmemory.cpp | 64 +++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp index d5f4052..0782ffe 100644 --- a/src/corelib/kernel/qsharedmemory.cpp +++ b/src/corelib/kernel/qsharedmemory.cpp @@ -194,11 +194,15 @@ QSharedMemory::~QSharedMemory() } /*! - Sets a new \a key for this shared memory object. - The \a key is first converted to a unicode string accepted by all supported platforms, - (see nativeKey()). If \a key and the current key are the same, the function returns - without doing anything. If the shared memory object is attached to an underlying - shared memory segment, it will \l {detach()} {detach} from it before setting the new key. + Sets the platform independent \a key for this shared memory object. If \a key + is the same as the current key, the function returns without doing anything. + + You can call key() to retrieve the platform independent key. Internally, + QSharedMemory converts this key into a platform specific key. If you instead + call nativeKey(), you will get the platform specific, converted key. + + If the shared memory object is attached to an underlying shared memory + segment, it will \l {detach()} {detach} from it before setting the new key. This function does not do an attach(). \sa key() nativeKey() isAttached() @@ -217,16 +221,22 @@ void QSharedMemory::setKey(const QString &key) } /*! - \since 4.7 - Sets a new native \a key for this shared memory object. - The specified \a key is used as-is, without any conversion. The \a key has to be - in a valid format for the current operating system (e.g. under Unix a valid \a key - corresponds to a filename). Be aware that the application might not be portable. - This function returns without doing anything if the \a key equals the current - native key. If the shared memory object is attached to an underlying shared memory + \since 4.8 + + Sets the native, platform specific, \a key for this shared memory object. If + \a key is the same as the current native key, the function returns without + doing anything. If all you want is to assign a key to a segment, you should + call setKey() instead. + + You can call nativeKey() to retrieve the native key. If a native key has been + assigned, calling key() will return a null string. + + If the shared memory object is attached to an underlying shared memory segment, it will \l {detach()} {detach} from it before setting the new key. This function does not do an attach(). + The application will not be portable if you set a native key. + \sa nativeKey() key() isAttached() */ void QSharedMemory::setNativeKey(const QString &key) @@ -282,12 +292,13 @@ bool QSharedMemoryPrivate::initKey() } /*! - Returns the key assigned with setKey() to this shared memory. - The key is the identifier used by Qt applications to identify the shared - memory segment. The actual native key used by the operating system is returned - by nativeKey(). A null string is returned if the key was specified using setNativeKey(). - When QSharedMemory is used for interprocess communication, the key is how each - process attaches to the shared memory segment through which the IPC occurs. + Returns the key assigned with setKey() to this shared memory, or a null key + if no key has been assigned, or if the segment is using a nativeKey(). The + key is the identifier used by Qt applications to identify the shared memory + segment. + + You can find the native, platform specific, key used by the operating system + by calling nativeKey(). \sa setKey() setNativeKey() */ @@ -298,15 +309,14 @@ QString QSharedMemory::key() const } /*! - \since 4.7 - Returns the native key assigned with setKey() or setNativeKey() to this shared memory. - The native key is the identifier used by the operating system to identify the - shared memory segment. When using setKey(), the native key is obtained by - converting the specified key into a format accepted by all supported platforms. - When using setNativeKey(), the native key actually corresponds to the specified key - without any conversion. When QSharedMemory is used for interprocess communication, - the key is how each process attaches to the shared memory segment through which - the IPC occurs. + \since 4.8 + + Returns the native, platform specific, key for this shared memory object. The + native key is the identifier used by the operating system to identify the + shared memory segment. + + You can use the native key to access shared memory segments that have not + been created by Qt, or to grant shared memory access to non-Qt applications. \sa setKey() setNativeKey() */ -- cgit v0.12 From fe08f4841cd9928e7c9ad0b797ede13f473b51b7 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Mon, 31 May 2010 09:21:04 +0200 Subject: Fix a simple mistake in QXmlStreamReader::atEnd() docs. Merge-request: 655 Reviewed-by: Andreas Aardal Hanssen --- src/corelib/xml/qxmlstream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/xml/qxmlstream.cpp b/src/corelib/xml/qxmlstream.cpp index ae12007..853f311 100644 --- a/src/corelib/xml/qxmlstream.cpp +++ b/src/corelib/xml/qxmlstream.cpp @@ -560,7 +560,7 @@ void QXmlStreamReader::clear() chunk of XML can be added with addData(), if the XML is being read from a QByteArray, or by waiting for more data to arrive if the XML is being read from a QIODevice. Either way, atEnd() will - return false once more adata is available. + return false once more data is available. \sa hasError(), error(), device(), QIODevice::atEnd() */ -- cgit v0.12 From 8c8f7639c1643473c5c10d4c5b9d3016c9cf070d Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Mon, 31 May 2010 10:10:57 +0200 Subject: Revert "Improved documentation for QSharedMemory's key/setKey functions." This reverts commit 26f3dbf0e20dbaf131bbbb35440b1ecb40b3f405. --- src/corelib/kernel/qsharedmemory.cpp | 64 +++++++++++++++--------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp index 0782ffe..d5f4052 100644 --- a/src/corelib/kernel/qsharedmemory.cpp +++ b/src/corelib/kernel/qsharedmemory.cpp @@ -194,15 +194,11 @@ QSharedMemory::~QSharedMemory() } /*! - Sets the platform independent \a key for this shared memory object. If \a key - is the same as the current key, the function returns without doing anything. - - You can call key() to retrieve the platform independent key. Internally, - QSharedMemory converts this key into a platform specific key. If you instead - call nativeKey(), you will get the platform specific, converted key. - - If the shared memory object is attached to an underlying shared memory - segment, it will \l {detach()} {detach} from it before setting the new key. + Sets a new \a key for this shared memory object. + The \a key is first converted to a unicode string accepted by all supported platforms, + (see nativeKey()). If \a key and the current key are the same, the function returns + without doing anything. If the shared memory object is attached to an underlying + shared memory segment, it will \l {detach()} {detach} from it before setting the new key. This function does not do an attach(). \sa key() nativeKey() isAttached() @@ -221,22 +217,16 @@ void QSharedMemory::setKey(const QString &key) } /*! - \since 4.8 - - Sets the native, platform specific, \a key for this shared memory object. If - \a key is the same as the current native key, the function returns without - doing anything. If all you want is to assign a key to a segment, you should - call setKey() instead. - - You can call nativeKey() to retrieve the native key. If a native key has been - assigned, calling key() will return a null string. - - If the shared memory object is attached to an underlying shared memory + \since 4.7 + Sets a new native \a key for this shared memory object. + The specified \a key is used as-is, without any conversion. The \a key has to be + in a valid format for the current operating system (e.g. under Unix a valid \a key + corresponds to a filename). Be aware that the application might not be portable. + This function returns without doing anything if the \a key equals the current + native key. If the shared memory object is attached to an underlying shared memory segment, it will \l {detach()} {detach} from it before setting the new key. This function does not do an attach(). - The application will not be portable if you set a native key. - \sa nativeKey() key() isAttached() */ void QSharedMemory::setNativeKey(const QString &key) @@ -292,13 +282,12 @@ bool QSharedMemoryPrivate::initKey() } /*! - Returns the key assigned with setKey() to this shared memory, or a null key - if no key has been assigned, or if the segment is using a nativeKey(). The - key is the identifier used by Qt applications to identify the shared memory - segment. - - You can find the native, platform specific, key used by the operating system - by calling nativeKey(). + Returns the key assigned with setKey() to this shared memory. + The key is the identifier used by Qt applications to identify the shared + memory segment. The actual native key used by the operating system is returned + by nativeKey(). A null string is returned if the key was specified using setNativeKey(). + When QSharedMemory is used for interprocess communication, the key is how each + process attaches to the shared memory segment through which the IPC occurs. \sa setKey() setNativeKey() */ @@ -309,14 +298,15 @@ QString QSharedMemory::key() const } /*! - \since 4.8 - - Returns the native, platform specific, key for this shared memory object. The - native key is the identifier used by the operating system to identify the - shared memory segment. - - You can use the native key to access shared memory segments that have not - been created by Qt, or to grant shared memory access to non-Qt applications. + \since 4.7 + Returns the native key assigned with setKey() or setNativeKey() to this shared memory. + The native key is the identifier used by the operating system to identify the + shared memory segment. When using setKey(), the native key is obtained by + converting the specified key into a format accepted by all supported platforms. + When using setNativeKey(), the native key actually corresponds to the specified key + without any conversion. When QSharedMemory is used for interprocess communication, + the key is how each process attaches to the shared memory segment through which + the IPC occurs. \sa setKey() setNativeKey() */ -- cgit v0.12 From 3026f8ce811e8cebc48e49f732344cc13e107cc6 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Mon, 31 May 2010 10:11:05 +0200 Subject: Revert "Added native key support to QSharedMemory API." This reverts commit 9b4ff3deb28b3d642dc4480207f2f23841cf26e9. --- src/corelib/kernel/qsharedmemory.cpp | 120 ++++++--------------- src/corelib/kernel/qsharedmemory.h | 2 - src/corelib/kernel/qsharedmemory_p.h | 1 - src/corelib/kernel/qsharedmemory_symbian.cpp | 11 +- src/corelib/kernel/qsharedmemory_unix.cpp | 15 +-- src/corelib/kernel/qsharedmemory_win.cpp | 13 ++- .../auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp | 26 ++--- 7 files changed, 65 insertions(+), 123 deletions(-) diff --git a/src/corelib/kernel/qsharedmemory.cpp b/src/corelib/kernel/qsharedmemory.cpp index d5f4052..fe93ebc 100644 --- a/src/corelib/kernel/qsharedmemory.cpp +++ b/src/corelib/kernel/qsharedmemory.cpp @@ -142,12 +142,9 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key, remain. Do not mix using QtSharedMemory and QSharedMemory. Port everything to QSharedMemory. - \warning QSharedMemory changes the key in a Qt-specific way, unless otherwise - specified. Interoperation with non-Qt applications is achieved by first creating - a default shared memory with QSharedMemory() and then setting a native key with - setNativeKey(). When using native keys, shared memory is not protected against - multiple accesses on it (e.g. unable to lock()) and a user-defined mechanism - should be used to achieve a such protection. + \warning QSharedMemory changes the key in a Qt-specific way. + It is therefore currently not possible to use the shared memory of + non-Qt applications with QSharedMemory. */ /*! @@ -156,8 +153,8 @@ QSharedMemoryPrivate::makePlatformSafeKey(const QString &key, Constructs a shared memory object with the given \a parent. The shared memory object's key is not set by the constructor, so the shared memory object does not have an underlying shared memory - segment attached. The key must be set with setKey() or setNativeKey() - before create() or attach() can be used. + segment attached. The key must be set with setKey() before create() + or attach() can be used. \sa setKey() */ @@ -194,52 +191,24 @@ QSharedMemory::~QSharedMemory() } /*! - Sets a new \a key for this shared memory object. - The \a key is first converted to a unicode string accepted by all supported platforms, - (see nativeKey()). If \a key and the current key are the same, the function returns - without doing anything. If the shared memory object is attached to an underlying - shared memory segment, it will \l {detach()} {detach} from it before setting the new key. - This function does not do an attach(). - - \sa key() nativeKey() isAttached() -*/ + Sets a new \a key for this shared memory object. If \a key and the + current key are the same, the function returns without doing + anything. If the shared memory object is attached to an underlying + shared memory segment, it will \l {detach()} {detach} from it before + setting the new key. This function does not do an attach(). + + \sa key() isAttached() + */ void QSharedMemory::setKey(const QString &key) { Q_D(QSharedMemory); - if (key == d->key && d->makePlatformSafeKey(key) == d->nativeKey) + if (key == d->key) return; if (isAttached()) detach(); d->cleanHandle(); d->key = key; - d->nativeKey = d->makePlatformSafeKey(key); -} - -/*! - \since 4.7 - Sets a new native \a key for this shared memory object. - The specified \a key is used as-is, without any conversion. The \a key has to be - in a valid format for the current operating system (e.g. under Unix a valid \a key - corresponds to a filename). Be aware that the application might not be portable. - This function returns without doing anything if the \a key equals the current - native key. If the shared memory object is attached to an underlying shared memory - segment, it will \l {detach()} {detach} from it before setting the new key. - This function does not do an attach(). - - \sa nativeKey() key() isAttached() -*/ -void QSharedMemory::setNativeKey(const QString &key) -{ - Q_D(QSharedMemory); - if (key == d->nativeKey && d->key.isNull()) - return; - - if (isAttached()) - detach(); - d->cleanHandle(); - d->key = QString(); - d->nativeKey = key; } bool QSharedMemoryPrivate::initKey() @@ -282,14 +251,13 @@ bool QSharedMemoryPrivate::initKey() } /*! - Returns the key assigned with setKey() to this shared memory. - The key is the identifier used by Qt applications to identify the shared - memory segment. The actual native key used by the operating system is returned - by nativeKey(). A null string is returned if the key was specified using setNativeKey(). - When QSharedMemory is used for interprocess communication, the key is how each - process attaches to the shared memory segment through which the IPC occurs. - - \sa setKey() setNativeKey() + Returns the key assigned to this shared memory. The key is the + identifier used by the operating system to identify the shared + memory segment. When QSharedMemory is used for interprocess + communication, the key is how each process attaches to the shared + memory segment through which the IPC occurs. + + \sa setKey() */ QString QSharedMemory::key() const { @@ -298,31 +266,13 @@ QString QSharedMemory::key() const } /*! - \since 4.7 - Returns the native key assigned with setKey() or setNativeKey() to this shared memory. - The native key is the identifier used by the operating system to identify the - shared memory segment. When using setKey(), the native key is obtained by - converting the specified key into a format accepted by all supported platforms. - When using setNativeKey(), the native key actually corresponds to the specified key - without any conversion. When QSharedMemory is used for interprocess communication, - the key is how each process attaches to the shared memory segment through which - the IPC occurs. - - \sa setKey() setNativeKey() -*/ -QString QSharedMemory::nativeKey() const -{ - Q_D(const QSharedMemory); - return d->nativeKey; -} - -/*! - Creates a shared memory segment of \a size bytes with the key passed to the - constructor, set with setKey() or set with setNativeKey(), then attaches to - the new shared memory segment with the given access \a mode and returns - \tt true. If a shared memory segment identified by the key already exists, - the attach operation is not performed and \tt false is returned. When the - return value is \tt false, call error() to determine which error occurred. + Creates a shared memory segment of \a size bytes with the key passed + to the constructor or set with setKey(), attaches to the new shared + memory segment with the given access \a mode, and returns \tt true. + If a shared memory segment identified by the key already exists, the + attach operation is not performed, and \tt false is returned. When + the return value is \tt false, call error() to determine which error + occurred. \sa error() */ @@ -344,7 +294,7 @@ bool QSharedMemory::create(int size, AccessMode mode) QString function = QLatin1String("QSharedMemory::create"); #ifndef QT_NO_SYSTEMSEMAPHORE QSharedMemoryLocker lock(this); - if (!d->key.isNull() && !d->tryLocker(&lock, function)) + if (!d->tryLocker(&lock, function)) return false; #endif @@ -388,7 +338,7 @@ int QSharedMemory::size() const /*! Attempts to attach the process to the shared memory segment identified by the key that was passed to the constructor or to a - call to setKey() or setNativeKey(). The access \a mode is \l {QSharedMemory::} + call to setKey(). The access \a mode is \l {QSharedMemory::} {ReadWrite} by default. It can also be \l {QSharedMemory::} {ReadOnly}. Returns true if the attach operation is successful. If false is returned, call error() to determine which error occurred. @@ -405,7 +355,7 @@ bool QSharedMemory::attach(AccessMode mode) return false; #ifndef QT_NO_SYSTEMSEMAPHORE QSharedMemoryLocker lock(this); - if (!d->key.isNull() && !d->tryLocker(&lock, QLatin1String("QSharedMemory::attach"))) + if (!d->tryLocker(&lock, QLatin1String("QSharedMemory::attach"))) return false; #endif @@ -445,7 +395,7 @@ bool QSharedMemory::detach() #ifndef QT_NO_SYSTEMSEMAPHORE QSharedMemoryLocker lock(this); - if (!d->key.isNull() && !d->tryLocker(&lock, QLatin1String("QSharedMemory::detach"))) + if (!d->tryLocker(&lock, QLatin1String("QSharedMemory::detach"))) return false; #endif @@ -501,9 +451,9 @@ const void *QSharedMemory::data() const by this process and returns true. If another process has locked the segment, this function blocks until the lock is released. Then it acquires the lock and returns true. If this function returns false, - it means that you have ignored a false return from create() or attach(), - that you have set the key with setNativeKey() or that - QSystemSemaphore::acquire() failed due to an unknown system error. + it means either that you have ignored a false return from create() + or attach(), or that QSystemSemaphore::acquire() failed due to an + unknown system error. \sa unlock(), data(), QSystemSemaphore::acquire() */ diff --git a/src/corelib/kernel/qsharedmemory.h b/src/corelib/kernel/qsharedmemory.h index 5673f43..fba939c 100644 --- a/src/corelib/kernel/qsharedmemory.h +++ b/src/corelib/kernel/qsharedmemory.h @@ -85,8 +85,6 @@ public: void setKey(const QString &key); QString key() const; - void setNativeKey(const QString &key); - QString nativeKey() const; bool create(int size, AccessMode mode = ReadWrite); int size() const; diff --git a/src/corelib/kernel/qsharedmemory_p.h b/src/corelib/kernel/qsharedmemory_p.h index 632a6e9..a52f8b3 100644 --- a/src/corelib/kernel/qsharedmemory_p.h +++ b/src/corelib/kernel/qsharedmemory_p.h @@ -122,7 +122,6 @@ public: void *memory; int size; QString key; - QString nativeKey; QSharedMemory::SharedMemoryError error; QString errorString; #ifndef QT_NO_SYSTEMSEMAPHORE diff --git a/src/corelib/kernel/qsharedmemory_symbian.cpp b/src/corelib/kernel/qsharedmemory_symbian.cpp index 091c2b5..9b84eb56 100644 --- a/src/corelib/kernel/qsharedmemory_symbian.cpp +++ b/src/corelib/kernel/qsharedmemory_symbian.cpp @@ -107,14 +107,16 @@ bool QSharedMemoryPrivate::cleanHandle() bool QSharedMemoryPrivate::create(int size) { + // Get a windows acceptable key + QString safeKey = makePlatformSafeKey(key); QString function = QLatin1String("QSharedMemory::create"); - if (nativeKey.isEmpty()) { + if (safeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: key error").arg(function); return false; } - TPtrC ptr(qt_QString2TPtrC(nativeKey)); + TPtrC ptr(qt_QString2TPtrC(safeKey)); TInt err = chunk.CreateGlobal(ptr, size, size); @@ -134,13 +136,14 @@ bool QSharedMemoryPrivate::attach(QSharedMemory::AccessMode /* mode */) // Grab a pointer to the memory block if (!chunk.Handle()) { QString function = QLatin1String("QSharedMemory::handle"); - if (nativeKey.isEmpty()) { + QString safeKey = makePlatformSafeKey(key); + if (safeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: unable to make key").arg(function); return false; } - TPtrC ptr(qt_QString2TPtrC(nativeKey)); + TPtrC ptr(qt_QString2TPtrC(safeKey)); TInt err = KErrNoMemory; diff --git a/src/corelib/kernel/qsharedmemory_unix.cpp b/src/corelib/kernel/qsharedmemory_unix.cpp index 064979b..a5f79c2 100644 --- a/src/corelib/kernel/qsharedmemory_unix.cpp +++ b/src/corelib/kernel/qsharedmemory_unix.cpp @@ -116,20 +116,21 @@ key_t QSharedMemoryPrivate::handle() return unix_key; // don't allow making handles on empty keys - if (nativeKey.isEmpty()) { + if (key.isEmpty()) { errorString = QSharedMemory::tr("%1: key is empty").arg(QLatin1String("QSharedMemory::handle:")); error = QSharedMemory::KeyError; return 0; } // ftok requires that an actual file exists somewhere - if (!QFile::exists(nativeKey)) { + QString fileName = makePlatformSafeKey(key); + if (!QFile::exists(fileName)) { errorString = QSharedMemory::tr("%1: UNIX key file doesn't exist").arg(QLatin1String("QSharedMemory::handle:")); error = QSharedMemory::NotFound; return 0; } - unix_key = ftok(QFile::encodeName(nativeKey).constData(), 'Q'); + unix_key = ftok(QFile::encodeName(fileName).constData(), 'Q'); if (-1 == unix_key) { errorString = QSharedMemory::tr("%1: ftok failed").arg(QLatin1String("QSharedMemory::handle:")); error = QSharedMemory::KeyError; @@ -180,7 +181,7 @@ bool QSharedMemoryPrivate::create(int size) { // build file if needed bool createdFile = false; - int built = createUnixKeyFile(nativeKey); + int built = createUnixKeyFile(makePlatformSafeKey(key)); if (built == -1) { errorString = QSharedMemory::tr("%1: unable to make key").arg(QLatin1String("QSharedMemory::handle:")); error = QSharedMemory::KeyError; @@ -193,7 +194,7 @@ bool QSharedMemoryPrivate::create(int size) // get handle if (!handle()) { if (createdFile) - QFile::remove(nativeKey); + QFile::remove(makePlatformSafeKey(key)); return false; } @@ -209,7 +210,7 @@ bool QSharedMemoryPrivate::create(int size) setErrorString(function); } if (createdFile && error != QSharedMemory::AlreadyExists) - QFile::remove(nativeKey); + QFile::remove(makePlatformSafeKey(key)); return false; } @@ -294,7 +295,7 @@ bool QSharedMemoryPrivate::detach() } // remove file - if (!QFile::remove(nativeKey)) + if (!QFile::remove(makePlatformSafeKey(key))) return false; } return true; diff --git a/src/corelib/kernel/qsharedmemory_win.cpp b/src/corelib/kernel/qsharedmemory_win.cpp index 0cdb123..0f5fdc7 100644 --- a/src/corelib/kernel/qsharedmemory_win.cpp +++ b/src/corelib/kernel/qsharedmemory_win.cpp @@ -99,17 +99,18 @@ HANDLE QSharedMemoryPrivate::handle() { if (!hand) { QString function = QLatin1String("QSharedMemory::handle"); - if (nativeKey.isEmpty()) { + QString safeKey = makePlatformSafeKey(key); + if (safeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: unable to make key").arg(function); return false; } #ifndef Q_OS_WINCE - hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)nativeKey.utf16()); + hand = OpenFileMapping(FILE_MAP_ALL_ACCESS, false, (wchar_t*)safeKey.utf16()); #else // This works for opening a mapping too, but always opens it with read/write access in // attach as it seems. - hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 0, (wchar_t*)nativeKey.utf16()); + hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, 0, (wchar_t*)safeKey.utf16()); #endif if (!hand) { setErrorString(function); @@ -132,15 +133,17 @@ bool QSharedMemoryPrivate::cleanHandle() bool QSharedMemoryPrivate::create(int size) { + // Get a windows acceptable key + QString safeKey = makePlatformSafeKey(key); QString function = QLatin1String("QSharedMemory::create"); - if (nativeKey.isEmpty()) { + if (safeKey.isEmpty()) { error = QSharedMemory::KeyError; errorString = QSharedMemory::tr("%1: key error").arg(function); return false; } // Create the file mapping. - hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)nativeKey.utf16()); + hand = CreateFileMapping(INVALID_HANDLE_VALUE, 0, PAGE_READWRITE, 0, size, (wchar_t*)safeKey.utf16()); setErrorString(function); // hand is valid when it already exists unlike unix so explicitly check diff --git a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp index dc071ab..1f65ae7 100644 --- a/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp +++ b/tests/auto/qtipc/qsharedmemory/tst_qsharedmemory.cpp @@ -225,17 +225,11 @@ void tst_QSharedMemory::key_data() { QTest::addColumn("constructorKey"); QTest::addColumn("setKey"); - QTest::addColumn("setNativeKey"); - - QTest::newRow("null, null, null") << QString() << QString() << QString(); - QTest::newRow("one, null, null") << QString("one") << QString() << QString(); - QTest::newRow("null, one, null") << QString() << QString("one") << QString(); - QTest::newRow("null, null, one") << QString() << QString() << QString("one"); - QTest::newRow("one, two, null") << QString("one") << QString("two") << QString(); - QTest::newRow("one, null, two") << QString("one") << QString() << QString("two"); - QTest::newRow("null, one, two") << QString() << QString("one") << QString("two"); - QTest::newRow("one, two, three") << QString("one") << QString("two") << QString("three"); - QTest::newRow("invalid") << QString("o/e") << QString("t/o") << QString("|x"); + + QTest::newRow("null, null") << QString() << QString(); + QTest::newRow("null, one") << QString() << QString("one"); + QTest::newRow("one, two") << QString("one") << QString("two"); + QTest::newRow("invalid") << QString("o/e") << QString("t/o"); } /*! @@ -245,17 +239,11 @@ void tst_QSharedMemory::key() { QFETCH(QString, constructorKey); QFETCH(QString, setKey); - QFETCH(QString, setNativeKey); QSharedMemory sm(constructorKey); QCOMPARE(sm.key(), constructorKey); - QCOMPARE(sm.nativeKey().isEmpty(), constructorKey.isEmpty()); sm.setKey(setKey); QCOMPARE(sm.key(), setKey); - QCOMPARE(sm.nativeKey().isEmpty(), setKey.isEmpty()); - sm.setNativeKey(setNativeKey); - QVERIFY(sm.key().isNull()); - QCOMPARE(sm.nativeKey(), setNativeKey); QCOMPARE(sm.isAttached(), false); QCOMPARE(sm.error(), QSharedMemory::NoError); @@ -274,7 +262,7 @@ void tst_QSharedMemory::create_data() QTest::addColumn("error"); QTest::newRow("null key") << QString() << 1024 - << false << QSharedMemory::KeyError; + << false << QSharedMemory::LockError; QTest::newRow("-1 size") << QString("negsize") << -1 << false << QSharedMemory::InvalidSize; QTest::newRow("nor size") << QString("norsize") << 1024 @@ -314,7 +302,7 @@ void tst_QSharedMemory::attach_data() QTest::addColumn("exists"); QTest::addColumn("error"); - QTest::newRow("null key") << QString() << false << QSharedMemory::KeyError; + QTest::newRow("null key") << QString() << false << QSharedMemory::LockError; QTest::newRow("doesn't exists") << QString("doesntexists") << false << QSharedMemory::NotFound; QTest::newRow("already exists") << QString(EXISTING_SHARE) << true << QSharedMemory::NoError; } -- cgit v0.12 From 3860340918846b5b156ba8e018d12cfe90461208 Mon Sep 17 00:00:00 2001 From: Tasuku Suzuki Date: Mon, 31 May 2010 12:23:12 +0200 Subject: Fix QT_NO_DIRMODEL build error in QtDeclarative. Reviewed-by: Andreas Aardal Hanssen Merge-request: 652 Merge-request: 652 Reviewed-by: Andreas Aardal Hanssen --- src/imports/folderlistmodel/plugin.cpp | 2 ++ src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp | 4 ++++ src/imports/folderlistmodel/qdeclarativefolderlistmodel.h | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/src/imports/folderlistmodel/plugin.cpp b/src/imports/folderlistmodel/plugin.cpp index 555df3c..1ec6106 100644 --- a/src/imports/folderlistmodel/plugin.cpp +++ b/src/imports/folderlistmodel/plugin.cpp @@ -53,7 +53,9 @@ public: virtual void registerTypes(const char *uri) { Q_ASSERT(QLatin1String(uri) == QLatin1String("Qt.labs.folderlistmodel")); +#ifndef QT_NO_DIRMODEL qmlRegisterType(uri,1,0,"FolderListModel"); +#endif } }; //![class decl] diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp index fccb9d4..9cf81ca 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.cpp @@ -45,6 +45,8 @@ #include #include +#ifndef QT_NO_DIRMODEL + QT_BEGIN_NAMESPACE class QDeclarativeFolderListModelPrivate @@ -397,3 +399,5 @@ void QDeclarativeFolderListModel::setShowOnlyReadable(bool on) //![code] QT_END_NAMESPACE + +#endif // QT_NO_DIRMODEL diff --git a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h index ea7d701..1bab5f84 100644 --- a/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h +++ b/src/imports/folderlistmodel/qdeclarativefolderlistmodel.h @@ -47,6 +47,8 @@ #include #include +#ifndef QT_NO_DIRMODEL + QT_BEGIN_HEADER QT_BEGIN_NAMESPACE @@ -152,4 +154,6 @@ QML_DECLARE_TYPE(QDeclarativeFolderListModel) QT_END_HEADER +#endif // QT_NO_DIRMODEL + #endif // QDECLARATIVEFOLDERLISTMODEL_H -- cgit v0.12 From e845c0d7a8ed33f2aa2a3ae5ebce931ea2043037 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 31 May 2010 11:45:25 +0200 Subject: Fix compilation with stricts compilers. Base class is type-dependent. One must not use unqualified-id to access base member. Reveiwed-by: Roberto Raggi --- tools/porting/src/codemodel.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/porting/src/codemodel.h b/tools/porting/src/codemodel.h index cb3088f..04ad178 100644 --- a/tools/porting/src/codemodel.h +++ b/tools/porting/src/codemodel.h @@ -96,7 +96,7 @@ class Collection: public QMultiHash { public: void add(CollectedType *collectedItem) - { insert(collectedItem->name(), collectedItem); } + { this->insert(collectedItem->name(), collectedItem); } }; typedef Collection ScopeCollection; -- cgit v0.12 From aa0b5d35b29fd2f23223e5a4eca4b0d48c74cb2f Mon Sep 17 00:00:00 2001 From: Morten Engvoldsen Date: Mon, 31 May 2010 13:09:37 +0200 Subject: Doc: replacing old image Task-number: QT-1520 --- .../assistant/doc/images/assistant-assistant.png | Bin 105954 -> 205326 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/tools/assistant/tools/assistant/doc/images/assistant-assistant.png b/tools/assistant/tools/assistant/doc/images/assistant-assistant.png index b825d