~ubuntu-branches/ubuntu/wily/tora/wily-proposed

« back to all changes in this revision

Viewing changes to src/toresultview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Meskes
  • Date: 2009-09-11 12:37:52 UTC
  • mfrom: (1.2.8 upstream) (3.3.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090911123752-qhu322xlclo2hpqu
Tags: 2.1.0-1
* New upstream version, the rebuild closes: #540046.
* Bumped Standards-Version to 3.8.3, no changes needed.
* New project homepage.
* Removed no longer needed 01_missing_includes.dpatch.
* Removed no longer used dh_desktop call.
* Added README.source file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include "toconf.h"
45
45
#include "tolistviewformatter.h"
46
46
#include "tolistviewformatterfactory.h"
47
 
#include "tolistviewformatteridentifier.h"
 
47
//#include "tolistviewformatteridentifier.h"
48
48
#include "tomain.h"
49
49
#include "tomemoeditor.h"
50
50
#include "toparamget.h"
51
51
#include "toresultview.h"
52
 
#include "tosearchreplace.h"
53
52
#include "tosql.h"
54
53
#include "totool.h"
55
54
#include "toresultlistformat.h"
 
55
#include "tosearchreplace.h"
 
56
 
 
57
#include <cstdio>
56
58
 
57
59
#include <qapplication.h>
58
60
#include <qclipboard.h>
75
77
#include <QAction>
76
78
#include <QMimeData>
77
79
#include <QColorGroup>
 
80
#include <QProgressDialog>
78
81
 
79
82
static int MaxColDisp;
80
83
static bool Gridlines;
467
470
                     false, false, false,
468
471
                     true, true, false)
469
472
{
470
 
    FirstSearch = false;
471
473
    setTreeStepSize(15);
472
474
    setSelectionMode(Extended);
473
475
    setAllColumnsShowFocus(true);
796
798
        Menu->addSeparator();
797
799
 
798
800
        copyAct = Menu->addAction(tr("&Copy field"));
799
 
        if (selectionMode() == Multi || selectionMode() == Extended)
800
 
        {
801
 
            copySelAct  = Menu->addAction(tr("Copy selection"));
802
 
            copyHeadAct = Menu->addAction(tr("Copy selection with header"));
803
 
        }
 
801
//        if (selectionMode() == Multi || selectionMode() == Extended)
 
802
//        {
 
803
//            copySelAct  = Menu->addAction(tr("Copy selection"));
 
804
//            copyHeadAct = Menu->addAction(tr("Copy selection with header"));
 
805
//        }
804
806
        copyTransAct = Menu->addAction(tr("Copy transposed"));
805
807
        if (selectionMode() == Multi || selectionMode() == Extended)
806
808
        {
844
846
        QClipboard *clip = qApp->clipboard();
845
847
        clip->setText(menuText());
846
848
    }
847
 
    else if (action == copySelAct)
 
849
    else if (action == copyFormatAct)
848
850
    {
849
851
        try
850
852
        {
851
 
            QString str = exportAsText(false, true);
 
853
            toResultListFormat exp(this, toResultListFormat::TypeCopy);
 
854
            if (!exp.exec())
 
855
                return;
 
856
            QString str = exportAsText(exp.exportSettings());
852
857
            if (!str.isNull())
853
858
            {
854
859
                QClipboard *clip = qApp->clipboard();
865
870
        setColumnAlignment(MenuColumn, Qt::AlignCenter);
866
871
    else if (action == rightAct)
867
872
        setColumnAlignment(MenuColumn, Qt::AlignRight);
868
 
    else if (action == copyHeadAct)
869
 
    {
870
 
        try
871
 
        {
872
 
            QString str = exportAsText(true, true);
873
 
            if (!str.isNull())
874
 
            {
875
 
                QClipboard *clip = qApp->clipboard();
876
 
                QMimeData drag;
877
 
                drag.setHtml(str);
878
 
                clip->setMimeData(&drag);
879
 
            }
880
 
        }
881
 
        TOCATCH;
882
 
    }
883
873
    else if (action == selectAllAct)
884
874
        selectAll(true);
885
875
//     else if(act ==
916
906
    toTreeWidget::focusInEvent(e);
917
907
}
918
908
 
919
 
bool toListView::searchNext(toSearchReplace *search)
 
909
bool toListView::searchNext(const QString & text)
920
910
{
921
911
    toTreeWidgetItem *item = currentItem();
922
912
 
923
 
    bool first = FirstSearch;
924
 
    FirstSearch = false;
925
 
 
926
 
    for (toTreeWidgetItem *next = NULL;item;item = next)
 
913
    bool first = true;
 
914
 
 
915
    bool cs = toMainWidget()->searchDialog()->caseSensitive();
 
916
    bool ww = toMainWidget()->searchDialog()->wholeWords();
 
917
    bool rx = toMainWidget()->searchDialog()->searchMode() == Search::SearchRegexp;
 
918
 
 
919
    QString realSearch(text);
 
920
    if (!cs)
 
921
        realSearch = realSearch.toUpper();
 
922
 
 
923
    for (toTreeWidgetItem *next = NULL; item; item = next)
927
924
    {
928
925
        if (!first)
929
926
            first = true;
931
928
        {
932
929
            for (int i = 0;i < columns();i++)
933
930
            {
934
 
                int pos = 0;
935
 
                int endPos = 0;
936
 
 
937
931
                toResultViewItem *resItem = dynamic_cast<toResultViewItem *>(item);
938
932
                toResultViewCheck *chkItem = dynamic_cast<toResultViewCheck *>(item);
939
933
                QString txt;
944
938
                else if (item)
945
939
                    txt = item->text(i);
946
940
 
947
 
                if (search->findString(item->text(0), pos, endPos))
 
941
                if (!cs)
 
942
                    txt = txt.toUpper();
 
943
 
 
944
                if (rx && txt.contains(QRegExp(text)))
 
945
                {
 
946
                    setCurrentItem(item);
 
947
                    return true;
 
948
                }
 
949
                else if ((ww && txt == realSearch) || (!ww && txt.contains(realSearch)))
948
950
                {
949
951
                    setCurrentItem(item);
950
952
                    return true;
971
973
    return false;
972
974
}
973
975
 
 
976
bool toListView::searchPrevious(const QString & text)
 
977
{
 
978
    // TODO/FIXME: real backward searching
 
979
    return searchNext(text);
 
980
}
 
981
 
974
982
toListView *toListView::copyTransposed(void)
975
983
{
976
984
    QMdiSubWindow * w = new QMdiSubWindow(toMainWidget()->workspace());
1035
1043
{
1036
1044
    try
1037
1045
    {
1038
 
        QString delimiter;
1039
 
        QString separator;
1040
 
        int type = exportType(separator, delimiter);
1041
 
 
1042
 
        QString nam;
1043
 
        switch (type)
1044
 
        {
1045
 
        case - 1:
 
1046
        toResultListFormat dia(this, toResultListFormat::TypeExport);
 
1047
        if (!dia.exec())
1046
1048
            return false;
1047
 
        default:
1048
 
            nam = "*.txt";
1049
 
            break;
1050
 
        case 2:
1051
 
            nam = "*.csv";
1052
 
            break;
1053
 
        case 3:
1054
 
            nam = "*.html";
1055
 
            break;
1056
 
        case 4:
1057
 
            nam = "*.sql";
1058
 
            break;
1059
 
        }
1060
 
 
1061
 
        QString filename = toSaveFilename(QString::null, nam, this);
 
1049
 
 
1050
        toExportSettings settings = dia.exportSettings();
 
1051
 
 
1052
        QString filename = toSaveFilename(QString::null, settings.extension, this);
1062
1053
        if (filename.isEmpty())
1063
1054
            return false;
1064
 
 
1065
 
        return toWriteFile(filename, exportAsText(true, false, type, separator, delimiter));
 
1055
        std::auto_ptr<toListViewFormatter> pFormatter(
 
1056
                toListViewFormatterFactory::Instance().CreateObject(settings.type));
 
1057
        return toWriteFile(filename, exportAsText(settings));
1066
1058
    }
1067
1059
    TOCATCH
1068
1060
    return false;
1070
1062
 
1071
1063
void toListView::addMenues(QMenu *) {}
1072
1064
 
1073
 
bool toListView::searchCanReplace(bool)
1074
 
{
1075
 
    return false;
1076
 
}
1077
 
 
1078
 
int toListView::exportType(QString &separator, QString &delimiter)
 
1065
#if 0
 
1066
int toListView::exportType(QString &separator, QString &delimiter,
 
1067
                           bool &includeHeader, bool &onlySelection)
1079
1068
{
1080
1069
    toResultListFormat format(this, NULL);
1081
1070
    if (!format.exec())
1082
1071
        return -1;
1083
1072
 
1084
 
    format.saveDefault();
1085
 
 
1086
1073
    separator = format.Separator->text();
1087
1074
    delimiter = format.Delimiter->text();
 
1075
    includeHeader = format.IncludeHeaders->isChecked();
 
1076
    onlySelection = format.OnlySelection->isChecked();
1088
1077
 
1089
1078
    return format.Format->currentIndex();
1090
1079
 
1091
1080
}
1092
 
 
1093
 
 
1094
 
QString toListView::exportAsText(bool tincludeHeader, bool tonlySelection, int type,
1095
 
                                 const QString &tsep, const QString &tdel)
 
1081
#endif
 
1082
 
 
1083
 
 
1084
QString toListView::exportAsText(toExportSettings settings)
1096
1085
{
 
1086
#if 0
1097
1087
    QString result;
1098
1088
 
1099
1089
    includeHeader = tincludeHeader;
1102
1092
    del = tdel;
1103
1093
 
1104
1094
    if (type < 0)
1105
 
        type = exportType(sep, del);
 
1095
        type = exportType(sep, del, includeHeader, onlySelection);
1106
1096
    if (type < 0)
1107
1097
        return QString::null;
1108
1098
 
1110
1100
    result =  pFormatter->getFormattedString(*this);
1111
1101
 
1112
1102
    return result;
 
1103
#endif
 
1104
    if (settings.requireSelection())
 
1105
        settings.selected = selectedIndexes();
 
1106
 
 
1107
    if (settings.rowsExport == toExportSettings::RowsAll)
 
1108
    {
 
1109
        QProgressDialog progress("Fetching All Data...", "Abort", 0, 2, this);
 
1110
        progress.setWindowModality(Qt::WindowModal);
 
1111
        while (model()->canFetchMore(currentIndex()))
 
1112
        {
 
1113
            if (progress.wasCanceled())
 
1114
                break;
 
1115
            model()->fetchMore(currentIndex());
 
1116
            progress.setValue(progress.value() == 0 ? 1 : 0);
 
1117
        }
 
1118
        progress.setValue(2);
 
1119
    }
 
1120
 
 
1121
    std::auto_ptr<toListViewFormatter> pFormatter(
 
1122
        toListViewFormatterFactory::Instance().CreateObject(settings.type));
 
1123
    return pFormatter->getFormattedString(settings, model());
1113
1124
}
1114
1125
 
1115
1126
void toListView::exportData(std::map<QString, QString> &ret, const QString &prefix)