~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kspread/plugins/scripting/ScriptingModule.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-09-21 15:36:35 UTC
  • mfrom: (1.4.1 upstream) (60.2.11 maverick)
  • Revision ID: james.westby@ubuntu.com-20100921153635-6tejqkiro2u21ydi
Tags: 1:2.2.2-0ubuntu3
Add kubuntu_03_fix-crash-on-closing-sqlite-connection-2.2.2.diff and
kubuntu_04_support-large-memo-values-for-msaccess-2.2.2.diff as
recommended by upstream http://kexi-
project.org/wiki/wikiview/index.php@Kexi2.2_Patches.html#sqlite_stab
ility

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
extern "C"
45
45
{
46
 
    KDE_EXPORT QObject* krossmodule()
47
 
    {
 
46
    KDE_EXPORT QObject* krossmodule() {
48
47
        return new ScriptingModule();
49
48
    }
50
49
}
52
51
/// \internal d-pointer class.
53
52
class ScriptingModule::Private
54
53
{
55
 
        public:
56
 
                QPointer<KSpread::Doc> doc;
57
 
                QHash< QString, ScriptingFunction* > functions;
58
 
                QStringList functionnames;
 
54
public:
 
55
    QPointer<KSpread::Doc> doc;
 
56
    QHash< QString, ScriptingFunction* > functions;
 
57
    QStringList functionnames;
59
58
};
60
59
 
61
60
ScriptingModule::ScriptingModule(QObject* parent)
62
 
        : KoScriptingModule(parent, "KSpread")
63
 
        , d( new Private() )
 
61
        : KoScriptingModule(parent, "KSpread")
 
62
        , d(new Private())
64
63
{
65
 
        d->doc = 0;
 
64
    d->doc = 0;
66
65
}
67
66
 
68
67
ScriptingModule::~ScriptingModule()
69
68
{
70
 
        kDebug() <<"ScriptingModule::~ScriptingModule()";
71
 
        delete d;
 
69
    kDebug() << "ScriptingModule::~ScriptingModule()";
 
70
    delete d;
72
71
}
73
72
 
74
73
KSpread::View* ScriptingModule::kspreadView()
75
74
{
76
 
    return dynamic_cast< KSpread::View* >( KoScriptingModule::view() );
 
75
    return dynamic_cast< KSpread::View* >(KoScriptingModule::view());
77
76
}
78
77
 
79
78
KSpread::Doc* ScriptingModule::kspreadDoc()
80
79
{
81
 
        if(! d->doc) {
82
 
                if( KSpread::View* v = kspreadView() )
83
 
                        d->doc = v->doc();
84
 
                if( ! d->doc )
85
 
                        d->doc = new KSpread::Doc(0, this);
86
 
        }
87
 
        return d->doc;
 
80
    if (! d->doc) {
 
81
        if (KSpread::View* v = kspreadView())
 
82
            d->doc = v->doc();
 
83
        if (! d->doc)
 
84
            d->doc = new KSpread::Doc(0, this);
 
85
    }
 
86
    return d->doc;
88
87
}
89
88
 
90
89
KoDocument* ScriptingModule::doc()
91
90
{
92
 
        return kspreadDoc();
 
91
    return kspreadDoc();
93
92
}
94
93
 
95
94
QObject* ScriptingModule::map()
96
95
{
97
 
        return kspreadDoc()->map()->findChild< KSpread::MapAdaptor* >();
 
96
    return kspreadDoc()->map()->findChild< KSpread::MapAdaptor* >();
98
97
}
99
98
 
100
99
QObject* ScriptingModule::view()
101
100
{
102
 
        KSpread::View* v = kspreadView();
103
 
        return v ? v->findChild< KSpread::ViewAdaptor* >() : 0;
 
101
    KSpread::View* v = kspreadView();
 
102
    return v ? v->findChild< KSpread::ViewAdaptor* >() : 0;
104
103
}
105
104
 
106
105
QObject* ScriptingModule::currentSheet()
112
111
 
113
112
QObject* ScriptingModule::sheetByName(const QString& name)
114
113
{
115
 
        if(kspreadDoc()->map())
116
 
                foreach(KSpread::Sheet* sheet, kspreadDoc()->map()->sheetList())
117
 
                        if(sheet->sheetName() == name)
118
 
                                return sheet->findChild< KSpread::SheetAdaptor* >();
119
 
        return 0;
 
114
    if (kspreadDoc()->map())
 
115
        foreach(KSpread::Sheet* sheet, kspreadDoc()->map()->sheetList()) {
 
116
        if (sheet->sheetName() == name) {
 
117
            return sheet->findChild< KSpread::SheetAdaptor* >(); {
 
118
            }
 
119
        }
 
120
    }
 
121
    return 0;
120
122
}
121
123
 
122
124
QStringList ScriptingModule::sheetNames()
123
125
{
124
 
        QStringList names;
125
 
        foreach(KSpread::Sheet* sheet, kspreadDoc()->map()->sheetList())
126
 
                names.append(sheet->sheetName());
127
 
        return names;
 
126
    QStringList names;
 
127
    foreach(KSpread::Sheet* sheet, kspreadDoc()->map()->sheetList()) {
 
128
        names.append(sheet->sheetName());
 
129
    }
 
130
    return names;
128
131
}
129
132
 
130
133
bool ScriptingModule::hasFunction(const QString& name)
131
134
{
132
 
        return d->functions.contains(name);
 
135
    return d->functions.contains(name);
133
136
}
134
137
 
135
138
QObject* ScriptingModule::function(const QString& name)
136
139
{
137
 
        if( d->functions.contains(name) )
138
 
                return d->functions[name];
139
 
        ScriptingFunction* function = new ScriptingFunction(this);
140
 
        function->setName(name);
141
 
        d->functions.insert(name, function);
142
 
        d->functionnames.append(name);
143
 
        return function;
 
140
    if (d->functions.contains(name))
 
141
        return d->functions[name];
 
142
    ScriptingFunction* function = new ScriptingFunction(this);
 
143
    function->setName(name);
 
144
    d->functions.insert(name, function);
 
145
    d->functionnames.append(name);
 
146
    return function;
144
147
}
145
148
 
146
149
QObject* ScriptingModule::createListener(const QString& sheetname, const QString& range)
147
150
{
148
151
    KSpread::Sheet* sheet = kspreadDoc()->map()->findSheet(sheetname);
149
 
    if( ! sheet ) return 0;
 
152
    if (! sheet) return 0;
150
153
    KSpread::Region region(range, kspreadDoc()->map(), sheet);
151
154
    QRect r = region.firstRange();
152
155
    return new KSpread::ScriptingCellListener(sheet, r.isNull() ? sheet->usedArea() : r);
154
157
 
155
158
bool ScriptingModule::fromXML(const QString& xml)
156
159
{
157
 
        KoXmlDocument xmldoc;
158
 
        if(! xmldoc.setContent(xml, true))
159
 
                return false;
160
 
        return kspreadDoc()->loadXML(xmldoc, 0);
 
160
    KoXmlDocument xmldoc;
 
161
    if (! xmldoc.setContent(xml, true))
 
162
        return false;
 
163
    return kspreadDoc()->loadXML(xmldoc, 0);
161
164
}
162
165
 
163
166
QString ScriptingModule::toXML()
164
167
{
165
 
        return kspreadDoc()->saveXML().toString(2);
 
168
    return kspreadDoc()->saveXML().toString(2);
166
169
}
167
170
 
168
171
bool ScriptingModule::openUrl(const QString& url)
172
175
 
173
176
bool ScriptingModule::saveUrl(const QString& url)
174
177
{
175
 
        return kspreadDoc()->saveAs(url);
 
178
    return kspreadDoc()->saveAs(url);
176
179
}
177
180
 
178
181
bool ScriptingModule::importUrl(const QString& url)
179
182
{
180
 
        return kspreadDoc()->importDocument(url);
 
183
    return kspreadDoc()->importDocument(url);
181
184
}
182
185
 
183
186
bool ScriptingModule::exportUrl(const QString& url)
184
187
{
185
 
        return kspreadDoc()->exportDocument(url);
 
188
    return kspreadDoc()->exportDocument(url);
186
189
}
187
190
 
188
191
QObject* ScriptingModule::reader()
197
200
 
198
201
QWidget* ScriptingModule::createSheetsListView(QWidget* parent)
199
202
{
200
 
        ScriptingSheetsListView* listview = new ScriptingSheetsListView(this, parent);
201
 
        if( parent && parent->layout() )
202
 
                parent->layout()->addWidget(listview);
203
 
        return listview;
 
203
    ScriptingSheetsListView* listview = new ScriptingSheetsListView(this, parent);
 
204
    if (parent && parent->layout())
 
205
        parent->layout()->addWidget(listview);
 
206
    return listview;
204
207
}
205
208
 
206
209
#include "ScriptingModule.moc"