pluginsubformods.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2007 by Fco. Javier M. C.                               *
00003  *   fcojavmc@todo-redes.com                                               *
00004  *                                                                         *
00005  *   Copyright (C) 2007 by Tomeu Borras Riera                              *
00006  *   tborras@conetxia.com                                                  *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00022  ***************************************************************************/
00023 
00024 #include <stdio.h>
00025 
00026 #include <QFile>
00027 #include <QTextStream>
00028 #include <QTranslator>
00029 #include <QTextCodec>
00030 #include <QLocale>
00031 
00032 #include "pluginsubformods.h"
00033 #include "funcaux.h"
00034 
00035 
00037 
00040 int entryPoint(QApplication *) {
00041     _depura("Punto de Entrada del plugin de Subformods\n", 0);
00043     QTranslator *traductor = new QTranslator(0);
00044     if (confpr->valor(CONF_TRADUCCION) == "locales") {
00045         traductor->load(QString("pluginsubformods_") + QLocale::system().name(),
00046                         confpr->valor(CONF_DIR_TRADUCCION).toAscii().constData());
00047     } else {
00048         QString archivo = "pluginsubformods_" + confpr->valor(CONF_TRADUCCION);
00049        traductor->load(archivo, confpr->valor(CONF_DIR_TRADUCCION).toAscii().constData());
00050     } // end if
00051     theApp->installTranslator(traductor);
00052     _depura("END Punto de Entrada del plugin de Subformods\n", 0);
00053     return 0;
00054 }
00055 
00056 
00058 
00061 myplugsubformods::myplugsubformods(SubForm3 *parent) : QObject(parent) {
00062     _depura("myplugsubformods::myplugsubformods", 0);
00063     _depura("END myplugsubformods::myplugsubformods", 0);
00064 }
00065 
00067 
00069 myplugsubformods::~myplugsubformods(){
00070     _depura("myplugsubformods::~myplugsubformods", 0);
00071     _depura("END myplugsubformods::~myplugsubformods", 0);
00072 }
00073 
00074 
00076 
00079 void myplugsubformods::s_pintaMenu(QMenu *menu) {
00080     _depura("myplugsubformods::s_pintaMenu", 0);
00081     menu->addSeparator();
00082     menu->addAction(tr("Exportar a hoja de calculo"));
00083     _depura("END myplugsubformods::s_pintaMenu", 0);
00084 }
00085 
00086 
00088 
00091 void myplugsubformods::s_trataMenu(QAction *action) {
00092     _depura("myplugsubformods::s_trataMenu", 0);
00093     if (action->text() == tr("Exportar a hoja de calculo")) {
00094         sacaods();
00095     } // end if
00096     _depura("END myplugsubformods::s_trataMenu", 0);
00097 }
00098 
00099 
00101 
00103 void myplugsubformods::sacaods() {
00104     _depura("myplugsubformods::sacaods", 0);
00105 
00106     QString archivod = confpr->valor ( CONF_DIR_USER ) + "listadoods.py";
00107     SubForm3 * subf = (SubForm3 *) parent();
00108 
00109 
00110     QString fitxersortidatxt = "";
00111 
00112     fitxersortidatxt += "#!/usr/bin/python\n";
00113     fitxersortidatxt += "# -*- coding: utf8 -*-\n";
00114     fitxersortidatxt += "\n";
00115     fitxersortidatxt += "import ooolib\n";
00116     fitxersortidatxt += "\n";
00117 
00118     fitxersortidatxt += "# Crea el documento\n";
00119     fitxersortidatxt += "doc = ooolib.Calc(\"Listado\")\n";
00120 
00121     int y = 1;
00122     int x = 1;
00123 
00125     for (int h = 0; h < subf->mui_listcolumnas->rowCount(); ++h) {
00126         if (subf->mui_listcolumnas->item(h, 0)->checkState() == Qt::Checked) {
00127 
00128             fitxersortidatxt += "# Fila "+ QString::number ( y ) +"\n";
00129 
00130             QString textocabecera = (subf->mui_listcolumnas->item(h, 2)->text());
00131             textocabecera.replace(QString("\n"), QString("\\n\\\n"));
00132 
00134             fitxersortidatxt += "doc.set_column_property(" + QString::number(x) + ", 'width', '" + QString::number((double) subf->mui_list->columnWidth(h) / 90) + "in')\n\n";
00135 
00136             fitxersortidatxt += "doc.set_cell_property('bold', True)\n";
00137             fitxersortidatxt += "doc.set_cell_value(" + QString::number(x++) + "," + QString::number(y) + ", 'string', '" + textocabecera + "')\n";
00138             fitxersortidatxt += "doc.set_cell_property('bold', False)\n";                       
00139         } // end if
00140     } // end for
00141 
00142     y += 1;
00143     x = 1;
00145     for (int h = 0; h < subf->mui_listcolumnas->rowCount(); ++h) {
00146         if (subf->mui_listcolumnas->item(h, 0)->checkState() == Qt::Checked) {
00147 
00148             fitxersortidatxt += "# Fila "+ QString::number ( y ) +"\n";
00149 
00150             QString textocabecera = (subf->mui_listcolumnas->item(h, 1)->text());
00151             //QString textocabecera = (subf->mui_listcolumnas->columnDBfieldName());
00152             textocabecera.replace(QString("\n"), QString("\\n\\\n"));
00153 
00154             fitxersortidatxt += "doc.set_cell_property('bold', True)\n";
00155             fitxersortidatxt += "doc.set_cell_value(" + QString::number(x++) + "," + QString::number(y) + ", 'string', '" + textocabecera + "')\n";
00156             fitxersortidatxt += "doc.set_cell_property('bold', False)\n";                       
00157         } // end if
00158     } // end for
00159 
00160     y += 1;
00161 
00162     bool resultconvdouble, resultconvinteger;
00163     double resultadodouble, resultadointeger;
00164 
00166     for (int i = 0; i < subf->mui_list->rowCount(); ++i) {
00167 
00168         int x = 1;
00169 
00170         for (int j = 0; j < subf->mui_listcolumnas->rowCount(); ++j) {
00171             if (subf->mui_listcolumnas->item(j, 0)->checkState() == Qt::Checked) {
00172                 fitxersortidatxt += "# Fila "+ QString::number ( y ) +"\n";
00173 
00174                 QString textocontenido = (subf->mui_list->item(i, j)->text());
00175 
00176 
00177                 //TODO: Mirar de mejorar el mecanismo de deteccion de tipo de dato.
00178                 
00181                 if (subf->mui_list->item(i, j)->textAlignment() == Qt::AlignRight) {
00183                     resultadodouble = textocontenido.toDouble(&resultconvdouble);
00185                     resultadointeger = textocontenido.toInt(&resultconvinteger);
00187                         //TODO:
00189                         //TODO:
00190                             
00191                     if (resultconvdouble)  {
00193                         fitxersortidatxt += "doc.set_cell_value(" + QString::number(x++) + "," + QString::number(y) + ", 'float' , '" + textocontenido + "')\n\n";
00194                     } else if (resultconvinteger) {
00196                         fitxersortidatxt += "doc.set_cell_value(" + QString::number(x++) + "," + QString::number(y) + ", 'float' , '" + textocontenido + "')\n\n";
00197                     } else {
00199                         textocontenido.replace(QString("\n"), QString("\\n\\\n"));
00200                         fitxersortidatxt += "doc.set_cell_value(" + QString::number(x++) + "," + QString::number(y) + ", 'string', '" + textocontenido + "')\n\n";
00201                     } // end if
00202                 } else {
00204                     textocontenido.replace(QString("\n"), QString("\\n\\\n"));
00205                     fitxersortidatxt += "doc.set_cell_value(" + QString::number(x++) + "," + QString::number(y) + ", 'string', '" + textocontenido + "')\n\n";
00206                 } // end if
00207 
00208             } // end if
00209         } // end forXMLProtect(subf->mui_list->item(i, j)->text())
00210 
00211         y++;
00212 
00213     } // end for
00214 
00215     fitxersortidatxt += "doc.save(\"listadoods.ods\")\n";
00216 
00217     QString cadena ="rm "+confpr->valor ( CONF_DIR_USER ) + "listadoods.ods";
00218     system ( cadena.toAscii() );
00219     cadena ="rm "+ archivod;
00220     system ( cadena.toAscii() );
00221 
00222     QFile file ( archivod );
00223     if ( file.open ( QIODevice::WriteOnly ) )  {
00224         QTextStream stream ( &file );
00225         stream.setCodec("UTF-8");
00226         stream << fitxersortidatxt;
00227         file.close();
00228     } // end if
00229 
00230     cadena= " cd "+confpr->valor ( CONF_DIR_USER ) +"; python "+archivod;
00231     system ( cadena.toAscii() );
00232     cadena = "oocalc "+confpr->valor ( CONF_DIR_USER ) + "listadoods.ods &";
00233     system ( cadena.toAscii() );
00234 
00235     _depura("END myplugsubformods::sacaods", 0);
00236 }
00237 
00238 
00240 
00244 int SubForm3_SubForm3_Post(SubForm3 *sub) {
00245     _depura("SubForm3_SubForm3_Post", 0);
00246     myplugsubformods *subformods = new myplugsubformods(sub);
00247     sub->QObject::connect(sub, SIGNAL(pintaMenu(QMenu *)), subformods, SLOT(s_pintaMenu(QMenu *)));
00248     sub->QObject::connect(sub, SIGNAL(trataMenu(QAction *)), subformods, SLOT(s_trataMenu(QAction *)));
00249     _depura("END SubForm3_SubForm3_Post", 0);
00250     return 0;
00251 }
00252 

Generated on Sat Dec 15 00:01:20 2007 for BulmaGes by  doxygen 1.5.1