[patch] application wide edit (cut, copy, paste) actions

Scott Wheeler wheeler at kde.org
Sat Feb 15 03:54:22 GMT 2003


I've been complaining about the lack of a framework for application wide 
implementation of edit actions for a little while, and started throwing out 
some ideas on IRC today.  When talking to Maks I came up with the idea for 
this patch.

Basically this will allow you to call kapp->copy() and similar edit functions 
and let KApplication do the work of figuring out which widget has the focus 
and if that widget supports these actions.

This should greatly simplify the work of implementing application wide actions 
like these.  There are a lot of if it's this widget do this, if it's that one 
do this, etc.  This basically reduces the logic to "if a widget has the focus 
and implements the slot, call that slot".

So this will handle all of the cut related code for a simple app:

KStdAction::cut( kapp, SLOT( cut() ), actionCollection() );

For example, if you have a QLineEdit has the focus and you call kapp->copy() 
it will copy the text.  It works on many other classes as is.  To add support 
to additional classes, you just need to implement these slots.

It's currently implemented for cut, copy, paste, clear and select all, and can 
easily be extended to other actions as needed.

It's a little bit hack-ish, but it conceals the ugliness in one method.  I 
sent an email today to qt-bugs with how I think things should be done in Qt 
4, but it's BIC, so I think this is the best way of doing things for the 
moment.  I'm attaching the email that I sent there earlier.

I'll commit this in the next day or so if nobody objects.

Cheers,

-Scott
-- 
It may be true that you can't fool all the people all the time, but you can 
fool enough of them to rule a large country. 
--Will Durant
-------------- next part --------------
From wheeler at kde.org Fri Feb 14 20:42:17 2003
From: Scott Wheeler <wheeler at kde.org>
To: qt-bugs at trolltech.com
Subject: "QEditable" interface in Qt 4
Date: Fri, 14 Feb 2003 20:42:17 +0100
User-Agent: KMail/1.5.9
MIME-Version: 1.0
Content-Disposition: inline
X-KMail-Identity: 1427191853
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Message-Id: <200302142042.17471.wheeler at kde.org>
Status: RO
X-Status: S
X-KMail-EncryptionState:  
X-KMail-SignatureState:  
X-KMail-MDN-Sent:  

I've been complaining about the "Edit" framework in Qt/KDE for a while, so I 
thought I would at least throw out my thoughts on The Right Way.  ;-)

Basically, for Qt 4, it would be really nice to have an abstract class called 
QEditable that was something like:

class QEditable
{
public:
	QEditable() {}
	virtual ~QEditable{}

	virtual void cut() = 0;
	virtual void copy() const = 0;
	virtual void paste() = 0;
	virtual void clear() = 0;
};

And then for widgets like QLineEdit you would have:

class QLineEdit : public QFrame, public QEditable
{
[...]
public slots:
	virtual void cut();
	virtual void copy() const;
	virtual void paste();
	virtual void clear();	
[...]
}

Obviously with concrete implementations.  This would allow to greatly simplify 
edit actions application wide by making something like:

void MyApp::cut()
{
	QEditable *editableWidget = dynamic_cast<QEditable *>(qApp->focusWidget());
	if(editableWidget)
		editableWidget->cut();
}

Which could even be the default implementation in QApplication.  Being able to 
have app wide edit action by default I think could remove a lot of code that 
does this manually.

Currently you can do some ugliness and query the meta object system for the 
presense of a slot, but that's hackish and not very C++ like.

Anyway, just my thoughts for the moment.  Let me know what you think.

Cheers,

-Scott

-- 
The fact that an opinion has been widely held is no evidence whatever that it 
is not utterly absurd. 
--Bertrand Russell

-------------- next part --------------
A non-text attachment was scrubbed...
Name: kapp-edit.patch
Type: text/x-diff
Size: 2847 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20030215/401f2ca4/attachment.patch>


More information about the kde-core-devel mailing list