~ubuntu-branches/ubuntu/oneiric/pyside/oneiric

« back to all changes in this revision

Viewing changes to libpyside/dynamicqmetaobject.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Raboud
  • Date: 2010-10-19 22:52:14 UTC
  • mfrom: (1.1.4 upstream)
  • mto: (13.1.1 sid)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20101019225214-0s9fbpz12x3962qa
Tags: upstream-0.4.2
ImportĀ upstreamĀ versionĀ 0.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#define MAX_SIGNALS_COUNT 50
37
37
#define MAX_SLOTS_COUNT 50
38
38
 
 
39
#define MAX_GLOBAL_SIGNALS_COUNT 500
 
40
#define MAX_GLOBAL_SLOTS_COUNT 500
 
41
 
 
42
#define GLOBAL_RECEIVER_CLASS_NAME "__GlobalReceiver__"
 
43
 
39
44
using namespace PySide;
40
45
 
41
46
enum PropertyFlags  {
110
115
    return strcmp(type, "qreal") == 0;
111
116
}
112
117
 
 
118
 
 
119
 
 
120
/*
 
121
 * Avoid API break keep this on cpp
 
122
 */
 
123
static int maxSlotsCount(const QString& className)
 
124
{
 
125
    int maxSlots = MAX_SLOTS_COUNT;
 
126
    if (className == GLOBAL_RECEIVER_CLASS_NAME)
 
127
        maxSlots = MAX_GLOBAL_SIGNALS_COUNT;
 
128
    return maxSlots;
 
129
}
 
130
 
 
131
static int maxSignalsCount(const QString& className)
 
132
{
 
133
    int maxSignals = MAX_SIGNALS_COUNT;
 
134
    if (className == GLOBAL_RECEIVER_CLASS_NAME)
 
135
        maxSignals = MAX_GLOBAL_SIGNALS_COUNT;
 
136
    return maxSignals;
 
137
}
 
138
 
113
139
uint PropertyData::flags() const
114
140
{
115
141
    const char* typeName = type().data();
271
297
        return;
272
298
    }
273
299
 
274
 
    if (m_signals.size() >= MAX_SIGNALS_COUNT) {
275
 
        qWarning() << "Fail to add dynamic signal to QObject. PySide support at most" << MAX_SIGNALS_COUNT << "dynamic signals.";
 
300
    int maxSignals = maxSignalsCount(m_className);
 
301
    if (m_signals.size() >= maxSignals) {
 
302
        qWarning() << "Fail to add dynamic signal to QObject. PySide support at most" << maxSignals << "dynamic signals.";
276
303
        return;
277
304
    }
278
305
 
286
313
    if (i != m_slots.end())
287
314
        return;
288
315
 
289
 
    if (m_slots.size() >= MAX_SLOTS_COUNT) {
290
 
        qWarning() << "Fail to add dynamic slot to QObject. PySide support at most" << MAX_SLOTS_COUNT << "dynamic slots.";
 
316
    int maxSlots = maxSlotsCount(m_className);
 
317
    if (m_slots.size() >= maxSlots) {
 
318
        qWarning() << "Fail to add dynamic slot to QObject. PySide support at most" << maxSlots << "dynamic slots.";
291
319
        return;
292
320
    }
293
321
 
294
322
    //search for a empty space
295
323
    MethodData blank;
296
324
    i = qFind(m_slots.begin(), m_slots.end(), blank);
297
 
    if (i != m_slots.end()) {
 
325
    if (i != m_slots.end())
298
326
        *i = MethodData(slot, type);
299
 
    } else {
 
327
    else
300
328
        m_slots << MethodData(slot, type);
301
 
    }
302
329
    updateMetaObject();
303
330
}
304
331
 
410
437
        if (iMethod != methods.end() && ((*iMethod).signature().size() > 0) ) {
411
438
            (*data)[index++] = registerString((*iMethod).signature(), strings); // func name
412
439
            mType = (*iMethod).type();
413
 
            iMethod++;
414
440
        } else {
415
441
            (*data)[index++] = null_index; // func name
416
442
        }
418
444
        (*data)[index++] = (mType.size() > 0 ? registerString(mType, strings) : null_index); // normalized type
419
445
        (*data)[index++] = null_index; // tags
420
446
        (*data)[index++] = flags;
 
447
        if (iMethod != methods.end()) 
 
448
            iMethod++;
421
449
    }
422
450
 
423
451
    *prtIndex = index;
439
467
        MethodScriptable = 0x40
440
468
    };
441
469
 
442
 
    uint n_signals = MAX_SIGNALS_COUNT;
443
 
    uint n_methods = n_signals + MAX_SLOTS_COUNT;
 
470
    int maxSignals = maxSignalsCount(m_className);
 
471
    int maxSlots = maxSlotsCount(m_className);
 
472
 
 
473
    uint n_signals = maxSignals;
 
474
    uint n_methods = n_signals + maxSlots;
444
475
    uint n_properties = m_properties.size();
445
476
    int header[] = {5,            // revision
446
477
                    0,            // class name index in m_metadata
465
496
    int index = HEADER_LENGHT;
466
497
 
467
498
    //write signals
468
 
    writeMethodsData(m_signals, &data, &strings, &index, MAX_SIGNALS_COUNT, NULL_INDEX, AccessPublic | MethodSignal);
 
499
    writeMethodsData(m_signals, &data, &strings, &index, maxSignals, NULL_INDEX, AccessPublic | MethodSignal);
469
500
 
470
501
    //write slots
471
 
    writeMethodsData(m_slots, &data, &strings, &index, MAX_SLOTS_COUNT, NULL_INDEX, AccessPublic | MethodSlot);
 
502
    writeMethodsData(m_slots, &data, &strings, &index, maxSlots, NULL_INDEX, AccessPublic | MethodSlot);
472
503
 
473
504
    if (m_properties.size())
474
505
        data[7] = index;
481
512
            data[index++] = NULL_INDEX;
482
513
 
483
514
        data[index++] = (pp.isValid() ? registerString(pp.type(), &strings) :  NULL_INDEX); // normalized type
484
 
        data[index++] = pp.flags(); //pp.flags(); //TODO: flags
 
515
        data[index++] = pp.flags();
485
516
    }
486
517
 
487
518
    data[index++] = 0; // the end