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 | unsigned int numFields = 0; | ||||
aacid: you don't need this anymore? | |||||
138 | | ||||
139 | for ( const Page * pIt : qAsConst(doc->m_pagesVector) ) | ||||
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 | { | ||||
141 | numFields += pIt->formFields().size(); | ||||
142 | } | ||||
sander: Why not simply `numFields += pIt->formFields()` ? | |||||
143 | | ||||
144 | return KJSNumber( numFields ); | ||||
145 | } | ||||
146 | | ||||
132 | 147 | | |||
133 | static KJSObject docGetInfo( KJSContext *ctx, void *object ) | 148 | static KJSObject docGetInfo( KJSContext *ctx, void *object ) | ||
134 | { | 149 | { | ||
135 | DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | 150 | DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | ||
136 | 151 | | |||
137 | KJSObject obj; | 152 | KJSObject obj; | ||
138 | QSet<DocumentInfo::Key> keys; | 153 | QSet<DocumentInfo::Key> keys; | ||
139 | keys << DocumentInfo::Title | 154 | keys << DocumentInfo::Title | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | |||||
243 | 258 | | |||
244 | // Document.syncAnnotScan() | 259 | // Document.syncAnnotScan() | ||
245 | static KJSObject docSyncAnnotScan( KJSContext *, void *, | 260 | static KJSObject docSyncAnnotScan( KJSContext *, void *, | ||
246 | const KJSArguments & ) | 261 | const KJSArguments & ) | ||
247 | { | 262 | { | ||
248 | return KJSUndefined(); | 263 | return KJSUndefined(); | ||
249 | } | 264 | } | ||
250 | 265 | | |||
266 | // Document.getNthFieldName | ||||
267 | static KJSObject docGetNthFieldName( KJSContext *ctx, void *object, | ||||
268 | const KJSArguments &arguments ) | ||||
269 | { | ||||
270 | DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); | ||||
271 | | ||||
272 | int numField = arguments.at( 0 ).toInt32( ctx ); | ||||
273 | | ||||
274 | for ( const Page * pIt : qAsConst(doc->m_pagesVector) ) | ||||
275 | { | ||||
sander: Please use a range-based for loop. | |||||
276 | const QLinkedList< Okular::FormField * > pageFields = pIt->formFields(); | ||||
277 | | ||||
278 | if(numField < pageFields.size()) | ||||
279 | { | ||||
280 | auto ffIt = pageFields.begin(); | ||||
281 | ffIt += numField; | ||||
282 | | ||||
283 | return KJSString( (*ffIt)->name() ); | ||||
284 | } | ||||
285 | | ||||
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… | |||||
286 | numField -= pageFields.size(); | ||||
287 | } | ||||
288 | | ||||
289 | return KJSUndefined(); | ||||
290 | } | ||||
291 | | ||||
251 | void JSDocument::initType( KJSContext *ctx ) | 292 | void JSDocument::initType( KJSContext *ctx ) | ||
252 | { | 293 | { | ||
253 | assert( g_docProto ); | 294 | assert( g_docProto ); | ||
254 | 295 | | |||
255 | static bool initialized = false; | 296 | static bool initialized = false; | ||
256 | if ( initialized ) | 297 | if ( initialized ) | ||
257 | return; | 298 | return; | ||
258 | initialized = true; | 299 | initialized = true; | ||
259 | 300 | | |||
260 | g_docProto->defineProperty( ctx, QStringLiteral("numPages"), docGetNumPages ); | 301 | g_docProto->defineProperty( ctx, QStringLiteral("numPages"), docGetNumPages ); | ||
261 | g_docProto->defineProperty( ctx, QStringLiteral("pageNum"), docGetPageNum, docSetPageNum ); | 302 | g_docProto->defineProperty( ctx, QStringLiteral("pageNum"), docGetPageNum, docSetPageNum ); | ||
262 | g_docProto->defineProperty( ctx, QStringLiteral("documentFileName"), docGetDocumentFileName ); | 303 | g_docProto->defineProperty( ctx, QStringLiteral("documentFileName"), docGetDocumentFileName ); | ||
263 | g_docProto->defineProperty( ctx, QStringLiteral("filesize"), docGetFilesize ); | 304 | g_docProto->defineProperty( ctx, QStringLiteral("filesize"), docGetFilesize ); | ||
264 | g_docProto->defineProperty( ctx, QStringLiteral("path"), docGetPath ); | 305 | g_docProto->defineProperty( ctx, QStringLiteral("path"), docGetPath ); | ||
265 | g_docProto->defineProperty( ctx, QStringLiteral("URL"), docGetURL ); | 306 | g_docProto->defineProperty( ctx, QStringLiteral("URL"), docGetURL ); | ||
266 | g_docProto->defineProperty( ctx, QStringLiteral("permStatusReady"), docGetPermStatusReady ); | 307 | g_docProto->defineProperty( ctx, QStringLiteral("permStatusReady"), docGetPermStatusReady ); | ||
267 | g_docProto->defineProperty( ctx, QStringLiteral("dataObjects"), docGetDataObjects ); | 308 | g_docProto->defineProperty( ctx, QStringLiteral("dataObjects"), docGetDataObjects ); | ||
268 | g_docProto->defineProperty( ctx, QStringLiteral("external"), docGetExternal ); | 309 | g_docProto->defineProperty( ctx, QStringLiteral("external"), docGetExternal ); | ||
310 | g_docProto->defineProperty( ctx, QStringLiteral("numFields"), docGetNumFields ); | ||||
269 | 311 | | |||
270 | // info properties | 312 | // info properties | ||
271 | g_docProto->defineProperty( ctx, QStringLiteral("info"), docGetInfo ); | 313 | g_docProto->defineProperty( ctx, QStringLiteral("info"), docGetInfo ); | ||
272 | g_docProto->defineProperty( ctx, QStringLiteral("author"), docGetAuthor ); | 314 | g_docProto->defineProperty( ctx, QStringLiteral("author"), docGetAuthor ); | ||
273 | g_docProto->defineProperty( ctx, QStringLiteral("creator"), docGetCreator ); | 315 | g_docProto->defineProperty( ctx, QStringLiteral("creator"), docGetCreator ); | ||
274 | g_docProto->defineProperty( ctx, QStringLiteral("keywords"), docGetKeywords ); | 316 | g_docProto->defineProperty( ctx, QStringLiteral("keywords"), docGetKeywords ); | ||
275 | g_docProto->defineProperty( ctx, QStringLiteral("producer"), docGetProducer ); | 317 | g_docProto->defineProperty( ctx, QStringLiteral("producer"), docGetProducer ); | ||
276 | g_docProto->defineProperty( ctx, QStringLiteral("title"), docGetTitle ); | 318 | g_docProto->defineProperty( ctx, QStringLiteral("title"), docGetTitle ); | ||
277 | g_docProto->defineProperty( ctx, QStringLiteral("subject"), docGetSubject ); | 319 | g_docProto->defineProperty( ctx, QStringLiteral("subject"), docGetSubject ); | ||
278 | 320 | | |||
279 | g_docProto->defineFunction( ctx, QStringLiteral("getField"), docGetField ); | 321 | g_docProto->defineFunction( ctx, QStringLiteral("getField"), docGetField ); | ||
280 | g_docProto->defineFunction( ctx, QStringLiteral("getPageLabel"), docGetPageLabel ); | 322 | g_docProto->defineFunction( ctx, QStringLiteral("getPageLabel"), docGetPageLabel ); | ||
281 | g_docProto->defineFunction( ctx, QStringLiteral("getPageRotation"), docGetPageRotation ); | 323 | g_docProto->defineFunction( ctx, QStringLiteral("getPageRotation"), docGetPageRotation ); | ||
282 | g_docProto->defineFunction( ctx, QStringLiteral("gotoNamedDest"), docGotoNamedDest ); | 324 | g_docProto->defineFunction( ctx, QStringLiteral("gotoNamedDest"), docGotoNamedDest ); | ||
283 | g_docProto->defineFunction( ctx, QStringLiteral("syncAnnotScan"), docSyncAnnotScan ); | 325 | g_docProto->defineFunction( ctx, QStringLiteral("syncAnnotScan"), docSyncAnnotScan ); | ||
326 | g_docProto->defineFunction( ctx, QStringLiteral("getNthFieldName"), docGetNthFieldName ); | ||||
284 | } | 327 | } | ||
285 | 328 | | |||
286 | KJSGlobalObject JSDocument::wrapDocument( DocumentPrivate *doc ) | 329 | KJSGlobalObject JSDocument::wrapDocument( DocumentPrivate *doc ) | ||
287 | { | 330 | { | ||
288 | if ( !g_docProto ) | 331 | if ( !g_docProto ) | ||
289 | g_docProto = new KJSPrototype(); | 332 | g_docProto = new KJSPrototype(); | ||
290 | return g_docProto->constructGlobalObject( doc ); | 333 | return g_docProto->constructGlobalObject( doc ); | ||
291 | } | 334 | } |
you don't need this anymore?