[Kst] extragear/graphics/kst/src
Barth Netterfield
netterfield at astro.utoronto.ca
Sun Dec 10 02:09:15 CET 2006
SVN commit 611934 by netterfield:
SuggestPlotName suggests unique names now.
Avoid letting the user create a view object with a non-unique name.
M +5 -0 libkst/kstdatacollection.cpp
M +2 -0 libkst/kstdatacollection.h
M +17 -0 libkstapp/kstdatacollection-gui.cpp
M +2 -0 libkstapp/kstdatacollection-gui.h
M +19 -0 libkstapp/kstviewobject.cpp
M +0 -1 libkstapp/view2dplotwidget.ui
M +12 -51 libkstapp/view2dplotwidget.ui.h
M +9 -1 libkstmath/kstdefaultnames.cpp
--- trunk/extragear/graphics/kst/src/libkst/kstdatacollection.cpp #611933:611934
@@ -208,6 +208,11 @@
// meaningless in no GUI: no plots!
}
+bool KstData::viewObjectNameNotUnique(const QString& tag) {
+ Q_UNUSED(tag)
+ // meaningless in no GUI: no view objects!
+ return false;
+}
int KstData::vectorToFile(KstVectorPtr v, QFile *f) {
// FIXME: implement me (non-gui)
--- trunk/extragear/graphics/kst/src/libkst/kstdatacollection.h #611933:611934
@@ -47,6 +47,8 @@
virtual bool matrixTagNameNotUnique(const QString& tag, bool warn = true, void *parent = 0L);
virtual bool matrixTagNameNotUniqueInternal(const QString& tag);
+ virtual bool viewObjectNameNotUnique(const QString& tag);
+
virtual void removeCurveFromPlots(KstBaseCurve *c); // no sharedptr here
/** Save a vector to a file */
--- trunk/extragear/graphics/kst/src/libkstapp/kstdatacollection-gui.cpp #611933:611934
@@ -264,6 +264,23 @@
return rc;
}
+bool KstGuiData::viewObjectNameNotUnique(const QString& tag) {
+ KstApp *app = KstApp::inst();
+ KMdiIterator<KMdiChildView*> *it = app->createIterator();
+ if (it) {
+ while (it->currentItem()) {
+ KstViewWindow *view = dynamic_cast<KstViewWindow*>(it->currentItem());
+ if (view) {
+ if (view->view()->findChild(tag, true)) {
+ return (true);
+ }
+ }
+ it->next();
+ }
+ app->deleteIterator(it);
+ }
+ return false;
+}
int KstGuiData::columns(const QString& window) {
KstViewWindow *w = dynamic_cast<KstViewWindow*>(KstApp::inst()->findWindow(window));
--- trunk/extragear/graphics/kst/src/libkstapp/kstdatacollection-gui.h #611933:611934
@@ -30,6 +30,8 @@
bool vectorTagNameNotUnique(const QString& tag, bool warn = true, void *parent = 0L);
bool matrixTagNameNotUnique(const QString& tag, bool warn = true, void *parent = 0L);
+ bool viewObjectNameNotUnique(const QString& tag);
+
void removeCurveFromPlots(KstBaseCurve *c); // no sharedptr here
/** Save a vector to a file */
--- trunk/extragear/graphics/kst/src/libkstapp/kstviewobject.cpp #611933:611934
@@ -1553,13 +1553,32 @@
void KstViewObject::rename() {
bool ok = false;
+ bool done;
+ QString oldName = tagName();
#if KDE_VERSION >= KDE_MAKE_VERSION(3,3,0)
QString newName = KInputDialog::getText(i18n("Kst"), i18n("Enter a new name for %1:").arg(tagName()), tagName(), &ok);
#else
QString newName = KLineEditDlg::getText(i18n("Enter a new name for %1:").arg(tagName()), tagName(), &ok, 0L);
#endif
+ done = !ok;
+ while (!done) {
+ setTagName(newName+"tmpholdingstring");
+ if (KstData::self()->viewObjectNameNotUnique(newName)) {
+#if KDE_VERSION >= KDE_MAKE_VERSION(3,3,0)
+ newName = KInputDialog::getText(i18n("Kst"), i18n("%1 is not a unique name: Enter a new name for %2:").arg(newName).arg(oldName), oldName, &ok);
+#else
+ newName = KLineEditDlg::getText(i18n("%1 is not a unique name: Enter a new name for %2:").arg(newName).arg(oldName), oldName, &ok, 0L);
+#endif
+ done = !ok;
+ } else {
+ done = ok = true;
+ }
+ }
+
if (ok) {
setTagName(newName);
+ } else {
+ setTagName(oldName);
}
}
--- trunk/extragear/graphics/kst/src/libkstapp/view2dplotwidget.ui #611933:611934
@@ -3279,7 +3279,6 @@
</slots>
<functions>
<function access="private" specifier="non virtual">init()</function>
- <function returnType="bool">checkPlotName()</function>
</functions>
<layoutdefaults spacing="6" margin="11"/>
<includehints>
--- trunk/extragear/graphics/kst/src/libkstapp/view2dplotwidget.ui.h #611933:611934
@@ -1166,10 +1166,19 @@
applyPlotMarkers(plot);
//_title->setText(plot->tagName());
- if (checkPlotName()) {
- plot->setTagName(_title->text().stripWhiteSpace());
- } else {
+ QString tag = _title->text().stripWhiteSpace();
+ if (tag.isEmpty()) {
plot->setTagName(KST::suggestPlotName());
+ } else {
+ plot->setTagName(tag+"randomtextasholdingpattern");
+ if (KstData::self()->viewObjectNameNotUnique(tag)) {
+ int j = 1;
+ while (KstData::self()->viewObjectNameNotUnique(tag+"-"+QString::number(j))) {
+ j++;
+ }
+ tag = tag + "-" + QString::number(j);
+ }
+ plot->setTagName(tag);
}
plot->setDirty();
@@ -1200,54 +1209,6 @@
*/
}
-
-bool View2DPlotWidget::checkPlotName() {
- bool rc = true;
-
- // first check if name is blank
- if (!_title->text().stripWhiteSpace().isEmpty()) {
- // FIXME: check if the name is a duplicate
-/* KstApp *app = KstApp::inst();
- KMdiIterator<KMdiChildView*> *iter;
- QString name = Name->text().stripWhiteSpace();
- KstViewObjectPtr viewObject;
-
- iter = app->createIterator();
- if (iter) {
- while (iter->currentItem()) {
- KMdiChildView *childview = iter->currentItem();
- KstViewWindow *viewwindow = dynamic_cast<KstViewWindow*>(childview);
- if (viewwindow) {
- viewObject = viewwindow->view()->findChild(name);
- if (viewObject) {
- QString message = i18n("%1: not a unique plot name.\n"
- "Change it to a unique name.").arg(Name->text().stripWhiteSpace());
- QWidget *page = TabWidget->page(0);
-
- KMessageBox::sorry(this, message);
-
- if (page) {
- TabWidget->showPage(page);
- }
- Name->selectAll();
- Name->setFocus();
-
- rc = false;
- break;
- }
- }
- iter->next();
- }
- app->deleteIterator(iter);
- }*/
- } else {
- rc = false;
- }
-
- return rc;
-}
-
-
void View2DPlotWidget::insertCurrentScalar() {
ScalarDest->insert(ScalarList->currentText());
}
--- trunk/extragear/graphics/kst/src/libkstmath/kstdefaultnames.cpp #611933:611934
@@ -16,6 +16,7 @@
***************************************************************************/
#include "kstdataobjectcollection.h"
+#include "kstdatacollection.h"
#include "kstdefaultnames.h"
#include "ksthistogram.h"
#include "kstcplugin.h"
@@ -28,7 +29,14 @@
QString KST::suggestPlotName() {
static int last = 0;
- return QString("P%1").arg(++last);
+
+ QString tag;
+
+ do {
+ tag = QString("P%1").arg(++last);
+ } while (KstData::self()->viewObjectNameNotUnique(tag));
+
+ return tag;
}
More information about the Kst
mailing list