~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to kspread/dialogs/kspread_dlg_formula.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2006-04-20 21:38:53 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060420213853-j5lxluqvymxt2zny
Tags: 1:1.5.0-0ubuntu2
UbuntuĀ uploadĀ 

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
   You should have received a copy of the GNU Library General Public License
22
22
   along with this library; see the file COPYING.LIB.  If not, write to
23
 
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24
 
   Boston, MA 02111-1307, USA.
 
23
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
24
 * Boston, MA 02110-1301, USA.
25
25
*/
26
26
 
27
27
#include <qtextbrowser.h>
34
34
#include "kspread_doc.h"
35
35
#include "kspread_locale.h"
36
36
#include "kspread_map.h"
37
 
#include "kspread_selection.h"
 
37
#include "selection.h"
 
38
#include "kspread_sheet.h"
38
39
#include "kspread_view.h"
39
 
#include "kspread_functions.h"
 
40
#include "functions.h"
40
41
 
41
42
#include <kapplication.h>
42
43
#include <kdebug.h>
50
51
#include <klineedit.h>
51
52
#include <qlayout.h>
52
53
 
53
 
KSpreadDlgFormula::KSpreadDlgFormula( KSpreadView* parent, const char* name,const QString& formulaName)
 
54
using namespace KSpread;
 
55
 
 
56
FormulaDialog::FormulaDialog( View* parent, const char* name,const QString& formulaName)
54
57
    : KDialogBase( parent, name,false,i18n("Function"), Ok|Cancel )
55
58
{
56
59
  setWFlags( Qt::WDestructiveClose );
59
62
    m_focus = 0;
60
63
    m_desc = 0;
61
64
 
62
 
    KSpreadCell* cell = m_pView->activeSheet()->cellAt( m_pView->canvasWidget()->markerColumn(),
 
65
    Cell* cell = m_pView->activeSheet()->cellAt( m_pView->canvasWidget()->markerColumn(),
63
66
                                                        m_pView->canvasWidget()->markerRow() );
64
67
     m_oldText=cell->text();
65
68
    // Make sure that there is a cell editor running.
66
69
    if ( !m_pView->canvasWidget()->editor() )
67
70
    {
68
 
        m_pView->canvasWidget()->createEditor( KSpreadCanvas::CellEditor );
 
71
        m_pView->canvasWidget()->createEditor( Canvas::CellEditor );
69
72
        if(cell->text().isEmpty())
70
73
          m_pView->canvasWidget()->editor()->setText( "=" );
71
74
        else
89
92
    grid1->addWidget( searchFunct, 0, 0 );
90
93
 
91
94
    typeFunction = new QComboBox(page);
92
 
    QStringList cats = KSpreadFunctionRepository::self()->groups();
 
95
    QStringList cats = FunctionRepository::self()->groups();
93
96
    cats.prepend( i18n("All") );
94
97
    typeFunction->insertStringList( cats  );
95
98
    grid1->addWidget( typeFunction, 1, 0 );
189
192
    connect( fiveElement,SIGNAL(textChanged ( const QString & )),
190
193
             this,SLOT(slotChangeText(const QString &)));
191
194
 
192
 
    connect( m_pView, SIGNAL( sig_chooseSelectionChanged( KSpreadSheet*, const QRect& ) ),
193
 
             this, SLOT( slotSelectionChanged( KSpreadSheet*, const QRect& ) ) );
 
195
    connect( m_pView->choice(), SIGNAL(changed(const Region&)),
 
196
             this, SLOT(slotSelectionChanged()));
194
197
 
195
198
    connect( m_browser, SIGNAL( linkClicked( const QString& ) ),
196
199
             this, SLOT( slotShowFunction( const QString& ) ) );
243
246
             this, SLOT( slotPressReturn() ) );
244
247
}
245
248
 
246
 
KSpreadDlgFormula::~KSpreadDlgFormula()
 
249
FormulaDialog::~FormulaDialog()
247
250
{
248
 
    kdDebug(36001)<<"KSpreadDlgFormula::~KSpreadDlgFormula() \n";
 
251
    kdDebug(36001)<<"FormulaDialog::~FormulaDialog() \n";
249
252
}
250
253
 
251
 
 
252
 
void KSpreadDlgFormula::slotPressReturn()
 
254
void FormulaDialog::slotPressReturn()
253
255
{
254
256
    //laurent 2001-07-07 desactivate this code
255
257
    //because kspread crash.
260
262
    */
261
263
}
262
264
 
263
 
void KSpreadDlgFormula::slotSearchText(const QString &_text)
 
265
void FormulaDialog::slotSearchText(const QString &_text)
264
266
{
265
267
    QString result = listFunct.makeCompletion( _text.upper() );
266
268
    if( !result.isNull() )
267
269
        functions->setCurrentItem( functions->index( functions->findItem( result ) ) );
268
270
}
269
271
 
270
 
bool KSpreadDlgFormula::eventFilter( QObject* obj, QEvent* ev )
 
272
bool FormulaDialog::eventFilter( QObject* obj, QEvent* ev )
271
273
{
272
274
    if ( obj == firstElement && ev->type() == QEvent::FocusIn )
273
275
        m_focus = firstElement;
288
290
    return FALSE;
289
291
}
290
292
 
291
 
void KSpreadDlgFormula::slotOk()
 
293
void FormulaDialog::slotOk()
292
294
{
293
295
    m_pView->doc()->emitBeginOperation( false );
294
296
 
296
298
    // Switch back to the old sheet
297
299
    if( m_pView->activeSheet()->sheetName() !=  m_sheetName )
298
300
    {
299
 
        KSpreadSheet *sheet=m_pView->doc()->map()->findSheet(m_sheetName);
 
301
        Sheet *sheet=m_pView->doc()->map()->findSheet(m_sheetName);
300
302
        if( sheet)
301
303
            m_pView->setActiveSheet(sheet);
302
304
    }
303
305
 
304
306
    // Revert the marker to its original position
305
 
    m_pView->selectionInfo()->setMarker( QPoint( m_column, m_row ),
306
 
                                         m_pView->activeSheet());
 
307
    m_pView->selectionInfo()->initialize( QPoint( m_column, m_row ) );
307
308
 
308
309
    // If there is still an editor then set the text.
309
310
    // Usually the editor is always in place.
324
325
    //  delete this;
325
326
}
326
327
 
327
 
void KSpreadDlgFormula::slotClose()
 
328
void FormulaDialog::slotClose()
328
329
{
329
330
    m_pView->doc()->emitBeginOperation( false );
330
331
 
333
334
    // Switch back to the old sheet
334
335
    if(m_pView->activeSheet()->sheetName() !=  m_sheetName )
335
336
    {
336
 
        KSpreadSheet *sheet=m_pView->doc()->map()->findSheet(m_sheetName);
 
337
        Sheet *sheet=m_pView->doc()->map()->findSheet(m_sheetName);
337
338
        if( !sheet )
338
339
            return;
339
340
        m_pView->setActiveSheet(sheet);
341
342
 
342
343
 
343
344
    // Revert the marker to its original position
344
 
    m_pView->selectionInfo()->setMarker( QPoint( m_column, m_row ),
345
 
                                         m_pView->activeSheet() );
 
345
    m_pView->selectionInfo()->initialize( QPoint( m_column, m_row ) );
346
346
 
347
347
    // If there is still an editor then reset the text.
348
348
    // Usually the editor is always in place.
360
360
    //delete this;
361
361
}
362
362
 
363
 
void KSpreadDlgFormula::slotSelectButton()
 
363
void FormulaDialog::slotSelectButton()
364
364
{
365
365
    if( functions->currentItem() != -1 )
366
366
    {
368
368
    }
369
369
}
370
370
 
371
 
void KSpreadDlgFormula::slotChangeText( const QString& )
 
371
void FormulaDialog::slotChangeText( const QString& )
372
372
{
373
373
    // Test the lock
374
374
    if( !refresh_result )
384
384
    result->setText( tmp );
385
385
}
386
386
 
387
 
QString KSpreadDlgFormula::createFormula()
 
387
QString FormulaDialog::createFormula()
388
388
{
389
389
    QString tmp( "" );
390
390
 
437
437
    return(tmp);
438
438
}
439
439
 
440
 
QString KSpreadDlgFormula::createParameter( const QString& _text, int param )
 
440
QString FormulaDialog::createParameter( const QString& _text, int param )
441
441
{
442
442
    if ( _text.isEmpty() )
443
443
        return QString( "" );
447
447
 
448
448
    QString text;
449
449
 
450
 
    KSpreadParameterType elementType = m_desc->param( param ).type();
 
450
    ParameterType elementType = m_desc->param( param ).type();
451
451
 
452
452
    switch( elementType )
453
453
    {
485
485
            }
486
486
            else
487
487
            {
488
 
                KSpreadPoint p = KSpreadPoint( _text, m_pView->doc()->map() );
489
 
                KSpreadRange r = KSpreadRange( _text, m_pView->doc()->map() );
 
488
                Point p = Point( _text, m_pView->doc()->map() );
 
489
                Range r = Range( _text, m_pView->doc()->map() );
490
490
 
491
491
                if( !p.isValid() && !r.isValid() )
492
492
                {
524
524
    return text;
525
525
}
526
526
 
527
 
static void showEntry( QLineEdit* edit, QLabel* label, KSpreadFunctionDescription* desc, int param )
 
527
static void showEntry( QLineEdit* edit, QLabel* label,
 
528
    FunctionDescription* desc, int param )
528
529
{
529
530
    edit->show();
530
531
    label->setText( desc->param( param ).helpText()+":" );
531
532
    label->show();
532
 
    KSpreadParameterType elementType = desc->param( param ).type();
 
533
    ParameterType elementType = desc->param( param ).type();
533
534
    KFloatValidator *validate=0L;
534
535
    switch( elementType )
535
536
    {
552
553
 
553
554
}
554
555
 
555
 
void KSpreadDlgFormula::slotDoubleClicked( QListBoxItem* item )
 
556
void FormulaDialog::slotDoubleClicked( QListBoxItem* item )
556
557
{
557
558
    if ( !item )
558
559
        return;
665
666
    slotChangeText( "" );
666
667
}
667
668
 
668
 
void KSpreadDlgFormula::slotSelected( const QString& function )
 
669
void FormulaDialog::slotSelected( const QString& function )
669
670
{
670
 
    KSpreadFunctionDescription* desc =
671
 
       KSpreadFunctionRepository::self()->functionInfo( function );
 
671
    FunctionDescription* desc =
 
672
        FunctionRepository::self()->functionInfo (function);
672
673
    if ( !desc )
673
674
    {
674
 
        m_browser->setText( "" );
675
 
        return;
 
675
      m_browser->setText (i18n ("Description is not available."));
 
676
      return;
676
677
    }
677
 
 
 
678
  
678
679
    if( functions->currentItem() !=- 1 )
679
680
        selectFunction->setEnabled( TRUE );
680
 
 
 
681
  
681
682
    // Lock
682
683
    refresh_result = false;
683
 
 
 
684
  
684
685
    m_funcName = function;
685
686
    m_desc = desc;
686
 
 
 
687
  
687
688
    // Set the help text
688
689
    m_browser->setText( m_desc->toQML() );
689
690
    m_browser->setContentsPos( 0, 0 );
690
 
 
 
691
  
691
692
    m_focus=0;
692
 
 
 
693
  
693
694
    m_tabwidget->setCurrentPage( 0 );
694
695
    m_tabwidget->setTabEnabled( m_input, FALSE );
695
 
 
 
696
  
696
697
    // Unlock
697
698
    refresh_result=true;
698
699
}
699
700
 
700
701
// from hyperlink in the "Related Function"
701
 
void KSpreadDlgFormula::slotShowFunction( const QString& function )
 
702
void FormulaDialog::slotShowFunction( const QString& function )
702
703
{
703
 
    KSpreadFunctionDescription* desc =
704
 
       KSpreadFunctionRepository::self()->functionInfo( function );
 
704
    FunctionDescription* desc =
 
705
       FunctionRepository::self()->functionInfo( function );
705
706
    if ( !desc ) return;
706
707
 
707
708
    // select the category
717
718
    slotSelected( function );
718
719
}
719
720
 
720
 
void KSpreadDlgFormula::slotSelectionChanged( KSpreadSheet* _sheet, const QRect& _selection )
 
721
void FormulaDialog::slotSelectionChanged()
721
722
{
722
723
    if ( !m_focus )
723
724
        return;
724
725
 
725
 
    if ( _selection.left() == 0 )
726
 
        return;
727
 
 
728
 
    if ( _selection.left() >= _selection.right() && _selection.top() >= _selection.bottom() )
729
 
    {
730
 
        int dx = _selection.right();
731
 
        int dy = _selection.bottom();
732
 
        QString tmp;
733
 
        tmp.setNum( dy );
734
 
        tmp = _sheet->sheetName() + "!" + KSpreadCell::columnName( dx ) + tmp;
735
 
        m_focus->setText( tmp );
736
 
    }
737
 
    else
738
 
    {
739
 
        QString area = util_rangeName( _sheet, _selection );
740
 
        m_focus->setText( area );
 
726
    if (m_pView->choice()->isValid())
 
727
    {
 
728
      QString area = m_pView->choice()->name();
 
729
      m_focus->setText( area );
741
730
    }
742
731
}
743
732
 
744
 
void KSpreadDlgFormula::slotActivated( const QString& category )
 
733
void FormulaDialog::slotActivated( const QString& category )
745
734
{
746
735
    QStringList lst;
747
736
    if ( category == i18n("All") )
748
 
        lst = KSpreadFunctionRepository::self()->functionNames();
 
737
      lst = FunctionRepository::self()->functionNames();
749
738
    else
750
 
        lst = KSpreadFunctionRepository::self()->functionNames( category );
 
739
      lst = FunctionRepository::self()->functionNames( category );
751
740
 
752
741
    kdDebug(36001)<<"category: "<<category<<" ("<<lst.count()<<"functions)" << endl;
753
742
 
765
754
    slotSelected( functions->text(0) );
766
755
}
767
756
 
768
 
void KSpreadDlgFormula::closeEvent ( QCloseEvent * e )
 
757
void FormulaDialog::closeEvent ( QCloseEvent * e )
769
758
{
770
759
  e->accept();
771
760
}