Qt-interest Archive, April 2007
Modifying spreadsheets
Pages: Prev | 1 | 2 | Next
Message 16 in thread
"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
news:BAY115-F23CEE3A5CA4AAE52ABBCA5DD5D0@xxxxxxxxxx
> Could you explain what you mean by fix?
>
> setHorizontalHeaderLabels(QStringList() << "Name" << "Surname" <<
> "Handicap");
So this is line 49? This code compiles for me when I call it with
a pointer to a QTableWidget. You are deriving your class from a
QTableWidget
so you should not need the pointer and this should compile.
Try doing it this way:
QStringList Label;
Label << "Name";
Label << "Surname";
Label << "Handicap";
setHorizontalHeaderLabels(Label);
What line has the error now? (Please show the
line and not the line number <g>)
--
[ signature omitted ]
Message 17 in thread
Same error now, but on line 52:
setHorizontalHeaderLabels(Label);
>From: "Duane Hebert" <spoo@xxxxxxxxx>
>To: qt-interest@xxxxxxxxxxxxx
>Subject: Re: Re: Re: Re: Re: Modifying spreadsheets
>Date: Fri, 13 Apr 2007 16:45:28 -0400
>
>
>"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
>news:BAY115-F23CEE3A5CA4AAE52ABBCA5DD5D0@xxxxxxxxxx
> > Could you explain what you mean by fix?
> >
> > setHorizontalHeaderLabels(QStringList() << "Name" << "Surname" <<
> > "Handicap");
>
>So this is line 49? This code compiles for me when I call it with
>a pointer to a QTableWidget. You are deriving your class from a
>QTableWidget
>so you should not need the pointer and this should compile.
>
>Try doing it this way:
>
>QStringList Label;
>Label << "Name";
>Label << "Surname";
>Label << "Handicap";
>setHorizontalHeaderLabels(Label);
>
>What line has the error now? (Please show the
>line and not the line number <g>)
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
_________________________________________________________________
Get Hotmail, News, Sport and Entertainment from MSN on your mobile.
http://www.msn.txt4content.com/
--
[ signature omitted ]
Message 18 in thread
"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
news:BAY115-F3597CD370FBC6BD56B2DC9DD5D0@xxxxxxxxxx
>
> Same error now, but on line 52:
>
> setHorizontalHeaderLabels(Label);
The online help for version 4.0 has this listed for QTableWidget:
void setHorizontalHeaderLabels ( const QStringList & labels )
so this function has existed since then. Also, the error that
you're getting (When compiling the updated code I get the error: no match
for call to
(QString) (QStringList&).) makes no sense in this context. How
have you included QString and QStringList ? should be
#include <QString>
#include <QStringList>
If that's the case, I have no ideas.
--
[ signature omitted ]
Message 19 in thread
That is how I have included the files.
>From: "Duane Hebert" <spoo@xxxxxxxxx>
>To: qt-interest@xxxxxxxxxxxxx
>Subject: Re: Re: Re: Re: Re: Re: Modifying spreadsheets
>Date: Fri, 13 Apr 2007 16:57:01 -0400
>
>
>"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
>news:BAY115-F3597CD370FBC6BD56B2DC9DD5D0@xxxxxxxxxx
> >
> > Same error now, but on line 52:
> >
> > setHorizontalHeaderLabels(Label);
>
>The online help for version 4.0 has this listed for QTableWidget:
>
>void setHorizontalHeaderLabels ( const QStringList & labels )
>
>so this function has existed since then. Also, the error that
>you're getting (When compiling the updated code I get the error: no match
>for call to
>(QString) (QStringList&).) makes no sense in this context. How
>have you included QString and QStringList ? should be
>#include <QString>
>#include <QStringList>
>
>If that's the case, I have no ideas.
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
_________________________________________________________________
Solve the Conspiracy and win fantastic prizes.
http://www.theconspiracygame.co.uk/
--
[ signature omitted ]
Message 20 in thread
"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
news:BAY115-F23519E30FF4906D5E5FF03DD5D0@xxxxxxxxxx
> That is how I have included the files.
I don't know then. Copy your current clear function completely and
post it here. Maybe there's still a typo somewhere...
--
[ signature omitted ]
Message 21 in thread
Ok. Here it is:
void Spreadsheet::clear()
{
setRowCount(0);
setColumnCount(0);
setRowCount(RowCount);
setColumnCount(ColumnCount);
QStringList Label;
Label << "Name";
Label << "Surname";
Label << "Handicap";
setHorizontalHeaderLabels(Label);
setCurrentCell(0, 0);
}
>From: "Duane Hebert" <spoo@xxxxxxxxx>
>To: qt-interest@xxxxxxxxxxxxx
>Subject: Re: Re: Re: Re: Re: Re: Re: Modifying spreadsheets
>Date: Fri, 13 Apr 2007 17:03:13 -0400
>
>
>"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
>news:BAY115-F23519E30FF4906D5E5FF03DD5D0@xxxxxxxxxx
> > That is how I have included the files.
>
>I don't know then. Copy your current clear function completely and
>post it here. Maybe there's still a typo somewhere...
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
_________________________________________________________________
Match.com - Click Here To Find Singles In Your Area Today!
http://msnuk.match.com/
--
[ signature omitted ]
Message 22 in thread
"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
news:BAY115-F23780C1C844995A23B987CDD5D0@xxxxxxxxxx
> Ok. Here it is:
>
> void Spreadsheet::clear()
> {
> setRowCount(0);
> setColumnCount(0);
> setRowCount(RowCount);
> setColumnCount(ColumnCount);
>
> QStringList Label;
> Label << "Name";
> Label << "Surname";
> Label << "Handicap";
> setHorizontalHeaderLabels(Label);
>
>
> setCurrentCell(0, 0);
> }
Don't know then. This looks fine as far as I can
see given that Spreadsheet is a class derived from
QTableWidget and you've included QStringList and
QString and QTableWidget. What platform are
you building on? Maybe it's a project error or something.
Maybe someone else has
an idea or try support@xxxxxxxxxxxxxx
--
[ signature omitted ]
Message 23 in thread
"Duane Hebert" <spoo@xxxxxxxxx> wrote in message
news:evorkt$36h$1@xxxxxxxxxxxxxxxxxxxxx
>
> "Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
> news:BAY115-F23780C1C844995A23B987CDD5D0@xxxxxxxxxx
> > Ok. Here it is:
> >
> > void Spreadsheet::clear()
> > {
> > setRowCount(0);
> > setColumnCount(0);
> > setRowCount(RowCount);
> > setColumnCount(ColumnCount);
> >
> > QStringList Label;
> > Label << "Name";
> > Label << "Surname";
> > Label << "Handicap";
> > setHorizontalHeaderLabels(Label);
> >
> >
> > setCurrentCell(0, 0);
> > }
>
> Don't know then. This looks fine as far as I can
> see given that Spreadsheet is a class derived from
> QTableWidget and you've included QStringList and
> QString and QTableWidget. What platform are
> you building on? Maybe it's a project error or something.
>
> Maybe someone else has
> an idea or try support@xxxxxxxxxxxxxx
There is one thing. QTableWidget::clear() is an
existing slot. Maybe it doesn't like you declaring a
public function with the same name. Try renaming this function
to something else like clearAll() or something.
Maybe the slot thing is confusing something.
--
[ signature omitted ]
Message 24 in thread
what do you mean by platform?
>From: "Duane Hebert" <spoo@xxxxxxxxx>
>To: qt-interest@xxxxxxxxxxxxx
>Subject: Re: Re: Re: Re: Re: Re: Re: Modifying spreadsheets
>Date: Fri, 13 Apr 2007 17:03:13 -0400
>
>
>"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
>news:BAY115-F23519E30FF4906D5E5FF03DD5D0@xxxxxxxxxx
> > That is how I have included the files.
>
>I don't know then. Copy your current clear function completely and
>post it here. Maybe there's still a typo somewhere...
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
_________________________________________________________________
Match.com - Click Here To Find Singles In Your Area Today!
http://msnuk.match.com/
--
[ signature omitted ]
Message 25 in thread
"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
news:BAY115-F235F26CA4E6FD6189AABF8DD5D0@xxxxxxxxxx
> what do you mean by platform?
Windows, Linux, Mac etc. Anyway,
if you've changed the function name and still
have the same problem, I don't have much
else to offer. Perhaps someone else sees something
that I'm missing.
Maybe you can try a small test app.
--
[ signature omitted ]
Message 26 in thread
The error is (in the header file spreadsheet.h):
you declare a function called QStringList...
QStringList(setHorizontalHeaderLabels);
obviously, this won't work...
HTH
Christoph
--
[ signature omitted ]
Message 27 in thread
"Christoph Duelli" <christoph.duelli@xxxxxx> wrote in message
news:evp0fm$5ts$1@xxxxxxxxxxxxxxxxxxxxx
> The error is (in the header file spreadsheet.h):
>
> you declare a function called QStringList...
> QStringList(setHorizontalHeaderLabels);
>
> obviously, this won't work...
> HTH
Yep. Missed that one. I also think the
clear() function should be renamed to avoid
problems the the slot clear().
--
[ signature omitted ]
Message 28 in thread
Interestingly, I have just compiled the program, and there were no errors.
However, when I ran the program, the horizontal headers said '1' '2' and '3'
rather than the labels I had set.
Does anyone out there have a sloution to this problem?
>From: "Marco Gallone" <polo75cake@xxxxxxxxxxx>
>To: qt-interest@xxxxxxxxxxxxx
>Subject: FW: Re: Re: Re: Re: Re: Re: Re: Modifying spreadsheets
>Date: Fri, 13 Apr 2007 21:15:12 +0000
>
>what do you mean by platform?
>
>
>>From: "Duane Hebert" <spoo@xxxxxxxxx>
>>To: qt-interest@xxxxxxxxxxxxx
>>Subject: Re: Re: Re: Re: Re: Re: Re: Modifying spreadsheets
>>Date: Fri, 13 Apr 2007 17:03:13 -0400
>>
>>
>>"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
>>news:BAY115-F23519E30FF4906D5E5FF03DD5D0@xxxxxxxxxx
>> > That is how I have included the files.
>>
>>I don't know then. Copy your current clear function completely and
>>post it here. Maybe there's still a typo somewhere...
>>
>>--
>>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>"unsubscribe" in the subject or the body.
>>List archive and information: http://lists.trolltech.com/qt-interest/
>>
>
>_________________________________________________________________
>Match.com - Click Here To Find Singles In Your Area Today!
>http://msnuk.match.com/
>
>--
>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>"unsubscribe" in the subject or the body.
>List archive and information: http://lists.trolltech.com/qt-interest/
>
_________________________________________________________________
Txt a lot? Get Messenger FREE on your mobile.
https://livemessenger.mobile.uk.msn.com/
#include <QtGui>
#include <QtGui>
#include <QString>
#include <QStringList>
#include "cell.h"
#include "spreadsheet.h"
Spreadsheet::Spreadsheet(QWidget *parent)
: QTableWidget(parent)
{
autoRecalc = true;
setItemPrototype(new Cell);
setSelectionMode(ContiguousSelection);
connect(this, SIGNAL(itemChanged(QTableWidgetItem *)),
this, SLOT(somethingChanged()));
clear();
}
QString Spreadsheet::currentLocation() const
{
return QChar('A' + currentColumn())
+ QString::number(currentRow() + 1);
}
QString Spreadsheet::currentFormula() const
{
return formula(currentRow(), currentColumn());
}
QTableWidgetSelectionRange Spreadsheet::selectedRange() const
{
QList<QTableWidgetSelectionRange> ranges = selectedRanges();
if (ranges.isEmpty())
return QTableWidgetSelectionRange();
return ranges.first();
}
void Spreadsheet::clear()
{
setRowCount(0);
setColumnCount(0);
setRowCount(RowCount);
setColumnCount(ColumnCount);
QStringList Label;
setHorizontalHeaderLabels(Label);
Label << "Name";
Label << "Surname";
Label << "Handicap";
setCurrentCell(0, 0);
}
bool Spreadsheet::readFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::warning(this, tr("Spreadsheet"),
tr("Cannot read file %1:\n%2.")
.arg(file.fileName())
.arg(file.errorString()));
return false;
}
QDataStream in(&file);
in.setVersion(QDataStream::Qt_4_1);
quint32 magic;
in >> magic;
if (magic != MagicNumber) {
QMessageBox::warning(this, tr("Spreadsheet"),
tr("The file is not a Spreadsheet file."));
return false;
}
clear();
quint16 row;
quint16 column;
QString str;
QApplication::setOverrideCursor(Qt::WaitCursor);
while (!in.atEnd()) {
in >> row >> column >> str;
setFormula(row, column, str);
}
QApplication::restoreOverrideCursor();
return true;
}
bool Spreadsheet::writeFile(const QString &fileName)
{
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::warning(this, tr("Spreadsheet"),
tr("Cannot write file %1:\n%2.")
.arg(file.fileName())
.arg(file.errorString()));
return false;
}
QDataStream out(&file);
out.setVersion(QDataStream::Qt_4_1);
out << quint32(MagicNumber);
QApplication::setOverrideCursor(Qt::WaitCursor);
for (int row = 0; row < RowCount; ++row) {
for (int column = 0; column < ColumnCount; ++column) {
QString str = formula(row, column);
if (!str.isEmpty())
out << quint16(row) << quint16(column) << str;
}
}
QApplication::restoreOverrideCursor();
return true;
}
void Spreadsheet::sort(const SpreadsheetCompare &compare)
{
QList<QStringList> rows;
QTableWidgetSelectionRange range = selectedRange();
int i;
for (i = 0; i < range.rowCount(); ++i) {
QStringList row;
for (int j = 0; j < range.columnCount(); ++j)
row.append(formula(range.topRow() + i,
range.leftColumn() + j));
rows.append(row);
}
qStableSort(rows.begin(), rows.end(), compare);
for (i = 0; i < range.rowCount(); ++i) {
for (int j = 0; j < range.columnCount(); ++j)
setFormula(range.topRow() + i, range.leftColumn() + j,
rows[i][j]);
}
clearSelection();
somethingChanged();
}
void Spreadsheet::cut()
{
copy();
del();
}
void Spreadsheet::copy()
{
QTableWidgetSelectionRange range = selectedRange();
QString str;
for (int i = 0; i < range.rowCount(); ++i) {
if (i > 0)
str += "\n";
for (int j = 0; j < range.columnCount(); ++j) {
if (j > 0)
str += "\t";
str += formula(range.topRow() + i, range.leftColumn() + j);
}
}
QApplication::clipboard()->setText(str);
}
void Spreadsheet::paste()
{
QTableWidgetSelectionRange range = selectedRange();
QString str = QApplication::clipboard()->text();
QStringList rows = str.split('\n');
int numRows = rows.count();
int numColumns = rows.first().count('\t') + 1;
if (range.rowCount() * range.columnCount() != 1
&& (range.rowCount() != numRows
|| range.columnCount() != numColumns)) {
QMessageBox::information(this, tr("Spreadsheet"),
tr("The information cannot be pasted because the copy "
"and paste areas aren't the same size."));
return;
}
for (int i = 0; i < numRows; ++i) {
QStringList columns = rows[i].split('\t');
for (int j = 0; j < numColumns; ++j) {
int row = range.topRow() + i;
int column = range.leftColumn() + j;
if (row < RowCount && column < ColumnCount)
setFormula(row, column, columns[j]);
}
}
somethingChanged();
}
void Spreadsheet::del()
{
foreach (QTableWidgetItem *item, selectedItems())
delete item;
}
void Spreadsheet::selectCurrentRow()
{
selectRow(currentRow());
}
void Spreadsheet::selectCurrentColumn()
{
selectColumn(currentColumn());
}
void Spreadsheet::recalculate()
{
for (int row = 0; row < RowCount; ++row) {
for (int column = 0; column < ColumnCount; ++column) {
if (cell(row, column))
cell(row, column)->setDirty();
}
}
viewport()->update();
}
void Spreadsheet::setAutoRecalculate(bool recalc)
{
autoRecalc = recalc;
if (autoRecalc)
recalculate();
}
void Spreadsheet::findNext(const QString &str, Qt::CaseSensitivity cs)
{
int row = currentRow();
int column = currentColumn() + 1;
while (row < RowCount) {
while (column < ColumnCount) {
if (text(row, column).contains(str, cs)) {
clearSelection();
setCurrentCell(row, column);
activateWindow();
return;
}
++column;
}
column = 0;
++row;
}
QApplication::beep();
}
void Spreadsheet::findPrevious(const QString &str,
Qt::CaseSensitivity cs)
{
int row = currentRow();
int column = currentColumn() - 1;
while (row >= 0) {
while (column >= 0) {
if (text(row, column).contains(str, cs)) {
clearSelection();
setCurrentCell(row, column);
activateWindow();
return;
}
--column;
}
column = ColumnCount - 1;
--row;
}
QApplication::beep();
}
void Spreadsheet::somethingChanged()
{
if (autoRecalc)
recalculate();
emit modified();
}
Cell *Spreadsheet::cell(int row, int column) const
{
return static_cast<Cell *>(item(row, column));
}
void Spreadsheet::setFormula(int row, int column,
const QString &formula)
{
Cell *c = cell(row, column);
if (!c) {
c = new Cell;
setItem(row, column, c);
}
c->setFormula(formula);
}
QString Spreadsheet::formula(int row, int column) const
{
Cell *c = cell(row, column);
if (c) {
return c->formula();
} else {
return "";
}
}
QString Spreadsheet::text(int row, int column) const
{
Cell *c = cell(row, column);
if (c) {
return c->text();
} else {
return "";
}
}
bool SpreadsheetCompare::operator()(const QStringList &row1,
const QStringList &row2) const
{
for (int i = 0; i < KeyCount; ++i) {
int column = keys[i];
if (column != -1) {
if (row1[column] != row2[column]) {
if (ascending[i]) {
return row1[column] < row2[column];
} else {
return row1[column] > row2[column];
}
}
}
}
return false;
}
#ifndef SPREADSHEET_H
#ifndef SPREADSHEET_H
#define SPREADSHEET_H
#include <QTableWidget>
class Cell;
class SpreadsheetCompare;
class Spreadsheet : public QTableWidget
{
Q_OBJECT
public:
Spreadsheet(QWidget *parent = 0);
bool autoRecalculate() const { return autoRecalc; }
QString currentLocation() const;
QString currentFormula() const;
QTableWidgetSelectionRange selectedRange() const;
void clear();
bool readFile(const QString &fileName);
bool writeFile(const QString &fileName);
void sort(const SpreadsheetCompare &compare);
public slots:
void cut();
void copy();
void paste();
void del();
void selectCurrentRow();
void selectCurrentColumn();
void recalculate();
void setAutoRecalculate(bool recalc);
void findNext(const QString &str, Qt::CaseSensitivity cs);
void findPrevious(const QString &str, Qt::CaseSensitivity cs);
signals:
void modified();
private slots:
void somethingChanged();
private:
enum { MagicNumber = 0x7F51C883, RowCount = 2000, ColumnCount = 3 };
Cell *cell(int row, int column) const;
QString text(int row, int column) const;
QString formula(int row, int column) const;
void setFormula(int row, int column, const QString &formula);
bool autoRecalc;
};
class SpreadsheetCompare
{
public:
bool operator()(const QStringList &row1,
const QStringList &row2) const;
enum { KeyCount = 3 };
int keys[KeyCount];
bool ascending[KeyCount];
};
#endif
Message 29 in thread
How about calling setHorizontalHeaderLabels after filling the list?
e.g
Label << "Name";
Label << "Surname";
Label << "Handicap";
setHorizontalHeaderLabels(Label);
"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
news:BAY115-F1511AD2ED59B9C5AD6170DD5C0@xxxxxxxxxx
> Interestingly, I have just compiled the program, and there were no errors.
> However, when I ran the program, the horizontal headers said '1' '2' and
> '3'
> rather than the labels I had set.
> Does anyone out there have a sloution to this problem?
>
>
>
>>From: "Marco Gallone" <polo75cake@xxxxxxxxxxx>
>>To: qt-interest@xxxxxxxxxxxxx
>>Subject: FW: Re: Re: Re: Re: Re: Re: Re: Modifying spreadsheets
>>Date: Fri, 13 Apr 2007 21:15:12 +0000
>>
>>what do you mean by platform?
>>
>>
>>>From: "Duane Hebert" <spoo@xxxxxxxxx>
>>>To: qt-interest@xxxxxxxxxxxxx
>>>Subject: Re: Re: Re: Re: Re: Re: Re: Modifying spreadsheets
>>>Date: Fri, 13 Apr 2007 17:03:13 -0400
>>>
>>>
>>>"Marco Gallone" <polo75cake@xxxxxxxxxxx> wrote in message
>>>news:BAY115-F23519E30FF4906D5E5FF03DD5D0@xxxxxxxxxx
>>> > That is how I have included the files.
>>>
>>>I don't know then. Copy your current clear function completely and
>>>post it here. Maybe there's still a typo somewhere...
>>>
>>>--
>>>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>>"unsubscribe" in the subject or the body.
>>>List archive and information: http://lists.trolltech.com/qt-interest/
>>>
>>
>>_________________________________________________________________
>>Match.com - Click Here To Find Singles In Your Area Today!
>>http://msnuk.match.com/
>>
>>--
>>To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
>>"unsubscribe" in the subject or the body.
>>List archive and information: http://lists.trolltech.com/qt-interest/
>>
>
> _________________________________________________________________
> Txt a lot? Get Messenger FREE on your mobile.
> https://livemessenger.mobile.uk.msn.com/
>
--
[ signature omitted ]