vymmodel.cpp
changeset 823 0bba81dde1bc
parent 822 c2ce9944148c
child 824 36eb4b8f409e
     1.1 --- a/vymmodel.cpp	Wed Feb 10 13:48:42 2010 +0000
     1.2 +++ b/vymmodel.cpp	Fri Feb 19 13:47:03 2010 +0000
     1.3 @@ -6,6 +6,7 @@
     1.4  #include "attributeitem.h"
     1.5  #include "treeitem.h"
     1.6  #include "branchitem.h"
     1.7 +#include "bugagent.h"
     1.8  #include "editxlinkdialog.h"
     1.9  #include "exports.h"
    1.10  #include "exportxhtmldialog.h"
    1.11 @@ -48,9 +49,7 @@
    1.12  
    1.13  extern Settings settings;
    1.14  
    1.15 -
    1.16 -
    1.17 -int VymModel::mapNum=0;	// make instance
    1.18 +uint VymModel::idLast=0;	// make instance
    1.19  
    1.20  VymModel::VymModel()
    1.21  {
    1.22 @@ -83,7 +82,8 @@
    1.23  	mapScene=NULL;
    1.24  
    1.25  	// History 
    1.26 -	mapNum++;
    1.27 +	idLast++;
    1.28 +	mapID=idLast;
    1.29      mapChanged=false;
    1.30  	mapDefault=true;
    1.31  	mapUnsaved=false;
    1.32 @@ -145,14 +145,14 @@
    1.33  
    1.34  	//Initialize DBUS object
    1.35  	adaptorModel=new AdaptorModel(this);	// Created and not deleted as documented in Qt
    1.36 -    if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapNum),this))
    1.37 +    if (!dbusConnection.registerObject (QString("/vymmodel_%1").arg(mapID),this))
    1.38  		qWarning ("VymModel: Couldn't register DBUS object!");
    1.39  }
    1.40  
    1.41  void VymModel::makeTmpDirectories()
    1.42  {
    1.43  	// Create unique temporary directories
    1.44 -	tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapNum);
    1.45 +	tmpMapDir = tmpVymDir+QString("/model-%1").arg(mapID);
    1.46  	histPath = tmpMapDir+"/history";
    1.47  	QDir d;
    1.48  	d.mkdir (tmpMapDir);
    1.49 @@ -169,7 +169,7 @@
    1.50  	return blockReposition;
    1.51  }
    1.52  
    1.53 -void VymModel::updateActions()	// FIXME-2  maybe don't update if blockReposition is set
    1.54 +void VymModel::updateActions()	// FIXME-4  maybe don't update if blockReposition is set
    1.55  {
    1.56  	//cout << "VM::updateActions \n";
    1.57  	// Tell mainwindow to update states of actions
    1.58 @@ -354,8 +354,6 @@
    1.59  	if (lmode==NewMap)
    1.60  	{
    1.61  		selModel->clearSelection();
    1.62 -		// FIXME-2 VM not needed??? model->setMapEditor(this);
    1.63 -		// (map state is set later at end of load...)
    1.64  	} else
    1.65  	{
    1.66  		BranchItem *bi=getSelectedBranch();
    1.67 @@ -470,7 +468,7 @@
    1.68  		file.close();
    1.69  		if ( ok ) 
    1.70  		{
    1.71 -			reposition();	// FIXME-2 VM reposition the view instead...
    1.72 +			reposition();	
    1.73  			emitSelectionChanged();
    1.74  			if (lmode==NewMap)
    1.75  			{
    1.76 @@ -952,7 +950,7 @@
    1.77  		QDateTime tmod=QFileInfo (filePath).lastModified();
    1.78  		if (tmod>fileChangedTime)
    1.79  		{
    1.80 -			// FIXME-2 VM switch to current mapeditor and finish lineedits...
    1.81 +			// FIXME-3 VM switch to current mapeditor and finish lineedits...
    1.82  			QMessageBox mb( vymName,
    1.83  				tr("The file of the map  on disk has changed:\n\n"  
    1.84  				   "   %1\n\nDo you want to reload that map with the new file?").arg(filePath),
    1.85 @@ -1877,7 +1875,7 @@
    1.86  	}	
    1.87  }
    1.88  
    1.89 -void VymModel::setHideLinkUnselected (bool b) // FIXME-2 Images still have visible link after load
    1.90 +void VymModel::setHideLinkUnselected (bool b) 
    1.91  {
    1.92  	TreeItem *ti=getSelectedItem();
    1.93  	if (ti && (ti->getType()==TreeItem::Image ||ti->isBranchLikeType()))
    1.94 @@ -2489,7 +2487,7 @@
    1.95  	return false;
    1.96  }
    1.97  
    1.98 -void VymModel::deleteSelection()	
    1.99 +void VymModel::deleteSelection()	//FIXME-2 xLinks in a deleted subtree are not restored on undo	
   1.100  {
   1.101  	BranchItem *selbi=getSelectedBranch();
   1.102  
   1.103 @@ -2532,7 +2530,7 @@
   1.104  			emitShowSelection();
   1.105  		} else if (ti->getType()==TreeItem::XLink)
   1.106  		{
   1.107 -			//FIXME-2 savestate missing
   1.108 +			//FIXME-2 savestate for deleting xlink missing
   1.109  			deleteItem (ti);
   1.110  		} else
   1.111  			qWarning ("VymmModel::deleteSelection()  unknown type?!");
   1.112 @@ -2728,7 +2726,7 @@
   1.113  	// saveState & reposition are called in above functions
   1.114  }
   1.115  
   1.116 -void VymModel::unscrollChildren() 	//FIXME-2 does not update flag yet, possible segfault
   1.117 +void VymModel::unscrollChildren() 
   1.118  {
   1.119  	BranchItem *selbi=getSelectedBranch();
   1.120  	BranchItem *prev=NULL;
   1.121 @@ -2929,72 +2927,19 @@
   1.122  
   1.123  void VymModel::getBugzillaData()	
   1.124  {
   1.125 -	TreeItem *selti=getSelectedItem();
   1.126 -	if (selti)
   1.127 +	BranchItem *selbi=getSelectedBranch();
   1.128 +	if (selbi)
   1.129  	{		
   1.130 -		QString url=selti->getURL();
   1.131 +		QString url=selbi->getURL();
   1.132  		if (!url.isEmpty())
   1.133  		{
   1.134  			QRegExp rx("(\\d+)");
   1.135  			if (rx.indexIn(url) !=-1)
   1.136  			{
   1.137  				QString bugID=rx.cap(1);
   1.138 -				cout << "VM::getBugzillaData bug="<<bugID.toStdString()<<endl;
   1.139 -
   1.140 -				Process p;
   1.141 -				//QString script="test/sleep.sh";
   1.142 -				QString script="test/vym-bug.pl";
   1.143 -				p.start (script,QStringList()<<bugID);
   1.144 -				if (!p.waitForStarted())
   1.145 -				{
   1.146 -					cout <<"VM::getBugzillaData couldn't start "<<script.toStdString()<<endl;
   1.147 -					return;
   1.148 -				}	
   1.149 -				if (!p.waitForFinished())
   1.150 -				{
   1.151 -					cout <<"VM::getBugzillaData couldn't finish "<<script.toStdString()<<endl;
   1.152 -					return;
   1.153 -				}
   1.154 -				//QByteArray result=p.readAll();
   1.155 -				QString result=p.getStdout();
   1.156 -				while (result.endsWith("\n")) result.chop(1); 
   1.157 -				//cout << QString(result).toStdString()<<endl;
   1.158 -				QString err=p.getErrout();
   1.159 -				if (!err.isEmpty())
   1.160 -				{
   1.161 -					cout << "VM::getBugzillaData Error:\n";
   1.162 -					cout <<err.toStdString()<<endl;
   1.163 -				}
   1.164 -				else if (!result.isEmpty())
   1.165 -				{
   1.166 -					QString heading,cdate,mdate,state,whiteboard;
   1.167 -					QRegExp re("short_desc:(.*)\n");
   1.168 -					re.setMinimal(true);
   1.169 -					if (re.indexIn (result) !=-1) heading=re.cap(1);
   1.170 -
   1.171 -					re.setPattern ("creation_ts:(.*)\\s");
   1.172 -					if (re.indexIn (result) !=-1) cdate=re.cap(1);
   1.173 -
   1.174 -					re.setPattern ("delta_ts:(.*)\\s");
   1.175 -					if (re.indexIn (result) !=-1) mdate=re.cap(1);
   1.176 -
   1.177 -					re.setPattern ("bug_status:(.*)\n");
   1.178 -					if (re.indexIn (result) !=-1) state=re.cap(1);
   1.179 -
   1.180 -					re.setPattern ("status_whiteboard:(.*)\n");
   1.181 -					if (re.indexIn (result) !=-1) whiteboard=re.cap(1);
   1.182 -
   1.183 -					setHeading (bugID + " - " + heading);
   1.184 -					cout << "VM: heading="<<heading.toStdString()<<endl;
   1.185 -					cout << "VM:   cdate="<<cdate.toStdString()<<endl;
   1.186 -					cout << "VM:   mdate="<<mdate.toStdString()<<endl;
   1.187 -					cout << "VM:   state="<<state.toStdString()<<endl;
   1.188 -					cout << "VM:  wboard="<<whiteboard.toStdString()<<endl;
   1.189 -					
   1.190 -					//cout <<"VM::getBugzillaData  "<<script.toStdString()<<" returned:\n";
   1.191 -					//cout <<QString(result).toStdString()<<endl;
   1.192 -				} else	
   1.193 -					cout << "VM::getBugzillaData "<<script.toStdString()<<"  returned nothing\n";
   1.194 +				qDebug()<< "VM::getBugzillaData bug="<<bugID;
   1.195 +
   1.196 +				new BugAgent (selbi,bugID);
   1.197  			}	
   1.198  		}
   1.199  	}
   1.200 @@ -3044,12 +2989,12 @@
   1.201  				"setVymLink (\""+fd->selectedFile()+"\")",
   1.202  				QString("Set vymlink of %1 to %2").arg(getObjectName(bi)).arg(fd->selectedFile())
   1.203  			);	
   1.204 -			setVymLink (fd->selectedFile() );	// FIXME-2 ok?
   1.205 +			setVymLink (fd->selectedFile() );	
   1.206  		}
   1.207  	}
   1.208  }
   1.209  
   1.210 -void VymModel::setVymLink (const QString &s)	// FIXME-3 no savestate?
   1.211 +void VymModel::setVymLink (const QString &s)	
   1.212  {
   1.213  	// Internal function, no saveState needed
   1.214  	TreeItem *selti=getSelectedItem();
   1.215 @@ -3297,7 +3242,7 @@
   1.216  			parser.setError (Aborted,"Type of selection is not a branch");
   1.217  		} else if (parser.checkParCount(0))
   1.218  		{
   1.219 -			selbi->deactivateAllStandardFlags();	
   1.220 +			selbi->deactivateAllStandardFlags();	//FIXME-2 this probably should emitDataChanged and also setChanged. Similar all other direct changes should be done...
   1.221  		}
   1.222  	/////////////////////////////////////////////////////////////////////
   1.223  	} else if (com=="colorBranch")
   1.224 @@ -4151,7 +4096,6 @@
   1.225  	// Any errors?
   1.226  	if (parser.errorLevel()==NoError)
   1.227  	{
   1.228 -		// setChanged();  FIXME-2 should not be called e.g. for export?!
   1.229  		reposition();
   1.230  		errorMsg.clear();
   1.231  		noErr=true;
   1.232 @@ -4536,6 +4480,11 @@
   1.233  	return linkstyle;
   1.234  }	
   1.235  
   1.236 +uint VymModel::getID()
   1.237 +{
   1.238 +	return mapID;
   1.239 +}
   1.240 +
   1.241  void VymModel::setMapDefLinkColor(QColor col)
   1.242  {
   1.243  	if ( !col.isValid() ) return;