Exemplo n.º 1
0
int PMObjectSelect::selectObject( PMObject* link,
                                  const QStringList& t,
                                  PMObject* & obj, QWidget* parent )
{
   PMObject* last = link;
   PMObject* scene;
   bool stop = false;
   bool found = false;
   
   do
   {
      scene = last->parent( );
      if( scene )
      {
         if( scene->type( ) == "Scene" )
         {
            last = last->prevSibling( );
            stop = true;
            found = true;
         }
         else
            last = last->parent( );
      }
      else
         stop = true;
   }
   while( !stop );
   
   if( found )
   {
      PMObjectSelect s( parent );

      PMObject* o = scene->firstChild( );
      bool l = false;
      
      while( o && !l && last )
      {
         if( t.findIndex( o->type( ) ) >= 0 )
            s.m_pListBox->insertItem( new PMListBoxObject( o ) );
         
         if( o == last )
            l = true;
         else
            o = o->nextSibling( );
      }
   
      int result = s.exec( );
      if( result == Accepted )
         obj = s.selectedObject( );
      
      return result;
   }
   else
      kdError( PMArea ) << "PMObjectSelect: Link does not seem to be correctly inserted in the scene.\n";
   return Rejected;
}
Exemplo n.º 2
0
double PMTextureMapBase::mapValue( const PMObject* obj ) const
{
   PMObject* o = firstChild( );
   QValueList<double>::ConstIterator it = m_mapValues.begin( );

   while( o && ( o != obj ) )
   {
      if( o->type( ) == mapType( ) )
         ++it;
      o = o->nextSibling( );
   }
   return *it;
}
Exemplo n.º 3
0
QValueList<double>::Iterator PMTextureMapBase::valueForChild( PMObject* obj )
{
   PMObject* o = firstChild( );
   QValueList<double>::Iterator it = m_mapValues.begin( );

   while( o && ( o != obj ) )
   {
      if( o->type( ) == mapType( ) )
         ++it;
      o = o->nextSibling( );
   }
   return it;
}
Exemplo n.º 4
0
PMObject* PMTextureMapBase::nextMapEntry( PMObject* o )
{
   bool stop = false;
   PMObject* result = o;

   do
   {
      if( result == 0 )
         result = firstChild( );
      else
         result = result->nextSibling( );

      if( !result )
         stop = true;
      else if( result->type( ) == mapType( ) )
         stop = true;
   }
   while( !stop );

   return result;
}
Exemplo n.º 5
0
int PMInsertRuleSystem::canInsert( const PMObject* parentObject,
                                   const QStringList& list,
                                   const PMObject* after )
{
   if( list.size( ) == 1 )
   {
      // more efficient
      if( canInsert( parentObject, list.first( ), after ) )
         return 1;
      else
         return 0;
   }

   // find rules for target class
   QPtrList<PMRuleTargetClass> targetClassList;
   PMMetaObject* meta = parentObject->metaObject( );
   for( ; meta; meta = meta->superClass( ) )
   {
      PMRuleTargetClass* tc = m_rulesDict.find( meta->className( ) );
      if( tc )
         targetClassList.append( tc );
   }
   if( targetClassList.isEmpty( ) )
      return 0; // not rules found

   // count already inserted children
   QPtrListIterator<PMRuleTargetClass> tit( targetClassList );
   for( ; tit.current( ); ++tit ) // ... for all target classes
   {
      QPtrListIterator<PMRule> rit = tit.current( )->rules( );
      for( ; rit.current( ); ++rit ) // ... and all rules
      {
         rit.current( )->reset( );
         bool afterInsertPoint = false;
         PMObject* o = parentObject->firstChild( );
         if( !after )
            afterInsertPoint = true;
         for( ; o; o = o->nextSibling( ) )
         {
            rit.current( )->countChild( o->className( ), afterInsertPoint );
            if( o == after )
               afterInsertPoint = true;
         }
      }
   }

   int number = 0;
   QStringList::const_iterator oit;

   for( oit = list.begin( ); oit != list.end( ); ++oit )
   {
      bool possible = false;
      for( tit.toFirst( ); tit.current( ) && !possible; ++tit )
      {
         QPtrListIterator<PMRule> rit = tit.current( )->rules( );

         for( ; rit.current( ) && !possible; ++rit )
         {
            PMRule* rule = rit.current( );
            if( rule->matches( *oit ) )
               possible = rule->evaluate( parentObject );
         }
      }
      if( possible )
      {
         // object can be inserted, count it
         for( ; tit.current( ); ++tit )
         {
            QPtrListIterator<PMRule> rit = tit.current( )->rules( );
            for( ; rit.current( ); ++rit )
               rit.current( )->countChild( *oit, false );
         }
			number++;
      }
   }

   return number;
}
Exemplo n.º 6
0
bool PMInsertRuleSystem::canInsert( const PMObject* parentObject,
                                    const QString& className,
                                    const PMObject* after,
                                    const PMObjectList* objectsBetween )
{
   bool possible = false;

   // find rules for target class
   PMMetaObject* meta = parentObject->metaObject( );
   for( ; meta && !possible; meta = meta->superClass( ) )
   {
      PMRuleTargetClass* tc = m_rulesDict.find( meta->className( ) );
      if( tc )
      {
         // check the exception list
         QStringList exceptions = tc->exceptions( );
         bool exceptionFound = false;
         QStringList::ConstIterator it;
         for( it = exceptions.begin( );
              it != exceptions.end( ) && !exceptionFound; ++it )
            if( parentObject->isA( *it ) )
               exceptionFound = true;

         if( !exceptionFound )
         {
            QPtrListIterator<PMRule> rit = tc->rules( );
            // find matching rules for class name
            for( ; rit.current( ) && !possible; ++rit )
            {
               PMRule* rule = rit.current( );
               if( rule->matches( className ) )
               {
                  // matching rule found
                  // reset the rule
                  rit.current( )->reset( );

                  // count already inserted child objects
                  bool afterInsertPoint = false;
                  PMObject* o = parentObject->firstChild( );
                  if( !after )
                     afterInsertPoint = true;
                  for( ; o; o = o->nextSibling( ) )
                  {
                     rule->countChild( o->className( ), afterInsertPoint );
                     if( o == after )
                        afterInsertPoint = true;
                  }
                  if( objectsBetween )
                  {
                     PMObjectListIterator it( *objectsBetween );
                     for( ; it.current( ); ++it )
                        rule->countChild( it.current( )->type( ), false );
                  }

                  // evaluate condition value
                  possible = rule->evaluate( parentObject );
               }
            }
         }
      }
   }

   return possible;
}
Exemplo n.º 7
0
PMObjectDrag::PMObjectDrag( PMPart* part, const PMObjectList& objList, QWidget* dragSource,
                            const char* name )
      : QDragObject( dragSource, name )
{
   QByteArray modelerData;

   QTextStream s2( modelerData, IO_WriteOnly );
   QDomDocument doc( "KPOVMODELER" );
   QDomElement top = doc.createElement( "objects" );
   doc.appendChild( top );
   top.setAttribute( "majorFormat", c_majorDocumentFormat );
   top.setAttribute( "minorFormat", c_minorDocumentFormat );

   PMObjectListIterator it( objList );
   for( ; it.current( ); ++it )
   {
      if( it.current( )->type( ) == "Scene" )
      {
         PMObject* o = it.current( )->firstChild( );
         for( ; o; o = o->nextSibling( ) )
         {
            QDomElement e = o->serialize( doc );
            top.appendChild( e );
         }
      }
      else
      {
         QDomElement e = it.current( )->serialize( doc );
         top.appendChild( e );
      }
   }

   s2 << doc;

   m_data.push_back( modelerData );
   m_mimeTypes.push_back( c_kpmDocumentMimeFormat );

   const QPtrList<PMIOFormat>& formats = part->ioManager( )->formats( );
   QPtrListIterator<PMIOFormat> fit( formats );
   for( ; fit.current( ); ++fit )
   {
      if( fit.current( )->services( ) & PMIOFormat::Export )
      {
         QByteArray data;
         QBuffer buffer( data );
         buffer.open( IO_WriteOnly );

         PMSerializer* ser = fit.current( )->newSerializer( &buffer );

         if( ser )
         {
            ser->serializeList( objList );
            ser->close( );
            delete ser;
            buffer.close( );

            m_data.push_back( data );
            m_mimeTypes.push_back( fit.current( )->mimeType( ) );

            kdDebug( PMArea ) << "Added mime type " << fit.current( )->mimeType( )
                              << " " << data.size( ) << " bytes" << endl;
         }
         else
            kdError( PMArea ) << "Format claims to support exporting, but doesn't provide a serializer" << endl;

         buffer.close( );
      }
   }
}