aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/classeditor
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/classeditor')
-rw-r--r--src/modules/classeditor/classeditor.cpp156
-rw-r--r--src/modules/classeditor/classeditor.h32
2 files changed, 155 insertions, 33 deletions
diff --git a/src/modules/classeditor/classeditor.cpp b/src/modules/classeditor/classeditor.cpp
index 9a1439748..8addfa662 100644
--- a/src/modules/classeditor/classeditor.cpp
+++ b/src/modules/classeditor/classeditor.cpp
@@ -1091,6 +1091,7 @@ void KviClassEditor::askForClassName(QString &szClassName,QString &szInerithClas
KviClassEditorDialog *pDialog=new KviClassEditorDialog(this,"classdialog",m_pClasses);
while(1)
{
+ szClassName="";
g_pClassEditorModule->lock();
bool bOk=pDialog->exec();
g_pClassEditorModule->unlock();
@@ -1098,39 +1099,44 @@ void KviClassEditor::askForClassName(QString &szClassName,QString &szInerithClas
szClassName=pDialog->getClassName();
szInerithClassName=pDialog->getInerithClassName();
// we allow only [\w:]+
- QRegExp re("[\\w:]+");
+ QRegExp re("[\\w]+");
if(!re.exactMatch(szClassName))
{
g_pClassEditorModule->lock();
QMessageBox::information(this,
- __tr2qs_ctx("Bad Class Name","editor"),
- __tr2qs_ctx("Class names can contain only letters, digits, underscores and '::' namespace separators","editor"),
+ __tr2qs_ctx("Bad Class Name","classeditor"),
+ __tr2qs_ctx("Class names can contain only letters, digits and underscores","classeditor"),
__tr2qs_ctx("Ok, Let me try again...","editor"));
g_pClassEditorModule->unlock();
continue;
}
- // make sure that we have only doubled "::" and not ":" or ":::..."
- QString tmp = szClassName;
- tmp.replace("::","@"); // @ is not allowed by the rule above
- if(tmp.indexOf(":",Qt::CaseInsensitive) != -1)
- {
- g_pClassEditorModule->lock();
- QMessageBox::information(this,
- __tr2qs_ctx("Bad Class Name","editor"),
- __tr2qs_ctx("Stray ':' character in class name: did you mean ...<namespace>::<name> ?","editor"),
- __tr2qs_ctx("Ok, Let me try again...","editor"));
- g_pClassEditorModule->unlock();
- continue;
- }
- if(tmp.indexOf("@@",Qt::CaseInsensitive) != -1)
+ break;
+ }
+ delete pDialog;
+}
+void KviClassEditor::askForFunction(QString &szFunctionName,bool * bInternal,const QString &szClassName)
+{
+ KviClassEditorFunctionDialog *pDialog=new KviClassEditorFunctionDialog(this,"function",szClassName);
+ while(1)
+ {
+ szFunctionName="";
+ g_pClassEditorModule->lock();
+ bool bOk=pDialog->exec();
+ g_pClassEditorModule->unlock();
+ if(!bOk) break;
+ szFunctionName=pDialog->getFunctionName();
+ *bInternal=pDialog->isInternalFunction();
+ // we allow only [\w:]+
+ QRegExp re("[\\w]+");
+ if(!re.exactMatch(szFunctionName))
{
- g_pClassEditorModule->lock();
- QMessageBox::information(this,
- __tr2qs_ctx("Bad Class Name","editor"),
- __tr2qs_ctx("Found an empty namespace in class name","editor"),
- __tr2qs_ctx("Ok, Let me try again...","editor"));
- g_pClassEditorModule->unlock();
- continue;
+ g_pClassEditorModule->lock();
+ QMessageBox::information(this,
+ __tr2qs_ctx("Bad Function Name","editor"),
+ __tr2qs_ctx("Function names can contain only letters, digits and underscores","editor"),
+ __tr2qs_ctx("Ok, Let me try again...","editor"));
+ g_pClassEditorModule->unlock();
+ continue;
}
break;
}
@@ -1236,16 +1242,20 @@ void KviClassEditor::newClass()
}
void KviClassEditor::newNamespace()
{
- QString szName = askForNamespaceName(__tr2qs_ctx("Add Namespace","editor"),__tr2qs_ctx("Please enter the name for the new namespace","editor"),"mynamespace");
- if(szName.isEmpty())return;
- newItem(szName,KviClassEditorTreeWidgetItem::Namespace);
+ QString szName = askForNamespaceName(__tr2qs_ctx("Add Namespace","editor"),__tr2qs_ctx("Please enter the name for the new namespace","editor"),"mynamespace");
+ if(szName.isEmpty())return;
+ newItem(szName,KviClassEditorTreeWidgetItem::Namespace);
}
void KviClassEditor::newMemberFunction()
{
-/* QString szName = askForNamespaceName(__tr2qs_ctx("Add Namespace","editor"),__tr2qs_ctx("Please enter the name for the new namespace","editor"),"mynamespace");
- if(szName.isEmpty())return;
- newItem(szName,KviClassEditorTreeWidgetItem::Namespace);*/
+ QString szFunctionName,szClassName;
+ szClassName=buildFullClassName(m_pLastClickedItem);
+ bool bInternal;
+ askForFunction(szFunctionName, &bInternal,szClassName);
+ if(szFunctionName.isEmpty())return;
+ KviClassEditorTreeWidgetItem *it=newItem(szFunctionName,KviClassEditorTreeWidgetItem::Method);
+ it->setInternalFunction(bInternal);
}
KviClassEditorTreeWidgetItem * KviClassEditor::newItem(QString &szName,KviClassEditorTreeWidgetItem::Type eType)
@@ -1401,7 +1411,7 @@ KviClassEditorDialog::KviClassEditorDialog(QWidget * pParent, const QString & sz
QLabel * pClassNameLabel = new QLabel(hbox);
pClassNameLabel->setObjectName("classnamelabel");
- // __tr2qs_ctx("Please enter the name for the new function","editor")
+
pClassNameLabel->setText(__tr2qs_ctx("Please enter the name for the new class:","classeditor"));
m_pClassNameLineEdit = new QLineEdit(hbox);
@@ -1465,3 +1475,87 @@ void KviClassEditorDialog::textChanged(const QString & szText)
{
m_pNewClassButton->setEnabled(!szText.isEmpty());
}
+
+KviClassEditorFunctionDialog::KviClassEditorFunctionDialog(QWidget * pParent, const QString & szName, const QString &szClassName)
+: QDialog(pParent)
+{
+ setObjectName(szName);
+
+ m_pParent = pParent;
+ QPalette p = palette();
+ p.setColor(foregroundRole(),QColor( 0, 0, 0 ));
+ p.setColor(backgroundRole(),QColor( 236, 233, 216 ));
+ setPalette(p);
+
+ QGridLayout * pLayout = new QGridLayout(this);
+
+ KviTalHBox * hbox = new KviTalHBox(this);
+ hbox->setSpacing(0);
+ hbox->setMargin(0);
+ pLayout->addWidget(hbox,0,0);
+
+ QLabel * pClassNameLabel = new QLabel(hbox);
+ pClassNameLabel->setObjectName("classnamelabel");
+ pClassNameLabel->setText("Class: <b>"+szClassName+"</b>");
+
+ hbox = new KviTalHBox(this);
+ hbox->setSpacing(0);
+ hbox->setMargin(0);
+ pLayout->addWidget(hbox,1,0);
+
+ QLabel * pFunctionNameLabel = new QLabel(hbox);
+ pFunctionNameLabel->setObjectName("functionnamelabel");
+ pFunctionNameLabel->setText(__tr2qs_ctx("Please enter the name for the new member function:","classeditor"));
+
+ m_pFunctionNameLineEdit = new QLineEdit(hbox);
+ m_pFunctionNameLineEdit->setObjectName("functionameineedit");
+
+
+ hbox = new KviTalHBox(this);
+ hbox->setSpacing(0);
+ hbox->setMargin(0);
+ pLayout->addWidget(hbox,2,0);
+
+
+ QLabel * pFunctionInternalLabel = new QLabel(hbox);
+ pFunctionInternalLabel->setObjectName("functionnamelabel");
+ pFunctionInternalLabel->setText(__tr2qs_ctx("Set as <b>Internal</b> Function: ","classeditor"));
+
+ m_pInternalCheckBox=new QCheckBox(hbox);
+ m_pInternalCheckBox->setChecked(false);
+ m_pFunctionNameLineEdit->setFocus();
+ hbox->setAlignment(m_pInternalCheckBox,Qt::AlignLeft);
+ hbox->setStretchFactor(m_pInternalCheckBox,70);
+ hbox->setStretchFactor(pFunctionInternalLabel,30);
+
+
+ hbox = new KviTalHBox(this);
+ hbox->setSpacing(0);
+ hbox->setMargin(0);
+ pLayout->addWidget(hbox,3,0);
+
+ m_pNewFunctionButton = new QPushButton(hbox);
+ m_pNewFunctionButton->setObjectName("newfunctionbutton");
+ m_pNewFunctionButton->setText(__tr2qs_ctx("&Add","classeditor"));
+ m_pNewFunctionButton->setEnabled(false);
+
+ QPushButton * pCancelButton = new QPushButton(hbox);
+ pCancelButton->setObjectName("cancelButton");
+ pCancelButton->setText(__tr2qs_ctx("&Cancel","editor"));
+
+ setLayout(pLayout);
+
+ // signals and slots connections
+ connect(pCancelButton, SIGNAL(clicked()), this, SLOT(reject()));
+ connect(m_pNewFunctionButton, SIGNAL(clicked()), this, SLOT(accept()));
+ connect(m_pFunctionNameLineEdit, SIGNAL(textChanged(const QString &)), this, SLOT(textChanged(const QString &)));
+}
+
+KviClassEditorFunctionDialog::~KviClassEditorFunctionDialog()
+{
+}
+
+void KviClassEditorFunctionDialog::textChanged(const QString & szText)
+{
+ m_pNewFunctionButton->setEnabled(!szText.isEmpty());
+}
diff --git a/src/modules/classeditor/classeditor.h b/src/modules/classeditor/classeditor.h
index be5a20695..5e96e5627 100644
--- a/src/modules/classeditor/classeditor.h
+++ b/src/modules/classeditor/classeditor.h
@@ -37,6 +37,7 @@
#include <QLineEdit>
#include <QStringList>
#include <QPushButton>
+#include <QCheckBox>
#include <QLabel>
#include <QTreeWidget>
//#include <QItemDelegate>
@@ -70,7 +71,7 @@ protected:
KviClassEditorTreeWidgetItem * m_pParentItem;
QString m_szName;
QString m_szBuffer;
- bool m_bClassModified;
+ bool m_bClassModified, m_bInternal;
QString m_szInerithClassName;
int m_cPos;
public:
@@ -79,7 +80,8 @@ public:
void setName(const QString &szName);
void setClassModified(bool bModified){m_bClassModified=bModified;};
bool classIsModified(){return m_bClassModified;};
-
+ void setInternalFunction(bool bInternal){m_bInternal=bInternal;};
+ bool isInternalFunction(){return m_bInternal;};
Type type(){ return m_eType; };
void setType(Type t);
bool isClass(){ return m_eType == Class; };
@@ -194,6 +196,8 @@ protected:
bool hasSelectedItems();
void askForClassName(QString &szClassName,QString &szInerithClassName);
QString askForNamespaceName(const QString &szAction,const QString &szText,const QString &szInitialText);
+ void askForFunction(QString &szFunctionName,bool * bInternal, const QString &szClassName);
+
/*
bool removeItem(KviClassEditorTreeWidgetItem *it,bool * pbYesToAll,bool bDeleteEmptyTree);
void removeItemChildren(KviClassEditorTreeWidgetItem *it);
@@ -270,4 +274,28 @@ protected slots:
*/
};
+class KviClassEditorFunctionDialog: public QDialog
+{
+ Q_OBJECT
+public:
+ KviClassEditorFunctionDialog(QWidget * pParent, const QString & szName, const QString & szClassName);
+
+ ~KviClassEditorFunctionDialog();
+public:
+ QString getFunctionName(){return m_pFunctionNameLineEdit->text();};
+ bool isInternalFunction(){return m_pInternalCheckBox->isChecked();};
+protected:
+ QPushButton * m_pNewFunctionButton;
+ QLineEdit * m_pFunctionNameLineEdit;
+ QCheckBox * m_pInternalCheckBox;
+ QWidget * m_pParent;
+protected slots:
+ void textChanged(const QString &);
+ void newClass();
+/*signals:
+ void replaceAll(const QString &, const QString &);
+ void initFind();
+ void nextFind(const QString &);
+*/
+};
#endif //_ALIASEDITOR_H_