[rkward-cvs] rkward/rkward/dataeditor editlabelsdialog.cpp,1.2,1.3 editlabelsdialog.h,1.1,1.2 twintablemember.cpp,1.16,1.17 twintablemember.h,1.14,1.15

Thomas Friedrichsmeier tfry at users.sourceforge.net
Thu Apr 6 19:40:48 UTC 2006


Update of /cvsroot/rkward/rkward/rkward/dataeditor
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3163

Modified Files:
	editlabelsdialog.cpp editlabelsdialog.h twintablemember.cpp 
	twintablemember.h 
Log Message:
Reworked EditLabelsDialog to use a table instead of a listview

Index: editlabelsdialog.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/editlabelsdialog.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** editlabelsdialog.h	21 Sep 2004 15:13:58 -0000	1.1
--- editlabelsdialog.h	6 Apr 2006 19:40:46 -0000	1.2
***************
*** 23,30 ****
  
  class RKVariable;
! class QListView;
! class QLineEdit;
! class QPushButton;
! class QListViewItem;
  
  /**
--- 23,49 ----
  
  class RKVariable;
! 
! #include "twintablemember.h"
! 
! /** special mini class provides the table in EditLabelsDialog
! 
! @author Thomas Friedrichsmeier
! */
! class LevelsTable : public TwinTableMember {
! public:
! 	LevelsTable (QWidget *parent, RObject::ValueLabels *labels);
! 	~LevelsTable ();
! /** reimplemented form QTable not to add trailing rows/cols if needed */
! 	QWidget *beginEdit (int row, int col, bool replace);
! /** reimplemented form QTable not to work on RObject::ValueLabels instead of QTableItems */
! 	void paintCell (QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg);
! /** reimplemented form QTable not to work on RObject::ValueLabels instead of QTableItems */
! 	void setText (int row, int col, const QString &text);
! /** reimplemented form QTable not to work on RObject::ValueLabels instead of QTableItems */
! 	QString text (int row, int col) const;
! private:
! friend class EditLabelsDialog;
! 	RObject::ValueLabels *storage;
! };
  
  /**
***************
*** 33,61 ****
  @author Thomas Friedrichsmeier
  */
- 
  class EditLabelsDialog : public QDialog {
! Q_OBJECT
  public:
  	EditLabelsDialog (QWidget *parent, RKVariable *var, int mode=0);
  
  	~EditLabelsDialog ();
- public slots:
- 	void addButtonClicked ();
- 	void removeButtonClicked ();
- 	void changeButtonClicked ();
- 	void listSelectionChanged (QListViewItem *item);
- 	void labelEditEnterPressed ();
  protected:
  /// reimplemented to submit the changes to the backend
  	void accept ();
  private:
! 	QListView *list;
  	RKVariable *var;
- 	RObject::ValueLabels *labels;
  	int mode;
- 	QPushButton *add_button;
- 	QPushButton *remove_button;
- 	QPushButton *change_button;
- 	QLineEdit *label_edit;
  };
  
--- 52,72 ----
  @author Thomas Friedrichsmeier
  */
  class EditLabelsDialog : public QDialog {
! 	Q_OBJECT
  public:
+ /** constuctor., the variable to work on.
+ @param parent a QWidget parent (usually 0)
+ @param var the variable/factor to set labels for
+ @param mode not yet used */
  	EditLabelsDialog (QWidget *parent, RKVariable *var, int mode=0);
  
  	~EditLabelsDialog ();
  protected:
  /// reimplemented to submit the changes to the backend
  	void accept ();
  private:
! 	LevelsTable *table;
  	RKVariable *var;
  	int mode;
  };
  

Index: twintablemember.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintablemember.cpp,v
retrieving revision 1.16
retrieving revision 1.17
diff -C2 -d -r1.16 -r1.17
*** twintablemember.cpp	2 Oct 2005 17:19:02 -0000	1.16
--- twintablemember.cpp	6 Apr 2006 19:40:46 -0000	1.17
***************
*** 45,53 ****
  }
  
! int TwinTableMember::numTrueCols () {
  	return numCols () - trailing_cols;
  }
  
! int TwinTableMember::numTrueRows () {
  	return QTable::numRows () - trailing_rows;
  }
--- 45,53 ----
  }
  
! int TwinTableMember::numTrueCols () const {
  	return numCols () - trailing_cols;
  }
  
! int TwinTableMember::numTrueRows () const {
  	return QTable::numRows () - trailing_rows;
  }

Index: twintablemember.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/twintablemember.h,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** twintablemember.h	21 Oct 2004 16:34:42 -0000	1.14
--- twintablemember.h	6 Apr 2006 19:40:46 -0000	1.15
***************
*** 49,55 ****
  	TwinTableMember *getTwin () { return twin; };
  /** like QTable::numRows (), but returns only the "true", i.e. active rows (excluding the trailing_rows) */
! 	int numTrueRows ();
  /** like QTable::numCols (), but returns only the "true", i.e. active columns (excluding the trailing_cols) */
! 	int numTrueCols ();
  /** reimplemented form QTable not to use QTableItems. This one raises an assert (should never be called) */
  	void removeRows (const QMemArray<int> &rows);
--- 49,55 ----
  	TwinTableMember *getTwin () { return twin; };
  /** like QTable::numRows (), but returns only the "true", i.e. active rows (excluding the trailing_rows) */
! 	int numTrueRows () const;
  /** like QTable::numCols (), but returns only the "true", i.e. active columns (excluding the trailing_cols) */
! 	int numTrueCols () const;
  /** reimplemented form QTable not to use QTableItems. This one raises an assert (should never be called) */
  	void removeRows (const QMemArray<int> &rows);

Index: editlabelsdialog.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/dataeditor/editlabelsdialog.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** editlabelsdialog.cpp	17 Nov 2004 20:35:48 -0000	1.2
--- editlabelsdialog.cpp	6 Apr 2006 19:40:46 -0000	1.3
***************
*** 20,177 ****
  #include <kdialogbase.h>
  
- #include <qlistview.h>
  #include <qlabel.h>
  #include <qlayout.h>
  #include <qpushbutton.h>
! #include <qlineedit.h>
  
  #include "../core/rkvariable.h"
  
  #include "../debug.h"
  
! EditLabelsDialog::EditLabelsDialog (QWidget *parent, RKVariable *var, int mode) : QDialog (parent) {
  	RK_TRACE (EDITOR);
- 	RK_ASSERT (var);
- 	RK_ASSERT (var->objectOpened ());
- 	
- 	EditLabelsDialog::var = var;
- 	EditLabelsDialog::mode = mode;
  
! 	QVBoxLayout *mainvbox = new QVBoxLayout (this, KDialog::marginHint (), KDialog::spacingHint ());
! 	QLabel *label = new QLabel (i18n ("Levels can be assigned only to consecutive integers starting with 1. Warning: if you remove a level, the indices of the other levels may change, hence changing the values of the factor!"), this);
! 	label->setAlignment (Qt::AlignAuto | Qt::AlignVCenter | Qt::ExpandTabs | Qt::WordBreak);
! 	mainvbox->addWidget (label);
! 	
! 	QHBoxLayout *hbox = new QHBoxLayout (mainvbox, KDialog::spacingHint ());
! 	
! 	list = new QListView (this);
! 	list->addColumn (i18n ("Index"));
! 	list->addColumn (i18n ("Label"));
! 	list->setSorting (0);
! 	labels = var->getValueLabels ();
! 	if (labels) {
! 		int i=1;
! 		while (labels->contains (QString::number (i))) {
! 			new QListViewItem (list, QString::number (i), (*labels)[QString::number (i)]);
! 			++i;
! 		}
! 	} else {
! 		labels = new RObject::ValueLabels;
! 	}
! 	connect (list, SIGNAL (selectionChanged (QListViewItem *)), this, SLOT (listSelectionChanged (QListViewItem *)));
! 	hbox->addWidget (list);
  
! 	QVBoxLayout *buttonvbox = new QVBoxLayout (hbox, KDialog::spacingHint ());
! 	label_edit = new QLineEdit (this);
! 	connect (label_edit, SIGNAL (returnPressed ()), this, SLOT (labelEditEnterPressed ()));
! 	buttonvbox->addWidget (label_edit);
! 	
! 	add_button = new QPushButton (i18n ("Add"), this);
! 	connect (add_button, SIGNAL (clicked ()), this, SLOT (addButtonClicked ()));
! 	remove_button = new QPushButton (i18n ("Remove"), this);
! 	connect (remove_button, SIGNAL (clicked ()), this, SLOT (removeButtonClicked ()));
! 	remove_button->setEnabled (false);
! 	change_button = new QPushButton (i18n ("Change"), this);
! 	connect (change_button, SIGNAL (clicked ()), this, SLOT (changeButtonClicked ()));
! 	change_button->setEnabled (false);
! 	
! 	buttonvbox->addWidget (change_button);
! 	buttonvbox->addWidget (add_button);
! 	buttonvbox->addWidget (remove_button);
! 	
! 	QPushButton *ok_button = new QPushButton (i18n ("Ok"), this);
! 	connect (ok_button, SIGNAL (clicked ()), this, SLOT (accept ()));
! 	mainvbox->addWidget (ok_button);
! 	
! 	setCaption (i18n ("Levels / Value labels for '%1'").arg (var->getShortName ()));
  }
  
! EditLabelsDialog::~EditLabelsDialog () {
  	RK_TRACE (EDITOR);
  }
  
! void EditLabelsDialog::addButtonClicked () {
  	RK_TRACE (EDITOR);
! 	
! 	QString text = label_edit->text ();
  	if (text.isEmpty ()) {
! 		text = "NA";
  	}
- 	
- 	QString index = QString::number (list->childCount () + 1);
- 	new QListViewItem (list, index, text);
- 	labels->insert (index, text);
  }
  
! void EditLabelsDialog::removeButtonClicked () {
  	RK_TRACE (EDITOR);
  
! 	QListViewItem *item = list->currentItem ();
! 	if (!item) {
! 		RK_ASSERT (false);
! 		return;
  	}
  
! 	QString index = item->text (0);
! 	labels->remove (index);
  
! 	int ind = index.toInt ();
! 	RK_ASSERT ((ind >= 1) && (ind <= list->childCount ()));
! 	delete item;
  	
! 	index = QString::number (++ind);
! 	while (labels->contains (index)) {
! 		item = list->findItem (index, 0);
! 		RK_ASSERT (item);
! 		delete (item);
! 		labels->insert (QString::number (ind - 1), (*labels)[index]);
! 		labels->remove (index);
! 		index = QString::number (++ind);
  	}
  }
  
! void EditLabelsDialog::changeButtonClicked () {
  	RK_TRACE (EDITOR);
  
! 	QListViewItem *item = list->currentItem ();
! 	if (!item) {
! 		RK_ASSERT (false);
! 		return;
  	}
  	
! 	QString text = label_edit->text ();
! 	if (text.isEmpty ()) {
! 		text = "NA";
! 	}
  	
! 	item->setText (1, text);
! 	labels->insert (item->text (0), item->text (1));
  }
  
! void EditLabelsDialog::listSelectionChanged (QListViewItem *item) {
  	RK_TRACE (EDITOR);
  	
! 	if (item) {
! 		add_button->setEnabled (false);
! 		change_button->setEnabled (true);
! 		remove_button->setEnabled (true);
  
! 		label_edit->setText (item->text (1));
! 	} else {
! 		add_button->setEnabled (true);
! 		change_button->setEnabled (false);
! 		remove_button->setEnabled (false);
  	}
  }
  
! void EditLabelsDialog::labelEditEnterPressed () {
  	RK_TRACE (EDITOR);
- 
- 	QListViewItem *item = list->currentItem ();
- 	if (item) {
- 		changeButtonClicked ();
- 	} else {
- 		addButtonClicked ();
- 	}
  }
  
--- 20,195 ----
  #include <kdialogbase.h>
  
  #include <qlabel.h>
  #include <qlayout.h>
  #include <qpushbutton.h>
! #include <qpainter.h>
! #include <qrect.h>
! #include <qpalette.h>
! #include <qstyle.h>
  
  #include "../core/rkvariable.h"
+ #include "celleditor.h"
  
  #include "../debug.h"
  
! LevelsTable::LevelsTable (QWidget *parent, RObject::ValueLabels *labels) : TwinTableMember (parent, 0, 1, 0) {
  	RK_TRACE (EDITOR);
  
! 	RK_ASSERT (labels);
! 	storage = labels;
  
! 	setNumCols (2);
! 	verticalHeader ()->setLabel (0, i18n ("Index"));
! 	verticalHeader ()->setLabel (1, i18n ("Label"));
! 	setColumnReadOnly (0, true);
! 
! 	setNumRows (storage->count () + 1);
  }
  
! LevelsTable::~LevelsTable () {
  	RK_TRACE (EDITOR);
  }
  
! void LevelsTable::setText (int row, int col, const QString &text) {
  	RK_TRACE (EDITOR);
! 	RK_ASSERT (col == 1);
! 
! 	storage->insert (QString::number (row+1), text);
  	if (text.isEmpty ()) {
! 		int maxrow = numTrueRows ()-1;
! 		while ((maxrow >= 0) && LevelsTable::text (maxrow, 1).isEmpty ()) {
! 			storage->remove (QString::number (maxrow + 1));
! 			--maxrow;
! 		}
! 		setNumRows (maxrow + 2);
  	}
  }
  
! QString LevelsTable::text (int row, int col) const {
  	RK_TRACE (EDITOR);
+ 	RK_ASSERT (col == 1);
+ 	RK_ASSERT (row < numTrueRows ());
  
! 	return ((*storage)[QString::number (row+1)]);
! }
! 
! void LevelsTable::paintCell (QPainter *p, int row, int col, const QRect &cr, bool selected, const QColorGroup &cg) {
! 	// no trace for paint operations
! 
! 	// draw background
! 	QBrush brush = QBrush (Qt::red);
! 	if (selected) {
! 		brush = cg.brush(QColorGroup::Highlight);
! 	} else {
! 			brush = cg.brush (QColorGroup::Base);
! 	}
! 	if (row >= numTrueRows ()) {
! 		brush = QBrush (Qt::gray);
  	}
  
! 	p->fillRect(0, 0, cr.width(), cr.height(), brush);
  
! 	// draw grid
! 	QPen pen (p->pen ());
! 	int gridColor = style ().styleHint (QStyle::SH_Table_GridLineColor, this);
! 	if (gridColor != -1) {
! 		const QPalette &pal = palette ();
! 		if (cg != colorGroup () && cg != pal.disabled () && cg != pal.inactive ()) p->setPen (cg.mid ());
! 		else p->setPen ((QRgb) gridColor);
! 	} else {
! 		p->setPen (cg.mid ());
! 	}
! 	int x2 = cr.width () - 1;
! 	int y2 = cr.height () - 1;
! 	p->drawLine (x2, 0, x2, y2);
! 	p->drawLine (0, y2, x2, y2);
! 	p->setPen (pen);
! 
! 	if (tted && (currEditRow () == row) && (currEditCol () == col)) {
! 		tted->raise ();
! 		return;
! 	}
  	
! 	// draw text
! 	if (selected) {
! 		p->setPen (cg.highlightedText());
! 	} else {
! 		p->setPen (cg.text ());
  	}
+ 
+ 	QString dummy;
+ 	if (row < numTrueRows ()) {
+ 		if (!col) {
+ 			dummy.setNum (row +1);
+ 		} else {
+ 			dummy = (*storage)[QString::number (row+1)];
+ 		}
+ 	}
+ 	p->drawText (2, 0, cr.width () - 4, cr.height (), Qt::AlignLeft, dummy);
  }
  
! 
! QWidget *LevelsTable::beginEdit (int row, int col, bool) {
  	RK_TRACE (EDITOR);
+ 	RK_ASSERT (!tted);
  
! 	if (row >= numTrueRows ()) {
! 		insertRows (numRows (), 1);
  	}
  	
! 	tted = new CellEditor (this, text (row, col), 0, 0);
! 
! 	QRect cr = cellGeometry (row, col);
! 	tted->resize (cr.size ());
! 	moveChild (tted, cr.x (), cr.y ());
! 	tted->show ();
  	
! 	tted->setActiveWindow ();
! 	tted->setFocus ();
! 	connect (tted, SIGNAL (lostFocus ()), this, SLOT (editorLostFocus ()));
! 
! 	updateCell (row, col);
! 	return (tted);
  }
  
! 
! EditLabelsDialog::EditLabelsDialog (QWidget *parent, RKVariable *var, int mode) : QDialog (parent) {
  	RK_TRACE (EDITOR);
+ 	RK_ASSERT (var);
+ 	RK_ASSERT (var->objectOpened ());
  	
! 	EditLabelsDialog::var = var;
! 	EditLabelsDialog::mode = mode;
  
! 	QVBoxLayout *mainvbox = new QVBoxLayout (this, KDialog::marginHint (), KDialog::spacingHint ());
! 	QLabel *label = new QLabel (i18n ("Levels can be assigned only to consecutive integers starting with 1. To remove levels at the end of the list, just set them to empty."), this);
! 	label->setAlignment (Qt::AlignAuto | Qt::AlignVCenter | Qt::ExpandTabs | Qt::WordBreak);
! 	mainvbox->addWidget (label);
! 
! 	QHBoxLayout *hbox = new QHBoxLayout (mainvbox, KDialog::spacingHint ());
! 
! 	RObject::ValueLabels *labels = var->getValueLabels ();
! 	if (!labels) {
! 		labels = new RObject::ValueLabels;
  	}
+ 
+ 	table = new LevelsTable (this, labels);
+ 	hbox->addWidget (table);
+ 
+ 	QHBoxLayout *buttonbox = new QHBoxLayout (mainvbox, KDialog::spacingHint ());
+ 
+ 	QPushButton *ok_button = new QPushButton (i18n ("Ok"), this);
+ 	connect (ok_button, SIGNAL (clicked ()), this, SLOT (accept ()));
+ 	buttonbox->addWidget (ok_button);
+ 
+ 	QPushButton *cancel_button = new QPushButton (i18n ("Cancel"), this);
+ 	connect (cancel_button, SIGNAL (clicked ()), this, SLOT (reject ()));
+ 	buttonbox->addWidget (cancel_button);
+ 	
+ 	setCaption (i18n ("Levels / Value labels for '%1'").arg (var->getShortName ()));
  }
  
! EditLabelsDialog::~EditLabelsDialog () {
  	RK_TRACE (EDITOR);
  }
  
***************
*** 179,182 ****
--- 197,201 ----
  	RK_TRACE (EDITOR);
  
+ 	RObject::ValueLabels *labels = table->storage;
  	if (labels->isEmpty ()) {
  		var->setValueLabels (0);





More information about the rkward-tracker mailing list