[opengtl-commits] [471] * add a docker to show compilation errors

[ Thread Index | Date Index | More lists.tuxfamily.org/opengtl-commits Archives ]


Revision: 471
Author:   cyrille
Date:     2008-11-09 23:37:06 +0100 (Sun, 09 Nov 2008)

Log Message:
-----------
* add a docker to show compilation errors
* add a docker to load images

Modified Paths:
--------------
    trunk/GTLDesigner/CMakeLists.txt
    trunk/GTLDesigner/src/CMakeLists.txt
    trunk/GTLDesigner/src/gtldesigner.cpp
    trunk/GTLDesigner/src/gtldesigner.h

Added Paths:
-----------
    trunk/GTLDesigner/cmake/modules/FindGTLImageIO.cmake
    trunk/GTLDesigner/src/ErrorMessagesModel.cpp
    trunk/GTLDesigner/src/ErrorMessagesModel.h
    trunk/GTLDesigner/src/ImagesDocker.ui

Property Changed:
----------------
    trunk/GTLDesigner/


Property changes on: trunk/GTLDesigner
___________________________________________________________________
Name: svn:ignore
   + build-debug
GTLDesigner.kdevelop
GTLDesigner.kdevelop.filelist
GTLDesigner.kdevelop.pcs
GTLDesigner.kdevses


Modified: trunk/GTLDesigner/CMakeLists.txt
===================================================================
--- trunk/GTLDesigner/CMakeLists.txt	2008-11-09 22:28:43 UTC (rev 470)
+++ trunk/GTLDesigner/CMakeLists.txt	2008-11-09 22:37:06 UTC (rev 471)
@@ -4,6 +4,7 @@
 
 find_package(OpenCTL REQUIRED)
 find_package(OpenShiva REQUIRED)
+find_package(GTLImageIO REQUIRED)
 find_package(KDE4 REQUIRED)
 include (KDE4Defaults)
 

Added: trunk/GTLDesigner/cmake/modules/FindGTLImageIO.cmake
===================================================================
--- trunk/GTLDesigner/cmake/modules/FindGTLImageIO.cmake	                        (rev 0)
+++ trunk/GTLDesigner/cmake/modules/FindGTLImageIO.cmake	2008-11-09 22:37:06 UTC (rev 471)
@@ -0,0 +1,36 @@
+     
+
+INCLUDE(UsePkgConfig)
+PKGCONFIG(GTLImageIO _GTLImageIOIncDir _GTLImageIOLinkDir _GTLImageIOLinkFlags _GTLImageIOCflags)
+
+set(GTLIMAGEIO_DEFINITIONS ${_GTLImageIOCflags})
+set(GTLIMAGEIO_LIBRARIES ${_GTLImageIOLinkFlags})
+set(GTLIMAGEIO_INCLUDE_DIR ${_GTLImageIOIncDir})
+
+if(GTLIMAGEIO_DEFINITIONS AND GTLIMAGEIO_LIBRARIES)
+
+  FIND_PROGRAM(PKGCONFIG_EXECUTABLE NAMES pkg-config PATHS /usr/bin/ /usr/local/bin )
+
+  # query pkg-config asking for GTLImageIO == 0.9.2
+  EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS --atleast-version=0.9.3 GTLImageIO RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
+
+  if(_return_VALUE STREQUAL "0")
+    set(GTLIMAGEIO_FOUND TRUE)
+    set(HAVE_GTLIMAGEIO TRUE)
+  else(_return_VALUE STREQUAL "0")
+    message(STATUS "GTLImageIO >= 0.9.6 was found")
+  endif(_return_VALUE STREQUAL "0")
+endif(GTLIMAGEIO_DEFINITIONS AND GTLIMAGEIO_LIBRARIES)
+
+if (GTLIMAGEIO_FOUND)
+    if (NOT GTLImageIO_FIND_QUIETLY)
+        message(STATUS "Found GTLIMAGEIO: ${GTLIMAGEIO_LIBRARIES}")
+    endif (NOT GTLImageIO_FIND_QUIETLY)
+else (GTLIMAGEIO_FOUND)
+    if (NOT GTLImageIO_FIND_QUIETLY)
+        message(STATUS "GTLImageIO was NOT found.")
+    endif (NOT GTLImageIO_FIND_QUIETLY)
+    if (GTLImageIO_FIND_REQUIRED)
+        message(FATAL_ERROR "Could NOT find GTLIMAGEIO")
+    endif (GTLImageIO_FIND_REQUIRED)
+endif (GTLIMAGEIO_FOUND)

Modified: trunk/GTLDesigner/src/CMakeLists.txt
===================================================================
--- trunk/GTLDesigner/src/CMakeLists.txt	2008-11-09 22:28:43 UTC (rev 470)
+++ trunk/GTLDesigner/src/CMakeLists.txt	2008-11-09 22:37:06 UTC (rev 471)
@@ -4,15 +4,16 @@
    gtldesigner.cpp
    ImageViewer.cpp
    main.cpp
+   ErrorMessagesModel.cpp
  )
 
-kde4_add_ui_files(gtldesigner_SRCS gtldesignerview_base.ui prefs_base.ui)
+kde4_add_ui_files(gtldesigner_SRCS gtldesignerview_base.ui prefs_base.ui ImagesDocker.ui)
 
 kde4_add_kcfg_files(gtldesigner_SRCS settings.kcfgc )
 
 kde4_add_executable(gtldesigner ${gtldesigner_SRCS})
 
-target_link_libraries(gtldesigner ${KDE4_KDEUI_LIBS} ${KDE4_KTEXTEDITOR_LIBS}  ${OPENSHIVA_LIBRARIES}  ${OPENCTL_LIBRARIES})
+target_link_libraries(gtldesigner ${KDE4_KDEUI_LIBS} ${KDE4_KTEXTEDITOR_LIBS}  ${OPENSHIVA_LIBRARIES}  ${OPENCTL_LIBRARIES} ${GTLIMAGEIO_LIBRARIES})
 
 install(TARGETS gtldesigner DESTINATION ${BIN_INSTALL_DIR} )
 

Added: trunk/GTLDesigner/src/ErrorMessagesModel.cpp
===================================================================
--- trunk/GTLDesigner/src/ErrorMessagesModel.cpp	                        (rev 0)
+++ trunk/GTLDesigner/src/ErrorMessagesModel.cpp	2008-11-09 22:37:06 UTC (rev 471)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either 
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public 
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>. */
+
+#include "ErrorMessagesModel.h"
+
+#include <vector>
+
+#include <KDebug>
+
+struct ErrorMessagesModel::Private
+{
+  std::vector<GTLCore::ErrorMessage> errorMessages;
+};
+
+ErrorMessagesModel::ErrorMessagesModel( const std::list<GTLCore::ErrorMessage>& _errorMessages) : d(new Private)
+{
+  d->errorMessages.insert( d->errorMessages.begin(), _errorMessages.begin(), _errorMessages.end() );
+}
+
+ErrorMessagesModel::~ErrorMessagesModel()
+{
+}
+
+QVariant ErrorMessagesModel::data( const QModelIndex & index, int role ) const
+{
+  if( index.isValid() )
+  {
+    switch( role )
+    {
+      case Qt::DisplayRole:
+          return QVariant( QString("%1: %2").arg( d->errorMessages[index.row()].line()).arg( d->errorMessages[index.row()].errorMessage().c_str()) );
+      case Qt::ForegroundRole:
+        return Qt::red;
+      case LineRole:
+        return QVariant( d->errorMessages[index.row()].line());
+    }
+  }
+  return QVariant();
+}
+
+int ErrorMessagesModel::rowCount ( const QModelIndex & parent ) const
+{
+  Q_UNUSED( parent );
+  return d->errorMessages.size();
+}


Property changes on: trunk/GTLDesigner/src/ErrorMessagesModel.cpp
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/GTLDesigner/src/ErrorMessagesModel.h
===================================================================
--- trunk/GTLDesigner/src/ErrorMessagesModel.h	                        (rev 0)
+++ trunk/GTLDesigner/src/ErrorMessagesModel.h	2008-11-09 22:37:06 UTC (rev 471)
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2008 Cyrille Berger <cberger@xxxxxxxxxxx>
+ * 
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either 
+ * version 2.1 of the License, or (at your option) any later version.
+ * 
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public 
+ * License along with this library.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef _ERROR_MESSAGES_MODEL_H_
+#define _ERROR_MESSAGES_MODEL_H_
+
+#include <QAbstractListModel>
+
+#include <GTLCore/ErrorMessage.h>
+
+class ErrorMessagesModel : public QAbstractListModel {
+  public:
+    enum Role {
+      LineRole = 100
+    };
+  public:
+    ErrorMessagesModel( const std::list<GTLCore::ErrorMessage>& );
+    ~ErrorMessagesModel();
+    virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
+    virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
+  private:
+    struct Private;
+    Private* const d;
+};
+
+#endif


Property changes on: trunk/GTLDesigner/src/ErrorMessagesModel.h
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/GTLDesigner/src/ImagesDocker.ui
===================================================================
--- trunk/GTLDesigner/src/ImagesDocker.ui	                        (rev 0)
+++ trunk/GTLDesigner/src/ImagesDocker.ui	2008-11-09 22:37:06 UTC (rev 471)
@@ -0,0 +1,54 @@
+<ui version="4.0" >
+ <class>ImagesDocker</class>
+ <widget class="QWidget" name="ImagesDocker" >
+  <property name="geometry" >
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <property name="windowTitle" >
+   <string>Form</string>
+  </property>
+  <layout class="QGridLayout" name="gridLayout" >
+   <item row="0" column="0" >
+    <widget class="QListWidget" name="listImages" />
+   </item>
+   <item row="1" column="0" >
+    <layout class="QHBoxLayout" name="horizontalLayout_2" >
+     <item>
+      <widget class="QPushButton" name="buttonAdd" >
+       <property name="text" >
+        <string>Add</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QPushButton" name="buttonRemove" >
+       <property name="text" >
+        <string>Remove</string>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <spacer name="horizontalSpacer_2" >
+       <property name="orientation" >
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeHint" stdset="0" >
+        <size>
+         <width>40</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>

Modified: trunk/GTLDesigner/src/gtldesigner.cpp
===================================================================
--- trunk/GTLDesigner/src/gtldesigner.cpp	2008-11-09 22:28:43 UTC (rev 470)
+++ trunk/GTLDesigner/src/gtldesigner.cpp	2008-11-09 22:37:06 UTC (rev 471)
@@ -19,9 +19,11 @@
 
 #include "QtGTL.h"
 
-#include <QtGui/QDropEvent>
-#include <QtGui/QPainter>
-#include <QtGui/QPrinter>
+#include <QDockWidget>
+#include <QListView>
+#include <QDropEvent>
+#include <QPainter>
+#include <QPrinter>
 
 #include <kconfigdialog.h>
 #include <kstatusbar.h>
@@ -39,11 +41,14 @@
 #include <ktexteditor/editor.h>
 #include <ktexteditor/editorchooser.h>
 #include <ktexteditor/configpage.h>
+#include <ktexteditor/cursor.h>
 
 #include <OpenShiva/Kernel.h>
 #include <GTLCore/Region.h>
+#include <GTLImageIO/ImageDCRegistry.h>
 
 #include "ImageViewer.h"
+#include "ErrorMessagesModel.h"
 
 GTLDesigner::GTLDesigner()
     : KXmlGuiWindow(),
@@ -69,6 +74,8 @@
 
     // add a status bar
     statusBar()->show();
+    
+    setupDockers();
 
     // a call to KXmlGuiWindow::setupGUI() populates the GUI
     // with actions, using KXMLGUI.
@@ -76,12 +83,39 @@
     // mainwindow to automatically save settings if changed: window size,
     // toolbar position, icon size, etc.
     setupGUI();
+    
 }
 
 GTLDesigner::~GTLDesigner()
 {
 }
 
+void GTLDesigner::setupDockers()
+{
+    QDockWidget* errorMessagesDockWidget = new QDockWidget(i18n("Error messages"), this);
+    errorMessagesDockWidget->setObjectName( "ErrorMessagesDocker" );
+    m_listView = new QListView( errorMessagesDockWidget );
+    errorMessagesDockWidget->setWidget( m_listView );
+    connect( m_listView, SIGNAL(activated(const QModelIndex &)),
+             SLOT( errorLineActivated(const QModelIndex&)) );
+    connect( m_listView, SIGNAL(clicked(const QModelIndex &)),
+             SLOT( errorLineActivated(const QModelIndex&)) );
+    addDockWidget( Qt::BottomDockWidgetArea, errorMessagesDockWidget );
+    
+    QDockWidget* imagesDockerDockWidget = new QDockWidget(i18n("Images"), this);
+    imagesDockerDockWidget->setObjectName("ImagesDocker");
+    QWidget* imagesDockerWidget = new QWidget( imagesDockerDockWidget );
+    imagesDockerDockWidget->setWidget( imagesDockerWidget );
+    ui_imagesDocker = new Ui::ImagesDocker;
+    ui_imagesDocker->setupUi( imagesDockerWidget );
+    
+    connect(ui_imagesDocker->buttonAdd, SIGNAL(released()), SLOT(addImage()));
+    connect(ui_imagesDocker->buttonRemove, SIGNAL(released()), SLOT(removeImage()));
+    
+    addDockWidget( Qt::RightDockWidgetArea, imagesDockerDockWidget );
+    
+}
+
 void GTLDesigner::setupActions()
 {
     KStandardAction::openNew(this, SLOT(fileNew()), actionCollection());
@@ -129,7 +163,6 @@
 
 void GTLDesigner::fileSave()
 {
-  kDebug() << m_document->isModified();
   m_document->documentSave();
   updateCaption();
 }
@@ -159,7 +192,6 @@
 }
 void GTLDesigner::executeShiva()
 {
-  GTLCore::PixelDescription pixel( GTLCore::Type::Float, 3 );
   OpenShiva::Kernel p("", 4);
   p.setSource( m_document->text().toAscii ().data() );
   p.compile();
@@ -188,7 +220,7 @@
       delete *it;
     }*/
   } else {
-    QMessageBox::critical(this, tr("QtShiva"), tr("Compilation error: %1").arg( p.compilationErrorsMessage().c_str() ));
+    m_listView->setModel( new ErrorMessagesModel( p.compilationErrors() ) );
   }
 }
 
@@ -233,4 +265,26 @@
   setCaption( caption );
 }
 
+void GTLDesigner::errorLineActivated( const QModelIndex & index )
+{
+  int line = m_listView->model()->data( index, ErrorMessagesModel::LineRole ).toInt();
+  m_view->setCursorPosition( KTextEditor::Cursor( line - 1, 0 ) );
+  m_view->setFocus( Qt::ActiveWindowFocusReason );
+}
+
+void GTLDesigner::addImage()
+{
+  KUrl file = KFileDialog::getOpenFileName( KUrl(), GTLImageIO::ImageDCRegistry::instance()->decodableFilter().c_str(), this);
+  QString fileName = file.toLocalFile();
+  if (fileName.isEmpty()) return;
+  QListWidgetItem* lwi = new QListWidgetItem( QFileInfo(fileName).fileName() );
+  lwi->setData(Qt::UserRole, fileName );
+  ui_imagesDocker->listImages->addItem( lwi );
+}
+
+void GTLDesigner::removeImage()
+{
+  delete ui_imagesDocker->listImages->currentItem();
+}
+
 #include "gtldesigner.moc"

Modified: trunk/GTLDesigner/src/gtldesigner.h
===================================================================
--- trunk/GTLDesigner/src/gtldesigner.h	2008-11-09 22:28:43 UTC (rev 470)
+++ trunk/GTLDesigner/src/gtldesigner.h	2008-11-09 22:37:06 UTC (rev 471)
@@ -21,12 +21,15 @@
 #include <kxmlguiwindow.h>
 
 #include "ui_prefs_base.h"
+#include "ui_ImagesDocker.h"
 
 class GTLDesignerView;
 class QPrinter;
 class KToggleAction;
 class KUrl;
 class QImage;
+class QListView;
+class QModelIndex;
 
 namespace KTextEditor
 {
@@ -67,19 +70,26 @@
     void executeCTL();
     void executeShiva();
     void updateCaption();
+    
+    void addImage();
+    void removeImage();
+    
+    void errorLineActivated(const QModelIndex& index);
 private:
     void setupActions();
     void showImage(const QImage&);
-
+    void setupDockers();
   private:
     KTextEditor::View *m_view;
     KTextEditor::Document *m_document;
     
     Ui::prefs_base ui_prefs_base ;
+    Ui::ImagesDocker* ui_imagesDocker;
 
     QPrinter   *m_printer;
     KToggleAction *m_toolbarAction;
     KToggleAction *m_statusbarAction;
+    QListView* m_listView;
 };
 
 #endif // _GTLDESIGNER_H_


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/