Changeset View
Changeset View
Standalone View
Standalone View
core/script/kjs_document.cpp
Show First 20 Lines • Show All 123 Lines • ▼ Show 20 Line(s) | 122 | { | |||
---|---|---|---|---|---|
124 | QWidget *widget = doc->m_widget; | 124 | QWidget *widget = doc->m_widget; | ||
125 | 125 | | |||
126 | const bool isShell = ( widget | 126 | const bool isShell = ( widget | ||
127 | && widget->parentWidget() | 127 | && widget->parentWidget() | ||
128 | && widget->parentWidget()->objectName().startsWith( QLatin1String( "okular::Shell" ) ) ); | 128 | && widget->parentWidget()->objectName().startsWith( QLatin1String( "okular::Shell" ) ) ); | ||
129 | return KJSBoolean( !isShell ); | 129 | return KJSBoolean( !isShell ); | ||
130 | } | 130 | } | ||
131 | 131 | | |||
132 | // Document.numFields | ||||
133 | static KJSObject docGetNumFields( KJSContext *, void *object ) | ||||
134 | { | ||||
135 | DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | ||||
136 | | ||||
137 | QVector< Page * >::const_iterator pIt = doc->m_pagesVector.constBegin(), pEnd = doc->m_pagesVector.constEnd(); | ||||
aacid: you don't need this anymore? | |||||
138 | unsigned int numFields = 0; | ||||
139 | | ||||
As you were using const iterators before: Shouldn't this be qAsConst(doc->m_pagesVector) to avoid unnecessary detaching? sander: As you were using const iterators before: Shouldn't this be `qAsConst(doc->m_pagesVector)` to… | |||||
140 | for ( Page * pIt : doc->m_pagesVector ) | ||||
141 | { | ||||
142 | const QLinkedList< Okular::FormField * > pageFields = pIt->formFields(); | ||||
sander: Why not simply `numFields += pIt->formFields()` ? | |||||
143 | numFields += pageFields.size(); | ||||
144 | } | ||||
145 | | ||||
146 | return KJSNumber( numFields ); | ||||
147 | } | ||||
148 | | ||||
132 | 149 | | |||
133 | static KJSObject docGetInfo( KJSContext *ctx, void *object ) | 150 | static KJSObject docGetInfo( KJSContext *ctx, void *object ) | ||
134 | { | 151 | { | ||
135 | DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | 152 | DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | ||
136 | 153 | | |||
137 | KJSObject obj; | 154 | KJSObject obj; | ||
138 | QSet<DocumentInfo::Key> keys; | 155 | QSet<DocumentInfo::Key> keys; | ||
139 | keys << DocumentInfo::Title | 156 | keys << DocumentInfo::Title | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | |||||
243 | 260 | | |||
244 | // Document.syncAnnotScan() | 261 | // Document.syncAnnotScan() | ||
245 | static KJSObject docSyncAnnotScan( KJSContext *, void *, | 262 | static KJSObject docSyncAnnotScan( KJSContext *, void *, | ||
246 | const KJSArguments & ) | 263 | const KJSArguments & ) | ||
247 | { | 264 | { | ||
248 | return KJSUndefined(); | 265 | return KJSUndefined(); | ||
249 | } | 266 | } | ||
250 | 267 | | |||
268 | // Document.getNthFieldName | ||||
269 | static KJSObject docGetNthFieldName( KJSContext *ctx, void *object, | ||||
270 | const KJSArguments &arguments ) | ||||
271 | { | ||||
272 | DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | ||||
273 | | ||||
274 | int numField = arguments.at( 0 ).toInt32( ctx ); | ||||
275 | | ||||
276 | for ( Page * pIt : doc->m_pagesVector ) | ||||
277 | { | ||||
sander: Please use a range-based for loop. | |||||
278 | const QLinkedList< Okular::FormField * > pageFields = pIt->formFields(); | ||||
279 | for( Okular::FormField *ffIt : pageFields ) | ||||
280 | { | ||||
281 | if(numField == 0) | ||||
282 | { | ||||
283 | return KJSString( ffIt->name() ); | ||||
284 | } | ||||
285 | numField--; | ||||
286 | } | ||||
287 | } | ||||
This convoluted for loop basically get the i-th element of a QLinkedList, which is not designed for index accessing (and that is why there is no at(int) method).
pino: This convoluted for loop basically get the i-th element of a QLinkedList, which is not designed… | |||||
I still have to check for all the pages. But my new implementation looks more like with what you described joaonetto: I still have to check for all the pages.
But my new implementation looks more like with what… | |||||
288 | return KJSUndefined(); | ||||
289 | } | ||||
290 | | ||||
251 | void JSDocument::initType( KJSContext *ctx ) | 291 | void JSDocument::initType( KJSContext *ctx ) | ||
252 | { | 292 | { | ||
253 | assert( g_docProto ); | 293 | assert( g_docProto ); | ||
254 | 294 | | |||
255 | static bool initialized = false; | 295 | static bool initialized = false; | ||
256 | if ( initialized ) | 296 | if ( initialized ) | ||
257 | return; | 297 | return; | ||
258 | initialized = true; | 298 | initialized = true; | ||
259 | 299 | | |||
260 | g_docProto->defineProperty( ctx, QStringLiteral("numPages"), docGetNumPages ); | 300 | g_docProto->defineProperty( ctx, QStringLiteral("numPages"), docGetNumPages ); | ||
261 | g_docProto->defineProperty( ctx, QStringLiteral("pageNum"), docGetPageNum, docSetPageNum ); | 301 | g_docProto->defineProperty( ctx, QStringLiteral("pageNum"), docGetPageNum, docSetPageNum ); | ||
262 | g_docProto->defineProperty( ctx, QStringLiteral("documentFileName"), docGetDocumentFileName ); | 302 | g_docProto->defineProperty( ctx, QStringLiteral("documentFileName"), docGetDocumentFileName ); | ||
263 | g_docProto->defineProperty( ctx, QStringLiteral("filesize"), docGetFilesize ); | 303 | g_docProto->defineProperty( ctx, QStringLiteral("filesize"), docGetFilesize ); | ||
264 | g_docProto->defineProperty( ctx, QStringLiteral("path"), docGetPath ); | 304 | g_docProto->defineProperty( ctx, QStringLiteral("path"), docGetPath ); | ||
265 | g_docProto->defineProperty( ctx, QStringLiteral("URL"), docGetURL ); | 305 | g_docProto->defineProperty( ctx, QStringLiteral("URL"), docGetURL ); | ||
266 | g_docProto->defineProperty( ctx, QStringLiteral("permStatusReady"), docGetPermStatusReady ); | 306 | g_docProto->defineProperty( ctx, QStringLiteral("permStatusReady"), docGetPermStatusReady ); | ||
267 | g_docProto->defineProperty( ctx, QStringLiteral("dataObjects"), docGetDataObjects ); | 307 | g_docProto->defineProperty( ctx, QStringLiteral("dataObjects"), docGetDataObjects ); | ||
268 | g_docProto->defineProperty( ctx, QStringLiteral("external"), docGetExternal ); | 308 | g_docProto->defineProperty( ctx, QStringLiteral("external"), docGetExternal ); | ||
309 | g_docProto->defineProperty( ctx, QStringLiteral("numFields"), docGetNumFields ); | ||||
269 | 310 | | |||
270 | // info properties | 311 | // info properties | ||
271 | g_docProto->defineProperty( ctx, QStringLiteral("info"), docGetInfo ); | 312 | g_docProto->defineProperty( ctx, QStringLiteral("info"), docGetInfo ); | ||
272 | g_docProto->defineProperty( ctx, QStringLiteral("author"), docGetAuthor ); | 313 | g_docProto->defineProperty( ctx, QStringLiteral("author"), docGetAuthor ); | ||
273 | g_docProto->defineProperty( ctx, QStringLiteral("creator"), docGetCreator ); | 314 | g_docProto->defineProperty( ctx, QStringLiteral("creator"), docGetCreator ); | ||
274 | g_docProto->defineProperty( ctx, QStringLiteral("keywords"), docGetKeywords ); | 315 | g_docProto->defineProperty( ctx, QStringLiteral("keywords"), docGetKeywords ); | ||
275 | g_docProto->defineProperty( ctx, QStringLiteral("producer"), docGetProducer ); | 316 | g_docProto->defineProperty( ctx, QStringLiteral("producer"), docGetProducer ); | ||
276 | g_docProto->defineProperty( ctx, QStringLiteral("title"), docGetTitle ); | 317 | g_docProto->defineProperty( ctx, QStringLiteral("title"), docGetTitle ); | ||
277 | g_docProto->defineProperty( ctx, QStringLiteral("subject"), docGetSubject ); | 318 | g_docProto->defineProperty( ctx, QStringLiteral("subject"), docGetSubject ); | ||
278 | 319 | | |||
279 | g_docProto->defineFunction( ctx, QStringLiteral("getField"), docGetField ); | 320 | g_docProto->defineFunction( ctx, QStringLiteral("getField"), docGetField ); | ||
280 | g_docProto->defineFunction( ctx, QStringLiteral("getPageLabel"), docGetPageLabel ); | 321 | g_docProto->defineFunction( ctx, QStringLiteral("getPageLabel"), docGetPageLabel ); | ||
281 | g_docProto->defineFunction( ctx, QStringLiteral("getPageRotation"), docGetPageRotation ); | 322 | g_docProto->defineFunction( ctx, QStringLiteral("getPageRotation"), docGetPageRotation ); | ||
282 | g_docProto->defineFunction( ctx, QStringLiteral("gotoNamedDest"), docGotoNamedDest ); | 323 | g_docProto->defineFunction( ctx, QStringLiteral("gotoNamedDest"), docGotoNamedDest ); | ||
283 | g_docProto->defineFunction( ctx, QStringLiteral("syncAnnotScan"), docSyncAnnotScan ); | 324 | g_docProto->defineFunction( ctx, QStringLiteral("syncAnnotScan"), docSyncAnnotScan ); | ||
325 | g_docProto->defineFunction( ctx, QStringLiteral("getNthFieldName"), docGetNthFieldName ); | ||||
284 | } | 326 | } | ||
285 | 327 | | |||
286 | KJSGlobalObject JSDocument::wrapDocument( DocumentPrivate *doc ) | 328 | KJSGlobalObject JSDocument::wrapDocument( DocumentPrivate *doc ) | ||
287 | { | 329 | { | ||
288 | if ( !g_docProto ) | 330 | if ( !g_docProto ) | ||
289 | g_docProto = new KJSPrototype(); | 331 | g_docProto = new KJSPrototype(); | ||
290 | return g_docProto->constructGlobalObject( doc ); | 332 | return g_docProto->constructGlobalObject( doc ); | ||
291 | } | 333 | } |
you don't need this anymore?