[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdeedu/rocs/src
From:       Wagner de Melo Reck <wagner.reck () gmail ! com>
Date:       2010-08-01 0:47:45
Message-ID: 20100801004745.EB045AC783 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1157722 by reck:

changing DS (but not yet converting from one to other).

 M  +53 -10    Core/DSPluginManager.cpp  
 M  +3 -2      Core/DSPluginManager.h  
 M  +4 -2      Core/graphDocument.cpp  
 M  +1 -0      Core/graphDocument.h  
 M  +2 -1      Interface/MainWindow.cpp  


--- trunk/KDE/kdeedu/rocs/src/Core/DSPluginManager.cpp #1157721:1157722
@@ -25,6 +25,8 @@
 #include <KDebug>
 
 #include <QHash>
+#include <QAction>
+
 namespace Rocs {
 class DSPluginManagerPrivate {
 public:
@@ -40,13 +42,13 @@
     }
     void loadPlugins() {
         loadDSPlugins();
-        if (plugins.isEmpty())
+        if (m_plugins.isEmpty())
           return;
         m_actualPlugin = pluginList().last();
     }
 
     KPluginInfo pluginInfo ( DSPluginInterface* plugin ) {
-        QString name = plugins.key(plugin);
+        QString name = m_plugins.key(plugin);
         foreach (KPluginInfo inf, m_DSPluginsInfo){
           if (inf.name() == name){
               return inf;
@@ -54,28 +56,54 @@
         }
         return KPluginInfo();
     }
-    Graph* createNewDS ( GraphDocument* arg1 ){
+    Graph* createNewDS ( GraphDocument* arg1 , const QString & pluginName ) {
+        if (!pluginName.isEmpty()) {
+            Rocs::DSPluginInterface * plugin = m_plugins.value(pluginName);
+            if (plugin) {
+                return plugin->createDS ( arg1 );
+            }
+        } else {
       if ( m_actualPlugin ) {
           return m_actualPlugin->createDS ( arg1 );
       }
+        }
       return 0;
     }
     QStringList listOfDS(){
-      return plugins.keys();
+        return m_plugins.keys();
     }
     QList < DSPluginInterface*> pluginList(){
-      return plugins.values();
+        return m_plugins.values();
     }
     QString actualPluginName(){
        return m_actualPlugin->name();
     }
+    Rocs::DSPluginInterface* plugin(const QString &pluginName) {
 
+        Rocs::DSPluginInterface * plugin = m_plugins.value(pluginName);
+        if (plugin)
+            return plugin;
+        return 0;
+//         foreach (Rocs::DSPluginInterface * plugin, plugins.values()) {
+//             kDebug() << plugin->name();
+//             if (plugin->name() == pluginName) {
+//                 return plugin;
+//             }
+//             return 0;
+//         }
+    }
+    void setActivePlugin(const QString &pluginName) {
+        if (Rocs::DSPluginInterface * plg = plugin(pluginName)) {
+            m_actualPlugin = plg;
+        }
+    }
+
 private:
 
     typedef KPluginInfo::List KPluginList;
     KPluginList m_DSPluginsInfo;
 
-    QHash<QString, DSPluginInterface*> plugins;
+    QHash<QString, DSPluginInterface*> m_plugins;
     DSPluginInterface * m_actualPlugin;
     QObject* m_parent;
 
@@ -86,7 +114,7 @@
             QString error;
             DSPluginInterface * plugin = \
KServiceTypeTrader::createInstanceFromQuery<DSPluginInterface> ( QString::fromLatin1 \
( "Rocs/DSPlugin" ), QString::fromLatin1 ( "[Name]=='%1'" ).arg ( pluginInfo.name() \
), m_parent, QVariantList(), &error );  if ( plugin ) {
-                plugins.insert ( pluginInfo.name(), plugin );
+                m_plugins.insert ( pluginInfo.name(), plugin );
                 pluginInfo.setPluginEnabled ( true );
                 return true;
             } else {
@@ -127,9 +155,24 @@
 }
 
 
-void Rocs::DSPluginManager::changeDS ( QString &newDS ) {
+void Rocs::DSPluginManager::changeActiveDS()
+{
+    QAction *action = qobject_cast<QAction *> ( sender() );
+
+    if (! action ) {
+        return;
+    }
+    changeActiveDS ( \
Rocs::DSPluginManager::New()->pluginsList().at(action->data().toInt() )->name() ); +
+}
+
+
+void Rocs::DSPluginManager::changeActiveDS (const QString &newDS ) {
     if ( listOfDS().contains ( newDS ) ) {
         emit changingDS ( newDS );
+        kDebug() << newDS << _d->actualPluginName();
+        _d->setActivePlugin(newDS);
+        kDebug() << newDS << _d->actualPluginName();
         emit DSChangedTo ( newDS );
         return;
     }
@@ -141,8 +184,8 @@
 
 }
 
-Graph* Rocs::DSPluginManager::createNewDS ( GraphDocument* parent ) {
-    return New()->_d->createNewDS(parent);
+Graph* Rocs::DSPluginManager::createNewDS ( GraphDocument* parent , const QString & \
pluginName) { +    return New()->_d->createNewDS(parent, pluginName);
 
 }
 
--- trunk/KDE/kdeedu/rocs/src/Core/DSPluginManager.h #1157721:1157722
@@ -40,7 +40,7 @@
     static DSPluginManager * New();
 
     /** build a new graph using actual data structure. */
-    static Graph * createNewDS(GraphDocument * parent = 0);
+    static Graph * createNewDS(GraphDocument* parent, const QString& pluginName = \
QString());  
     /** When the DS pluin  is changed, all the existent graphs must be 'rebuild' \
with the new DS. If is not possible to change to a new data structure without losing \
data, then user should be asked to continue or nor. If user say to not continue, all \
ready done job should be undo.*/  static Graph * changeToDS(Graph*);
@@ -65,7 +65,8 @@
 
   public slots:
       /** used to set change the data structure. */
-    void changeDS( QString& newDS);
+    void changeActiveDS();
+    void changeActiveDS( const QString& newDS);
     QString actualPlugin() const;
 
   private:
--- trunk/KDE/kdeedu/rocs/src/Core/graphDocument.cpp #1157721:1157722
@@ -39,6 +39,7 @@
     _height = height;
     _modified = false;
     _saved = false;
+    _DSType = Rocs::DSPluginManager::New()->actualPlugin();
 }
 
 GraphDocument::GraphDocument(const GraphDocument& gd)
@@ -47,7 +48,7 @@
     _name = gd.name();
     _width = gd.width();
     _height = gd.height();
-
+    _DSType = gd._DSType;
     foreach (Graph *g, gd) {
         append(g);
     }
@@ -111,7 +112,8 @@
 
 Graph* GraphDocument::addGraph(QString name) {
 
-  Graph *g = Rocs::DSPluginManager::New()->createNewDS(this);
+
+  Graph *g = Rocs::DSPluginManager::New()->createNewDS(this, _DSType);
 //     Graph *g = new Graph(this);
     g->setName(name);
     append(g);
--- trunk/KDE/kdeedu/rocs/src/Core/graphDocument.h #1157721:1157722
@@ -127,6 +127,7 @@
     bool _modified;
     bool _saved;
     Graph *_activeGraph;
+    QString _DSType;
 };
 
 #endif
--- trunk/KDE/kdeedu/rocs/src/Interface/MainWindow.cpp #1157721:1157722
@@ -362,7 +362,7 @@
           action->setChecked(true);
         }
         action->setActionGroup(group);
-        connect ( action, SIGNAL ( triggered ( bool ) ),this, SLOT ( changeDS() ) );
+        connect ( action, SIGNAL ( triggered ( bool ) \
),Rocs::DSPluginManager::New(), SLOT ( changeActiveDS()) );  pluginList.append ( \
action );  }
     plugActionList ( "DS_plugins", pluginList );
@@ -564,6 +564,7 @@
       return;
     }
     Rocs::DSPluginInterface *plugin = \
Rocs::DSPluginManager::New()->pluginsList().at(action->data().toInt() ); +
     kDebug() << "Changed " << plugin->name();
 }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic