• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • libs
  • kasten
  • controllers
  • io
  • export
exportcontroller.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Kasten Framework, made within the KDE community.
3 
4  Copyright 2008,2011 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 
24 #include "exportcontroller.h"
25 
26 // lib
27 #include "exportdialog.h"
28 // Kasten gui
29 #include <modelcodecviewmanager.h>
30 #include <dataselectable.h>
31 #include <abstractmodelexporterconfigeditor.h>
32 // Kasten core
33 #include <modelcodecmanager.h>
34 #include <abstractdocument.h>
35 #include <abstractmodelexporter.h>
36 // KDE
37 #include <KXMLGUIClient>
38 #include <KXMLGUIFactory>
39 #include <KActionCollection>
40 #include <KLocale>
41 #include <KSelectAction>
42 
43 
44 Q_DECLARE_METATYPE( Kasten2::AbstractModelExporter* )
45 
46 namespace Kasten2
47 {
48 
49 ExportController::ExportController( ModelCodecViewManager* modelCodecViewManager,
50  ModelCodecManager* modelCodecManager,
51  KXMLGUIClient* guiClient )
52  : AbstractXmlGuiController(),
53  mModelCodecViewManager( modelCodecViewManager ),
54  mModelCodecManager( modelCodecManager ),
55  mModel( 0 )
56 {
57  KActionCollection* actionCollection = guiClient->actionCollection();
58 
59  mExportSelectAction = actionCollection->add<KSelectAction>( QLatin1String("export") );
60  mExportSelectAction->setText( i18nc("@title:menu","Export") );
61  mExportSelectAction->setIcon( KIcon( QLatin1String("document-export") ) );
62  mExportSelectAction->setToolBarMode( KSelectAction::MenuMode );
63  connect( mExportSelectAction, SIGNAL(triggered(QAction*)), SLOT(onActionTriggered(QAction*)) );
64 
65  setTargetModel( 0 );
66 }
67 
68 void ExportController::setTargetModel( AbstractModel* model )
69 {
70  if( mModel ) mModel->disconnect( this );
71 
72  mModel = model ? model->findBaseModelWithInterface<If::DataSelectable*>() : 0;
73  mSelectionControl = mModel ? qobject_cast<If::DataSelectable *>( mModel ) : 0;
74 
75  if( mSelectionControl )
76  {
77  // TODO: only fill the list on menu call...
78  connect( mModel, SIGNAL(hasSelectedDataChanged(bool)), SLOT(updateActions()) );
79  }
80 
81  updateActions();
82 }
83 
84 
85 void ExportController::updateActions()
86 {
87  mExportSelectAction->removeAllActions();
88 
89  const AbstractModelSelection* selection = ( mSelectionControl != 0 ) ? mSelectionControl->modelSelection() : 0;
90 
91  const QList<AbstractModelExporter*> exporterList =
92  mModelCodecManager->exporterList( mModel, selection );
93  const bool hasExporters = ( exporterList.size() > 0 );
94 
95  if( hasExporters )
96  {
97  for( int c = 0; c < exporterList.size(); ++c )
98  {
99  AbstractModelExporter* exporter = exporterList.at( c );
100  const QString title = exporter->remoteTypeName();
101  QAction* action = new QAction( title, mExportSelectAction );
102 
103  action->setData( QVariant::fromValue(exporter) );
104  mExportSelectAction->addAction( action );
105  }
106  }
107  else
108  {
109  QAction* noneAction = new QAction( i18nc("@item There are no exporters.","Not available."), mExportSelectAction );
110  noneAction->setEnabled( false );
111  mExportSelectAction->addAction( noneAction );
112  }
113 
114  mExportSelectAction->setEnabled( mModel != 0 );
115 }
116 
117 void ExportController::onActionTriggered( QAction *action )
118 {
119  AbstractModelExporter* exporter = action->data().value<AbstractModelExporter* >();
120 
121  const AbstractModelSelection* selection = ( mSelectionControl != 0 ) ? mSelectionControl->modelSelection() : 0;
122 
123  AbstractModelExporterConfigEditor* configEditor =
124  mModelCodecViewManager->createConfigEditor( exporter );
125 
126  if( configEditor )
127  {
128  ExportDialog* dialog = new ExportDialog( exporter->remoteTypeName(), configEditor );
129  dialog->setData( mModel, selection );
130  if( !dialog->exec() )
131  return;
132  }
133 
134  mModelCodecManager->exportDocument( exporter, mModel, selection );
135 }
136 
137 }
Kasten2::If::DataSelectable::modelSelection
virtual const AbstractModelSelection * modelSelection() const =0
abstractdocument.h
modelcodecmanager.h
Kasten2::ModelCodecManager::exporterList
QList< AbstractModelExporter * > exporterList(AbstractModel *model, const AbstractModelSelection *selection) const
Definition: modelcodecmanager.cpp:64
Kasten2::AbstractModel::findBaseModelWithInterface
AbstractModel * findBaseModelWithInterface() const
returns the first baseModel which is of type T, or null if none is found.
Definition: abstractmodel.h:109
exportcontroller.h
exportdialog.h
Kasten2::ModelCodecManager::exportDocument
void exportDocument(AbstractModelExporter *exporter, AbstractModel *model, const AbstractModelSelection *selection)
Definition: modelcodecmanager.cpp:107
Kasten2::ExportController::setTargetModel
virtual void setTargetModel(AbstractModel *model)
Definition: exportcontroller.cpp:68
Kasten2::AbstractModelExporter::remoteTypeName
QString remoteTypeName() const
Definition: abstractmodelexporter.cpp:40
Kasten2::AbstractModelSelection
Definition: abstractmodelselection.h:35
Kasten2::If::DataSelectable
Definition: dataselectable.h:42
Kasten2::ModelCodecViewManager::createConfigEditor
AbstractModelStreamEncoderConfigEditor * createConfigEditor(AbstractModelStreamEncoder *encoder) const
Definition: modelcodecviewmanager.cpp:67
abstractmodelexporterconfigeditor.h
Kasten2::ModelCodecViewManager
Definition: modelcodecviewmanager.h:50
abstractmodelexporter.h
Kasten2::AbstractModel
Definition: abstractmodel.h:40
dataselectable.h
modelcodecviewmanager.h
Kasten2::ModelCodecManager
Definition: modelcodecmanager.h:48
Kasten2::AbstractModelExporter
Definition: abstractmodelexporter.h:45
QList
Definition: bookmarkable.h:29
Kasten2::AbstractXmlGuiController
Definition: abstractxmlguicontroller.h:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal