summaryrefslogtreecommitdiff
authorthufir <thufir>2002-07-04 17:55:16 (UTC)
committer thufir <thufir>2002-07-04 17:55:16 (UTC)
commitf3eaec3a60e32af8abad6563df32499a096b7e70 (patch) (unidiff)
tree996220ef5b11b20c6482e21b2cdb928ce6a9c6c3
parent3fc06dce797f62393bab41f4ea520bdbeb31eb9f (diff)
downloadopie-f3eaec3a60e32af8abad6563df32499a096b7e70.zip
opie-f3eaec3a60e32af8abad6563df32499a096b7e70.tar.gz
opie-f3eaec3a60e32af8abad6563df32499a096b7e70.tar.bz2
fixed bugs
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-sheet/opie-sheet.control2
-rw-r--r--noncore/apps/opie-sheet/sortdlg.cpp10
2 files changed, 6 insertions, 6 deletions
diff --git a/noncore/apps/opie-sheet/opie-sheet.control b/noncore/apps/opie-sheet/opie-sheet.control
index f772247..38f9083 100644
--- a/noncore/apps/opie-sheet/opie-sheet.control
+++ b/noncore/apps/opie-sheet/opie-sheet.control
@@ -1,10 +1,10 @@
1Files: bin/sheetqt apps/Applications/opie-sheet.desktop help/html/sheetqt.html help/html/sheetqt/* pics/opie-sheet/sheetqt.png 1Files: bin/sheetqt apps/Applications/opie-sheet.desktop help/sheetqt.html help/sheetqt/* pics/opie-sheet/sheetqt.png
2Priority: optional 2Priority: optional
3Section: opie/applications 3Section: opie/applications
4Maintainer: Serdar Ozler <sozler@sitebest.com> 4Maintainer: Serdar Ozler <sozler@sitebest.com>
5Architecture: arm 5Architecture: arm
6Version: 1.0.1 6Version: 1.0.1
7Depends: opie-base ($QPE_VERSION) 7Depends: opie-base ($QPE_VERSION)
8License: Public Domain 8License: Public Domain
9Description: Opie Sheet 9Description: Opie Sheet
10 Spreadsheet software for Opie. 10 Spreadsheet software for Opie.
diff --git a/noncore/apps/opie-sheet/sortdlg.cpp b/noncore/apps/opie-sheet/sortdlg.cpp
index 4f18fd3..c60be0d 100644
--- a/noncore/apps/opie-sheet/sortdlg.cpp
+++ b/noncore/apps/opie-sheet/sortdlg.cpp
@@ -1,192 +1,192 @@
1/*************************************************************************** 1/***************************************************************************
2 * * 2 * *
3 * This program is free software; you can redistribute it and/or modify * 3 * This program is free software; you can redistribute it and/or modify *
4 * it under the terms of the GNU General Public License as published by * 4 * it under the terms of the GNU General Public License as published by *
5 * the Free Software Foundation; either version 2 of the License, or * 5 * the Free Software Foundation; either version 2 of the License, or *
6 * (at your option) any later version. * 6 * (at your option) any later version. *
7 * * 7 * *
8 ***************************************************************************/ 8 ***************************************************************************/
9 9
10/* 10/*
11 * Opie Sheet (formerly Sheet/Qt) 11 * Opie Sheet (formerly Sheet/Qt)
12 * by Serdar Ozler <sozler@sitebest.com> 12 * by Serdar Ozler <sozler@sitebest.com>
13 */ 13 */
14 14
15#include <qlabel.h> 15#include <qlabel.h>
16#include <qradiobutton.h> 16#include <qradiobutton.h>
17#include <qmessagebox.h> 17#include <qmessagebox.h>
18#include "sortdlg.h" 18#include "sortdlg.h"
19 19
20SortDialog::SortDialog(QWidget *parent=0) 20SortDialog::SortDialog(QWidget *parent=0)
21 :QDialog(parent, 0, TRUE) 21 :QDialog(parent, 0, TRUE)
22{ 22{
23 // Main widget 23 // Main widget
24 tabs=new QTabWidget(this); 24 tabs=new QTabWidget(this);
25 widgetSort=new QWidget(tabs); 25 widgetSort=new QWidget(tabs);
26 widgetOptions=new QWidget(tabs); 26 widgetOptions=new QWidget(tabs);
27 tabs->addTab(widgetSort, tr("&Sort")); 27 tabs->addTab(widgetSort, tr("&Sort"));
28 tabs->addTab(widgetOptions, tr("&Options")); 28 tabs->addTab(widgetOptions, tr("&Options"));
29 29
30 // Sort tab 30 // Sort tab
31 comboFieldA=createFieldCombo(tr("&Sort by"), 10); 31 comboFieldA=createFieldCombo(tr("&Sort by"), 10);
32 groupOrderA=createOrderButtons(10); 32 groupOrderA=createOrderButtons(10);
33 comboFieldB=createFieldCombo(tr("&Then by"), 90); 33 comboFieldB=createFieldCombo(tr("&Then by"), 90);
34 groupOrderB=createOrderButtons(90); 34 groupOrderB=createOrderButtons(90);
35 comboFieldC=createFieldCombo(tr("Then &by"), 170); 35 comboFieldC=createFieldCombo(tr("Then &by"), 170);
36 groupOrderC=createOrderButtons(170); 36 groupOrderC=createOrderButtons(170);
37 37
38 // Options tab 38 // Options tab
39 checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions); 39 checkCase=new QCheckBox(tr("&Case Sensitive"), widgetOptions);
40 checkCase->setGeometry(10, 10, 215, 20); 40 checkCase->setGeometry(10, 10, 215, 20);
41 checkCase->setChecked(TRUE); 41 checkCase->setChecked(TRUE);
42 42
43 groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions); 43 groupDirection=new QVButtonGroup(tr("&Direction"), widgetOptions);
44 groupDirection->setGeometry(10, 40, 215, 70); 44 groupDirection->setGeometry(10, 40, 215, 70);
45 QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection); 45 QRadioButton *radio=new QRadioButton(tr("&Top to bottom (rows)"), groupDirection);
46 radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection); 46 radio=new QRadioButton(tr("&Left to right (columns)"), groupDirection);
47 groupDirection->setButton(0); 47 groupDirection->setButton(0);
48 connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int))); 48 connect(groupDirection, SIGNAL(clicked(int)), this, SLOT(directionChanged(int)));
49 49
50 // Main widget 50 // Main widget
51 box=new QVBoxLayout(this); 51 box=new QVBoxLayout(this);
52 box->addWidget(tabs); 52 box->addWidget(tabs);
53 53
54 setCaption(tr("Sort")); 54 setCaption(tr("Sort"));
55} 55}
56 56
57SortDialog::~SortDialog() 57SortDialog::~SortDialog()
58{ 58{
59} 59}
60 60
61QComboBox *SortDialog::createFieldCombo(const QString &caption, int y) 61QComboBox *SortDialog::createFieldCombo(const QString &caption, int y)
62{ 62{
63 QLabel *label=new QLabel(caption, widgetSort); 63 QLabel *label=new QLabel(caption, widgetSort);
64 label->setGeometry(10, y+5, 215, 20); 64 label->setGeometry(10, y+5, 215, 20);
65 QComboBox *combo=new QComboBox(FALSE, widgetSort); 65 QComboBox *combo=new QComboBox(FALSE, widgetSort);
66 combo->setGeometry(10, y+35, 105, 20); 66 combo->setGeometry(10, y+35, 105, 20);
67 label->setBuddy(combo); 67 label->setBuddy(combo);
68 return combo; 68 return combo;
69} 69}
70 70
71QVButtonGroup *SortDialog::createOrderButtons(int y) 71QVButtonGroup *SortDialog::createOrderButtons(int y)
72{ 72{
73 QVButtonGroup *group=new QVButtonGroup(widgetSort); 73 QVButtonGroup *group=new QVButtonGroup(widgetSort);
74 group->setGeometry(125, y, 100, 60); 74 group->setGeometry(125, y, 100, 60);
75 QRadioButton *radio=new QRadioButton(tr("&Ascending"), group); 75 QRadioButton *radio=new QRadioButton(tr("&Ascending"), group);
76 radio=new QRadioButton(tr("&Descending"), group); 76 radio=new QRadioButton(tr("&Descending"), group);
77 group->setButton(0); 77 group->setButton(0);
78 return group; 78 return group;
79} 79}
80 80
81void SortDialog::directionChanged(int id) 81void SortDialog::directionChanged(int id)
82{ 82{
83 direction=id; 83 direction=id;
84 fillFieldCombo(comboFieldA); 84 fillFieldCombo(comboFieldA);
85 fillFieldCombo(comboFieldB); 85 fillFieldCombo(comboFieldB);
86 fillFieldCombo(comboFieldC); 86 fillFieldCombo(comboFieldC);
87} 87}
88 88
89void SortDialog::fillFieldCombo(QComboBox *combo) 89void SortDialog::fillFieldCombo(QComboBox *combo)
90{ 90{
91 combo->clear(); 91 combo->clear();
92 if (direction) 92 if (direction)
93 for (int row=row1; row<=row2; ++row) 93 for (int row=row1; row<=row2; ++row)
94 combo->insertItem("Row "+QString::number(row+1)); 94 combo->insertItem("Row "+QString::number(row+1));
95 else 95 else
96 for (int col=col1; col<=col2; ++col) 96 for (int col=col1; col<=col2; ++col)
97 combo->insertItem("Column "+Sheet::getHeaderString(col+1)); 97 combo->insertItem("Column "+Sheet::getHeaderString(col+1));
98} 98}
99 99
100int SortDialog::exec(Sheet *s) 100int SortDialog::exec(Sheet *s)
101{ 101{
102 sheet=s; 102 sheet=s;
103 sheet->getSelection(&row1, &col1, &row2, &col2); 103 sheet->getSelection(&row1, &col1, &row2, &col2);
104 104
105 direction=0; 105 direction=0;
106 fillFieldCombo(comboFieldA); 106 fillFieldCombo(comboFieldA);
107 fillFieldCombo(comboFieldB); 107 fillFieldCombo(comboFieldB);
108 fillFieldCombo(comboFieldC); 108 fillFieldCombo(comboFieldC);
109 109
110 if (row1==row2 && col1==col2) 110 if (row1==row2 && col1==col2)
111 { 111 {
112 QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!")); 112 QMessageBox::warning(this, tr("Error"), tr("One cell cannot be sorted!"));
113 return QDialog::Rejected; 113 return QDialog::Rejected;
114 } 114 }
115 if (QDialog::exec()==QDialog::Accepted) 115 if (QDialog::exec()==QDialog::Accepted)
116 { 116 {
117 QString field1S=comboFieldA->currentText(), field2S=comboFieldA->currentText(), field3S=comboFieldA->currentText(); 117 QString field1S=comboFieldA->currentText(), field2S=comboFieldB->currentText(), field3S=comboFieldC->currentText();
118 field1S=field1S.mid(field1S.find(' ')+1); 118 field1S=field1S.mid(field1S.find(' ')+1);
119 field2S=field2S.mid(field2S.find(' ')+1); 119 field2S=field2S.mid(field2S.find(' ')+1);
120 field3S=field3S.mid(field3S.find(' ')+1); 120 field3S=field3S.mid(field3S.find(' ')+1);
121 int field1, field2, field3; 121 int field1, field2, field3;
122 if (direction) 122 if (direction)
123 { 123 {
124 field1=field1S.toInt()-1; 124 field1=field1S.toInt()-1;
125 field2=field2S.toInt()-1; 125 field2=field2S.toInt()-1;
126 field3=field3S.toInt()-1; 126 field3=field3S.toInt()-1;
127 int i, j; 127 int i, j;
128 for (i=col2; i>=col1; --i) 128 for (i=col2; i>=col1; --i)
129 for (j=col1+1; j<=i; ++j) 129 for (j=col1+1; j<=i; ++j)
130 { 130 {
131 bool swap=FALSE; 131 bool swap=FALSE;
132 int compareResult=compareItems(s->item(field1, j-1), s->item(field1, j), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked()); 132 int compareResult=compareItems(s->item(field1, j-1), s->item(field1, j), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked());
133 if (compareResult>0) swap=TRUE; 133 if (compareResult>0) swap=TRUE;
134 else if (compareResult==0) 134 else if (compareResult==0)
135 { 135 {
136 compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked()); 136 compareResult=compareItems(s->item(field2, j-1), s->item(field2, j), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked());
137 if (compareResult>0) swap=TRUE; 137 if (compareResult>0) swap=TRUE;
138 else if (compareResult==0) 138 else if (compareResult==0)
139 { 139 {
140 compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked()); 140 compareResult=compareItems(s->item(field3, j-1), s->item(field3, j), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked());
141 if (compareResult>0) swap=TRUE; 141 if (compareResult>0) swap=TRUE;
142 } 142 }
143 } 143 }
144 if (swap) 144 if (swap)
145 for (int row=row1; row<=row2; ++row) 145 for (int row=row1; row<=row2; ++row)
146 s->swapCells(row, j-1, row, j); 146 s->swapCells(row, j-1, row, j);
147 } 147 }
148 } 148 }
149 else 149 else
150 { 150 {
151 field1=Sheet::getHeaderColumn(field1S)-1; 151 field1=Sheet::getHeaderColumn(field1S)-1;
152 field2=Sheet::getHeaderColumn(field2S)-1; 152 field2=Sheet::getHeaderColumn(field2S)-1;
153 field3=Sheet::getHeaderColumn(field3S)-1; 153 field3=Sheet::getHeaderColumn(field3S)-1;
154 int i, j; 154 int i, j;
155 for (i=row2; i>=row1; --i) 155 for (i=row2; i>=row1; --i)
156 for (j=row1+1; j<=i; ++j) 156 for (j=row1+1; j<=i; ++j)
157 { 157 {
158 bool swap=FALSE; 158 bool swap=FALSE;
159 int compareResult=compareItems(s->item(j-1, field1), s->item(j, field1), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked()); 159 int compareResult=compareItems(s->item(j-1, field1), s->item(j, field1), groupOrderA->id(groupOrderA->selected()), checkCase->isChecked());
160 if (compareResult>0) swap=TRUE; 160 if (compareResult>0) swap=TRUE;
161 else if (compareResult==0) 161 else if (compareResult==0)
162 { 162 {
163 compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderA->id(groupOrderB->selected()), checkCase->isChecked()); 163 compareResult=compareItems(s->item(j-1, field2), s->item(j, field2), groupOrderB->id(groupOrderB->selected()), checkCase->isChecked());
164 if (compareResult>0) swap=TRUE; 164 if (compareResult>0) swap=TRUE;
165 else if (compareResult==0) 165 else if (compareResult==0)
166 { 166 {
167 compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderA->id(groupOrderC->selected()), checkCase->isChecked()); 167 compareResult=compareItems(s->item(j-1, field3), s->item(j, field3), groupOrderC->id(groupOrderC->selected()), checkCase->isChecked());
168 if (compareResult>0) swap=TRUE; 168 if (compareResult>0) swap=TRUE;
169 } 169 }
170 } 170 }
171 if (swap) 171 if (swap)
172 for (int col=col1; col<=col2; ++col) 172 for (int col=col1; col<=col2; ++col)
173 s->swapCells(j-1, col, j, col); 173 s->swapCells(j-1, col, j, col);
174 } 174 }
175 } 175 }
176 return QDialog::Accepted; 176 return QDialog::Accepted;
177 } 177 }
178 return QDialog::Rejected; 178 return QDialog::Rejected;
179} 179}
180 180
181int SortDialog::compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE) 181int SortDialog::compareItems(QTableItem *item1, QTableItem *item2, int descending=0, bool caseSensitive=TRUE)
182{ 182{
183 int result=0; 183 int result=0;
184 if (item1) 184 if (item1)
185 { 185 {
186 if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper())); 186 if (item2) result=(caseSensitive ? item1->text().compare(item2->text()) : item1->text().upper().compare(item2->text().upper()));
187 else result=-1; 187 else result=-1;
188 } 188 }
189 else 189 else
190 if (item2) result=1; 190 if (item2) result=1;
191 return (descending ? -result : result); 191 return (descending ? -result : result);
192} 192}